InternalFreeze[] frozenNodes = freeze.getFrozenChildNodes();
for (int i = 0; i < frozenNodes.length; i++) {
InternalFreeze child = frozenNodes[i];
NodeImpl restoredChild = null;
if (child instanceof InternalFrozenNode) {
InternalFrozenNode f = (InternalFrozenNode) child;
// check for existing
if (f.getFrozenUUID() != null) {
try {
NodeImpl existing = (NodeImpl) session.getNodeByUUID(f.getFrozenUUID());
// check if one of this restoretrees node
if (removeExisting) {
existing.remove();
} else if (existing.isShareable()) {
// if existing node is shareable, then clone it
restoredChild = clone(existing, f.getName());
} else {
// since we delete the OPV=Copy children beforehand, all
// found nodes must be outside of this tree
throw new ItemExistsException(
"Unable to restore node, item already"
+ " exists outside of restored tree: "
+ existing);
}
} catch (ItemNotFoundException e) {
// ignore, item with uuid does not exist
}
}
if (restoredChild == null) {
restoredChild = addNode(f.getName(), f);
restoredChild.restoreFrozenState(f, vsel, restored, removeExisting);
}
} else if (child instanceof InternalFrozenVersionHistory) {
InternalFrozenVersionHistory f = (InternalFrozenVersionHistory) child;
VersionHistory history = (VersionHistory) session.getNodeById(f.getVersionHistoryId());
NodeId nodeId = NodeId.valueOf(history.getVersionableUUID());
String oldVersion = "jcr:dummy";
// check if representing versionable already exists somewhere
if (itemMgr.itemExists(nodeId)) {