Creating a Corresponding Node

Corresponding nodes can be created by “cloning” a node (or subtree of nodes) from one workspace to another using the Workspace.clone method:

Workspace.clone(String srcWorkspace,
String srcAbsPath,
String destAbsPath,
boolean removeExisting)

This method clones the subtree at srcAbsPath in srcWorkspace to destAbsPath in this workspace. The clone method clones both referenceable and nonreferenceable nodes. In the case of referenceable nodes clone preserves the node's UUID so that the new node in the destination workspace has the same UUID as the node in the source workspace.

For a non-referenceable node, a corresponding node in another workspace can be created either through clone, or simply by creating a node in the destination workspace (using Node.addNode) with the same relative path to the nearest referenceable node.

However, the use of clone is required for the creation corresponding referenceable nodes because simply creating a new referenceable node at the same path in the other workspace will not work, since the new node will automatically be assigned a new UUID and not the same UUID as its correspondee.

If there already exists anywhere in this workspace a node with the same UUID as an incoming node from srcWorkspace, and removeExisting is false, then clone will throw an ItemExistsException.

If removeExisting is true then the existing node is removed from its current location and the cloned node with the same UUID from srcWorkspace is copied to this workspace as part of the copied subtree (that is, not into the former location of the old node). The subtree of the cloned node will reflect the clones state in srcWorkspace, in other words the existing node will be moved and changed. If the existing node cannot be moved and changed because of node type constraints, access control constraints or because its parent is checked-in (or its parent is non-versionable but its nearest versionable ancestor is checked-in), then the appropriate exception is thrown (ConstraintViolationException, AccessControlException or VersionException, respectively).