Corresponding nodes can be created by “cloning” a node (or subtree of nodes) from one workspace to another using theWorkspace.clone method:
Workspace.clone(String srcWorkspace,
String srcAbsPath,
String destAbsPath,
boolean removeExisting)
This method clones the subtree atsrcAbsPath insrcWorkspace todestAbsPath inthis workspace. Theclone method clones both referenceable and nonreferenceable nodes. In the case of referenceable nodesclone 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 throughclone, or simply by creating a node in the destination workspace (usingNode.addNode) with the same relative path to the nearest referenceable node.
However, the use ofclone isrequired 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 fromsrcWorkspace, andremoveExisting isfalse, thenclone will throw anItemExistsException.
IfremoveExisting istrue then the existing node is removed from its current location and the cloned node with the same UUID fromsrcWorkspace 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 insrcWorkspace, in other words the existing node will be movedand 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 orVersionException, respectively).