// Create the new node ...
AbstractJcrNode child;
if (!nodeAlreadyExists) {
List<Value> primaryTypeValueList = properties.get(JcrLexicon.PRIMARY_TYPE);
String typeName = primaryTypeValueList != null ? primaryTypeValueList.get(0).getString() : null;
Name primaryTypeName = nameFor(typeName);
if (JcrNtLexicon.SHARE.equals(primaryTypeName)) {
assert key != null;
assert uuid != null;
// check if we already have the key of the shareable node
NodeKey shareableNodeKey = uuidToNodeKeyMapping.get(uuid);
if (shareableNodeKey != null) {
// we already know the key of the shareable node, so we need to just link it and return
parent.mutable().linkChild(cache, shareableNodeKey, nodeName);
node = session().node(shareableNodeKey, null, parentKey);
} else {
// we haven't processed the shareable node yet, so we need to make sure we process the share later.
parent.mutable().linkChild(cache, key, nodeName);
node = session().node(key, null, parentKey);
// make sure we post-process the share and set the correct id
nodesForPostProcessing.add(node);
// save the original UUID of the share to be able to track it back to the shareable node
shareIdsToUUIDMap.put(key, uuid);
}
ignoreAllChildren = true;
return;
}
// store the node key that we created for this UUID, so we can create shares
uuidToNodeKeyMapping.put(uuid, key);
if (shareableNodeAlreadyExists && key != null) {
parent.mutable().linkChild(cache, key, nodeName);
node = session().node(key, null, parentKey);
ignoreAllChildren = true;
return;
}
// Otherwise, it's just a regular node...
child = parent.addChildNode(nodeName, primaryTypeName, key, true, false);
} else {
child = existingNode;
}
assert child != null;
// Set the properties on the new node ...
// Set the mixin types first (before we set any properties that may require the mixins to be present) ...
List<Value> mixinTypeValueList = properties.get(JcrLexicon.MIXIN_TYPES);
if (mixinTypeValueList != null) {
for (Value value : mixinTypeValueList) {
String mixinName = value.getString();
// in the case when keys are being reused, the old node at that key is visible (with all its properties)
// via the WS cache -> ISPN db. Therefore, there might be the case when even though the child was created
// via addChild(), the old node with all the old properties and mixins is still visible at the key() and
// so the "new child" reports the mixin as already present (even though it's not)
boolean addMixinInternally = (child.isNodeType(mixinName) && !nodeAlreadyExists) ||
INTERNAL_MIXINS.contains(mixinName.toLowerCase());
if (addMixinInternally) {
child.mutable().addMixin(child.sessionCache(), nameFor(mixinName));
} else {
child.addMixin(mixinName);
}
}
}
for (Map.Entry<Name, List<Value>> entry : properties.entrySet()) {
Name propertyName = entry.getKey();
// These are all handled earlier ...
if (JcrLexicon.PRIMARY_TYPE.equals(propertyName)) {
continue;
}