session.checkPermission(this, ModeShapePermissions.ADD_NODE);
SessionCache cache = session.cache();
ChildReferences childRefs = node().getChildReferences(cache);
ChildReference srcRef = childRefs.getChild(srcPath.getLastSegment());
if (srcRef == null) {
String workspaceName = workspaceName();
throw new ItemNotFoundException(JcrI18n.pathNotFound.text(srcChildRelPath, workspaceName));
}
NodeKey destKey = null;
if (destChildRelPath != null) {
Path destPath = session.pathFactory().create(destChildRelPath);
if (destPath.isAbsolute() || destPath.size() != 1) {
throw new ItemNotFoundException(JcrI18n.invalidPathParameter.text(destChildRelPath, "destChildRelPath"));
}
if (srcPath.isSameAs(destPath)) {
return;
}
ChildReference destRef = childRefs.getChild(destPath.getLastSegment());
if (destRef == null) {
String workspaceName = workspaceName();
throw new ItemNotFoundException(JcrI18n.pathNotFound.text(destChildRelPath, workspaceName));
}
destKey = destRef.getKey();
}
// Now that we've verified the parameters, perform the move ...
mutable().reorderChild(cache, srcRef.getKey(), destKey);
}