*/
private void validate( JcrNodeDefinition node,
List<Name> supertypes,
List<JcrNodeType> pendingTypes ) throws RepositoryException {
if (node.isAutoCreated() && !node.isProtected() && node.getDefaultPrimaryType() == null) {
throw new InvalidNodeTypeDefinitionException(JcrI18n.autocreatedNodesNeedDefaults.text(node.getName()));
}
if (node.isMandatory() && JcrNodeType.RESIDUAL_ITEM_NAME.equals(node.getName())) {
throw new InvalidNodeTypeDefinitionException(JcrI18n.residualDefinitionsCannotBeMandatory.text("child nodes"));
}
Name nodeName = context.getValueFactories().getNameFactory().create(node.getName());
nodeName = nodeName == null ? JcrNodeType.RESIDUAL_NAME : nodeName;
List<JcrNodeDefinition> ancestors = findChildNodeDefinitions(supertypes, nodeName, NodeCardinality.ANY, pendingTypes);
for (JcrNodeDefinition ancestor : ancestors) {
if (ancestor.isProtected()) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.cannotOverrideProtectedDefinition.text(ancestor.getDeclaringNodeType().getName(),
"child node"));
}
if (ancestor.isMandatory() && !node.isMandatory()) {
throw new InvalidNodeTypeDefinitionException(
JcrI18n.cannotMakeMandatoryDefinitionOptional.text(ancestor.getDeclaringNodeType().getName(),
"child node"));
}
Name[] requiredPrimaryTypeNames = ancestor.requiredPrimaryTypeNames();
for (int i = 0; i < requiredPrimaryTypeNames.length; i++) {
NodeType apt = findTypeInMapOrList(requiredPrimaryTypeNames[i], pendingTypes);
if (apt == null) {
I18n msg = JcrI18n.couldNotFindDefinitionOfRequiredPrimaryType;
throw new InvalidNodeTypeDefinitionException(msg.text(requiredPrimaryTypeNames[i],
node.getName(),
node.getDeclaringNodeType()));
}
boolean found = false;
for (Name name : node.requiredPrimaryTypeNames()) {
JcrNodeType npt = findTypeInMapOrList(name, pendingTypes);
if (npt.isNodeType(apt.getName())) {
found = true;
break;
}
}
if (!found) {
I18n msg = JcrI18n.cannotRedefineChildNodeWithIncompatibleDefinition;
throw new InvalidNodeTypeDefinitionException(msg.text(nodeName, apt.getName(), node.getDeclaringNodeType()));
}
}
}
}