throw new SystemFailureException(e);
}
}
protected PropertyDefinition readPropertyDefinition( CachedNode propDefn ) throws ConstraintViolationException {
PropertyDefinitionTemplate defn = new JcrPropertyDefinitionTemplate(context());
defn.setName(strings.create(first(propDefn, JcrLexicon.NAME, JcrNodeType.RESIDUAL_ITEM_NAME)));
defn.setAutoCreated(booleans.create(first(propDefn, JcrLexicon.AUTO_CREATED)));
defn.setMandatory(booleans.create(first(propDefn, JcrLexicon.MANDATORY)));
defn.setMultiple(booleans.create(first(propDefn, JcrLexicon.MULTIPLE)));
defn.setProtected(booleans.create(first(propDefn, JcrLexicon.PROTECTED)));
defn.setOnParentVersion(OnParentVersionAction.valueFromName(strings.create(first(propDefn, JcrLexicon.ON_PARENT_VERSION))));
defn.setRequiredType(propertyType(first(propDefn, JcrLexicon.REQUIRED_TYPE)));
Property queryOps = propDefn.getProperty(JcrLexicon.AVAILABLE_QUERY_OPERATORS, system);
if (queryOps != null && !queryOps.isEmpty()) {
String[] queryOperators = new String[queryOps.size()];
int i = 0;
for (Object op : queryOps) {
queryOperators[i++] = strings.create(op);
}
defn.setAvailableQueryOperators(queryOperators);
}
Property defaultValues = propDefn.getProperty(JcrLexicon.DEFAULT_VALUES, system);
if (defaultValues != null && !defaultValues.isEmpty()) {
Value[] values = new Value[defaultValues.size()];
int i = 0;
for (Object value : defaultValues) {
org.modeshape.jcr.value.PropertyType modeType = org.modeshape.jcr.value.PropertyType.discoverType(value);
int jcrType = PropertyTypeUtil.jcrPropertyTypeFor(modeType);
String strValue = strings.create(value);
try {
values[i++] = jcrValues.createValue(strValue, jcrType);
} catch (ValueFormatException err) {
values[i++] = jcrValues.createValue(strValue);
}
i++;
}
defn.setDefaultValues(values);
}
Property constraints = propDefn.getProperty(JcrLexicon.VALUE_CONSTRAINTS, system);
if (constraints != null && !constraints.isEmpty()) {
String[] values = new String[constraints.size()];
int i = 0;
for (Object value : constraints) {
values[i++] = strings.create(value);
}
defn.setValueConstraints(values);
}
return defn;
}