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, srcPath, srcStateMgr, srcAccessMgr,
destParentState.getNodeId(), flag, refTracker);
// add to new parent
destParentState.addChildNodeEntry(destName.getName(), newState.getNodeId());
// adjust references that refer to uuid's which have been mapped to
// newly generated uuid's on copy/clone
Iterator<Object> iter = refTracker.getProcessedReferences();
while (iter.hasNext()) {
PropertyState prop = (PropertyState) iter.next();
// being paranoid...
if (prop.getType() != PropertyType.REFERENCE
&& prop.getType() != PropertyType.WEAKREFERENCE) {
continue;
}
boolean modified = false;
InternalValue[] values = prop.getValues();
InternalValue[] newVals = new InternalValue[values.length];
for (int i = 0; i < values.length; i++) {
NodeId adjusted = refTracker.getMappedId(values[i].getNodeId());
if (adjusted != null) {
newVals[i] = InternalValue.create(adjusted);
modified = true;
} else {
// reference doesn't need adjusting, just copy old value
newVals[i] = values[i];
}
}
if (modified) {
prop.setValues(newVals);
stateMgr.store(prop);
}
}
refTracker.clear();
// store states
stateMgr.store(newState);
stateMgr.store(destParentState);
return newState.getNodeId();