ItemImpl existing = null;
try {
existing = getItemManager().getItem(destPath);
if (!existing.isNode()) {
// there's already a property with that name
throw new ItemExistsException(existing.safeGetJCRPath());
} else {
// there's already a node with that name:
// check same-name sibling setting of existing node
if (!((NodeImpl) existing).getDefinition().allowsSameNameSiblings()) {
throw new ItemExistsException(existing.safeGetJCRPath());
}
}
} catch (AccessDeniedException ade) {
// FIXME by throwing ItemExistsException we're disclosing too much information
throw new ItemExistsException(destAbsPath);
} catch (PathNotFoundException pnfe) {
// no name collision since same-name siblings are allowed
}
// check constraints
// get applicable definition of target node at new location
NodeTypeImpl nt = (NodeTypeImpl) targetNode.getPrimaryNodeType();
NodeDefinitionImpl newTargetDef;
try {
newTargetDef = destParentNode.getApplicableChildNodeDefinition(destName.getName(), nt.getQName());
} catch (RepositoryException re) {
String msg = destAbsPath + ": no definition found in parent node's node type for new node";
log.debug(msg);
throw new ConstraintViolationException(msg, re);
}
// if there's already a node with that name also check same-name sibling
// setting of new node; just checking same-name sibling setting on
// existing node is not sufficient since same-name sibling nodes don't
// necessarily have identical definitions
if (existing != null && !newTargetDef.allowsSameNameSiblings()) {
throw new ItemExistsException(existing.safeGetJCRPath());
}
// check protected flag of old & new parent
if (destParentNode.getDefinition().isProtected()) {
String msg = destAbsPath + ": cannot add a child node to a protected node";