}
// validate child-node definitions
QNodeDefinition[] cnda = ntDef.getChildNodeDefs();
for (int i = 0; i < cnda.length; i++) {
QNodeDefinition cnd = cnda[i];
/* make sure declaring node type matches name of node type definition */
if (!name.equals(cnd.getDeclaringNodeType())) {
String msg = "[" + name + "#" + cnd.getName()
+ "] invalid declaring node type specified";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
checkNamespace(cnd.getName());
// check that auto-created child-nodes specify a name
if (cnd.definesResidual() && cnd.isAutoCreated()) {
String msg = "[" + name + "#" + cnd.getName()
+ "] auto-created child-nodes must specify a name";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
// check that auto-created child-nodes specify a default primary type
if (cnd.getDefaultPrimaryType() == null
&& cnd.isAutoCreated()) {
String msg = "[" + name + "#" + cnd.getName()
+ "] auto-created child-nodes must specify a default primary type";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
// check default primary type
Name dpt = cnd.getDefaultPrimaryType();
checkNamespace(dpt);
boolean referenceToSelf = false;
EffectiveNodeType defaultENT = null;
if (dpt != null) {
// check if this node type specifies itself as default primary type
if (name.equals(dpt)) {
referenceToSelf = true;
}
/**
* the default primary type must be registered, with one notable
* exception: the node type just being registered
*/
if (!name.equals(dpt) && !validatedDefs.containsKey(dpt)) {
String msg = "[" + name + "#" + cnd.getName()
+ "] invalid default primary type '" + dpt + "'";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
/**
* build effective (i.e. merged and resolved) node type from
* default primary type and check for conflicts
*/
try {
if (!referenceToSelf) {
defaultENT = entProvider.getEffectiveNodeType(new Name[] {dpt}, validatedDefs);
} else {
/**
* the default primary type is identical with the node
* type just being registered; we have to instantiate it
* 'manually'
*/
ent = entProvider.getEffectiveNodeType(ntDef, validatedDefs);
defaultENT = ent;
}
if (cnd.isAutoCreated()) {
/**
* check for circularity through default primary types
* of auto-created child nodes (node type 'a' defines
* auto-created child node with default primary type 'a')
*/
Stack definingNTs = new Stack();
definingNTs.push(name);
checkForCircularNodeAutoCreation(defaultENT, definingNTs, validatedDefs);
}
} catch (ConstraintViolationException e) {
String msg = "[" + name + "#" + cnd.getName()
+ "] failed to validate default primary type";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg, e);
} catch (NoSuchNodeTypeException e) {
String msg = "[" + name + "#" + cnd.getName()
+ "] failed to validate default primary type";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg, e);
}
}
// check required primary types
Name[] reqTypes = cnd.getRequiredPrimaryTypes();
if (reqTypes != null && reqTypes.length > 0) {
for (int n = 0; n < reqTypes.length; n++) {
Name rpt = reqTypes[n];
checkNamespace(rpt);
referenceToSelf = false;
/**
* check if this node type specifies itself as required
* primary type
*/
if (name.equals(rpt)) {
referenceToSelf = true;
}
/**
* the required primary type must be registered, with one
* notable exception: the node type just being registered
*/
if (!name.equals(rpt) && !validatedDefs.containsKey(rpt)) {
String msg = "[" + name + "#" + cnd.getName()
+ "] invalid required primary type: " + rpt;
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
/**
* check if default primary type satisfies the required
* primary type constraint
*/
if (defaultENT != null && !defaultENT.includesNodeType(rpt)) {
String msg = "[" + name + "#" + cnd.getName()
+ "] default primary type does not satisfy required primary type constraint "
+ rpt;
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg);
}
/**
* build effective (i.e. merged and resolved) node type from
* required primary type constraint and check for conflicts
*/
try {
if (!referenceToSelf) {
entProvider.getEffectiveNodeType(new Name[] {rpt}, validatedDefs);
} else {
/**
* the required primary type is identical with the
* node type just being registered; we have to
* instantiate it 'manually'
*/
if (ent == null) {
ent = entProvider.getEffectiveNodeType(ntDef, validatedDefs);
}
}
} catch (ConstraintViolationException e) {
String msg = "[" + name + "#" + cnd.getName()
+ "] failed to validate required primary type constraint";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg, e);
} catch (NoSuchNodeTypeException e) {
String msg = "[" + name + "#" + cnd.getName()
+ "] failed to validate required primary type constraint";
log.debug(msg);
throw new InvalidNodeTypeDefinitionException(msg, e);
}
}