}
protected void create() throws SAXException {
try {
AbstractJcrNode parent = parentHandler.node();
final NodeKey parentKey = parent.key();
assert parent != null;
// Figure out the key for the node ...
NodeKey key = null;
List<Value> rawUuid = properties.get(JcrLexicon.UUID);
String uuid = null;
boolean shareableNodeAlreadyExists = false;
if (rawUuid != null) {
assert rawUuid.size() == 1;
uuid = rawUuid.get(0).getString();
key = parentKey.withId(uuid);
try {
// Deal with any existing node ...
AbstractJcrNode existingNode = session().node(key, null, parentKey);
switch (uuidBehavior) {
case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING:
parent = existingNode.getParent();
// Attention: this *does not* remove the entry from the DB (ISPN). Therefore, it's always
// accessible
// to the workspace cache and thus to the current session !!!.
// Therefore, *old properties, mixins etc* will be accessible on the new child created later on
// until a session.save() is performed.
preRemoveNode(existingNode);
existingNode.remove();
break;
case ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW:
key = cache().getRootKey().withRandomId();
break;
case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING:
if (existingNode.path().isAtOrAbove(parent.path())) {
String text = JcrI18n.cannotRemoveParentNodeOfTarget.text(existingNode.getPath(),
key,
parent.getPath());
throw new ConstraintViolationException(text);
}
// Attention: this *does not* remove the entry from the DB (ISPN). Therefore, it's always
// accessible
// to the workspace cache and thus to the current session !!!.
// Therefore, *old properties, mixins etc* will be accessible on the new child created later on
// until a session.save() is performed.
preRemoveNode(existingNode);
existingNode.remove();
break;
case ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW:
if (existingNode.isShareable()) {
shareableNodeAlreadyExists = true;
} else {
throw new ItemExistsException(JcrI18n.itemAlreadyExistsWithUuid.text(key,
session().workspace()
.getName(),
existingNode.getPath()));
}
}
} catch (ItemNotFoundException e) {
// there wasn't an existing item, so just continue
}
}
// See if the node was already autocreated by the parent
AbstractJcrNode existingNode = parent.getNodeIfExists(nodeName);
boolean nodeAlreadyExists = existingNode != null && existingNode.getDefinition().isAutoCreated();
// 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 {