assert supertypes != null;
assert pendingTypes != null;
boolean residual = JcrNodeType.RESIDUAL_ITEM_NAME.equals(propertyDefinition.getName());
if (propertyDefinition.isMandatory() && !propertyDefinition.isProtected() && residual) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.residualPropertyDefinitionsCannotBeMandatory.text(propertyDefinition.getName()));
}
if (propertyDefinition.isAutoCreated() && residual) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.residualPropertyDefinitionsCannotBeAutoCreated.text(propertyDefinition.getName()));
}
Value[] defaultValues = propertyDefinition.getDefaultValues();
if (propertyDefinition.isAutoCreated() && !propertyDefinition.isProtected()
&& (defaultValues == null || defaultValues.length == 0)) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.autocreatedPropertyNeedsDefault.text(propertyDefinition.getName(),
propertyDefinition.getDeclaringNodeType()
.getName()));
}
if (!propertyDefinition.isMultiple() && (defaultValues != null && defaultValues.length > 1)) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.singleValuedPropertyNeedsSingleValuedDefault.text(propertyDefinition.getName(),
propertyDefinition.getDeclaringNodeType()
.getName()));
}
Name propName = context.getValueFactories().getNameFactory().create(propertyDefinition.getName());
propName = propName == null ? JcrNodeType.RESIDUAL_NAME : propName;
List<JcrPropertyDefinition> propertyDefinitionsFromAncestors = findPropertyDefinitions(supertypes,
propName,
propertyDefinition.isMultiple() ? PropertyCardinality.MULTI_VALUED_ONLY : PropertyCardinality.SINGLE_VALUED_ONLY,
pendingTypes);
for (JcrPropertyDefinition propertyDefinitionFromAncestor : propertyDefinitionsFromAncestors) {
if (propertyDefinitionFromAncestor.isProtected()) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.cannotOverrideProtectedDefinition.text(propertyDefinitionFromAncestor.getDeclaringNodeType()
.getName(),
"property"));
}
if (propertyDefinitionFromAncestor.isMandatory() && !propertyDefinition.isMandatory()) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.cannotMakeMandatoryDefinitionOptional.text(propertyDefinitionFromAncestor.getDeclaringNodeType()
.getName(),
"property"));
}
if (!propertyDefinition.isAsOrMoreConstrainedThan(propertyDefinitionFromAncestor, context)) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.constraintsChangedInSubtype.text(propName,
propertyDefinitionFromAncestor.getDeclaringNodeType()
.getName()));
}
if (!isAlwaysSafeConversion(propertyDefinition.getRequiredType(), propertyDefinitionFromAncestor.getRequiredType())) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.cannotRedefineProperty.text(propName,
org.modeshape.jcr.api.PropertyType.nameFromValue(propertyDefinition.getRequiredType()),
propertyDefinitionFromAncestor.getDeclaringNodeType()
.getName(),
org.modeshape.jcr.api.PropertyType.nameFromValue(propertyDefinitionFromAncestor.getRequiredType())));