PropDef propDef,
NodeTypeDef ntDef, int n)
throws RepositoryException {
NodeId id = new NodeId(calculateStableUUID(
ntDef.getName().toString() + "/" + NameConstants.JCR_PROPERTYDEFINITION.toString() + "/" + n));
VirtualNodeState pState = createNodeState(
parent, NameConstants.JCR_PROPERTYDEFINITION, id,
NameConstants.NT_PROPERTYDEFINITION);
// add properties
if (!propDef.definesResidual()) {
pState.setPropertyValue(NameConstants.JCR_NAME, InternalValue.create(propDef.getName()));
}
pState.setPropertyValue(NameConstants.JCR_AUTOCREATED, InternalValue.create(propDef.isAutoCreated()));
pState.setPropertyValue(NameConstants.JCR_MANDATORY, InternalValue.create(propDef.isMandatory()));
pState.setPropertyValue(NameConstants.JCR_ONPARENTVERSION,
InternalValue.create(OnParentVersionAction.nameFromValue(propDef.getOnParentVersion())));
pState.setPropertyValue(NameConstants.JCR_PROTECTED, InternalValue.create(propDef.isProtected()));
pState.setPropertyValue(NameConstants.JCR_MULTIPLE, InternalValue.create(propDef.isMultiple()));
pState.setPropertyValue(
NameConstants.JCR_REQUIREDTYPE,
InternalValue.create(PropertyType.nameFromValue(propDef.getRequiredType()).toUpperCase()));
pState.setPropertyValues(NameConstants.JCR_DEFAULTVALUES, PropertyType.STRING, propDef.getDefaultValues());
ValueConstraint[] vc = propDef.getValueConstraints();
InternalValue[] vals = new InternalValue[vc.length];
for (int i = 0; i < vc.length; i++) {
vals[i] = InternalValue.create(vc[i].getDefinition());
}
pState.setPropertyValues(NameConstants.JCR_VALUECONSTRAINTS, PropertyType.STRING, vals);
return pState;
}