throw new RepositoryException(msg, infe);
}
// 3. do copy operation (modify and store affected states)
ReferenceChangeTracker refTracker = new ReferenceChangeTracker();
// create deep copy of source node state
NodeState newState = copyNodeState(srcState, srcStateMgr, srcAccessMgr,
destParentState.getNodeId(), flag, refTracker);
// add to new parent
destParentState.addChildNodeEntry(destName.getName(), newState.getNodeId());
// change definition (id) of new node
NodeDef newNodeDef =
findApplicableNodeDefinition(destName.getName(),
srcState.getNodeTypeName(), destParentState);
newState.setDefinitionId(newNodeDef.getId());
// adjust references that refer to uuid's which have been mapped to
// newly generated uuid's on copy/clone
Iterator iter = refTracker.getProcessedReferences();
while (iter.hasNext()) {
PropertyState prop = (PropertyState) iter.next();
// being paranoid...
if (prop.getType() != PropertyType.REFERENCE) {
continue;
}
boolean modified = false;
InternalValue[] values = prop.getValues();
InternalValue[] newVals = new InternalValue[values.length];
for (int i = 0; i < values.length; i++) {
InternalValue val = values[i];
UUID original = val.getUUID();
UUID adjusted = refTracker.getMappedUUID(original);
if (adjusted != null) {
newVals[i] = InternalValue.create(adjusted);
modified = true;
} else {
// reference doesn't need adjusting, just copy old value
newVals[i] = val;
}
}
if (modified) {
prop.setValues(newVals);
stateMgr.store(prop);
}
}
refTracker.clear();
// store states
stateMgr.store(newState);
stateMgr.store(destParentState);
return newState.getNodeId();