// check if add node is possible. note, that the options differ if
// the 'addNode' is called from inside a regular add-node to create
// autocreated child nodes that may be 'protected'.
validator.checkAddNode(parent, nodeName, nodeTypeName, options);
// a new NodeState doesn't have mixins defined yet -> ent is ent of primarytype
EffectiveNodeType ent = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeTypeName);
if (nodeTypeName == null) {
// no primary node type specified,
// try default primary type from definition
nodeTypeName = definition.getDefaultPrimaryType();
if (nodeTypeName == null) {
String msg = "No applicable node type could be determined for " + nodeName;
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
List addedStates = new ArrayList();
// create new nodeState. NOTE, that the uniqueID is not added to the
// state for consistency between 'addNode' and importXML
NodeState nodeState = transientStateMgr.createNewNodeState(nodeName, null, nodeTypeName, definition, parent);
addedStates.add(nodeState);
if (uuid != null) {
QValue[] value = getQValues(uuid, qValueFactory);
ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
QPropertyDefinition pDef = defProvider.getQPropertyDefinition(NameConstants.MIX_REFERENCEABLE, NameConstants.JCR_UUID, PropertyType.STRING, false);
addedStates.add(addPropertyState(nodeState, NameConstants.JCR_UUID, PropertyType.STRING, value, pDef, 0));
}
// add 'auto-create' properties defined in node type
QPropertyDefinition[] pda = ent.getAutoCreateQPropertyDefinitions();
for (int i = 0; i < pda.length; i++) {
QPropertyDefinition pd = pda[i];
if (!nodeState.hasPropertyName(pd.getName())) {
QValue[] autoValue = computeSystemGeneratedPropertyValues(nodeState, pd);
if (autoValue != null) {
int propOptions = ItemStateValidator.CHECK_NONE;
// execute 'addProperty' without adding operation.
addedStates.add(addPropertyState(nodeState, pd.getName(), pd.getRequiredType(), autoValue, pd, propOptions));
}
}
}
// recursively add 'auto-create' child nodes defined in node type
QNodeDefinition[] nda = ent.getAutoCreateQNodeDefinitions();
for (int i = 0; i < nda.length; i++) {
QNodeDefinition nd = nda[i];
// execute 'addNode' without adding the operation.
int opt = ItemStateValidator.CHECK_LOCK | ItemStateValidator.CHECK_COLLISION;
addedStates.addAll(addNodeState(nodeState, nd.getName(), nd.getDefaultPrimaryType(), null, nd, opt));