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)) {
NodeImpl n = session.getNodeById(nodeId);
if (removeExisting) {
String dstPath = getPath() + "/" + n.getName();
if (!n.getPath().equals(dstPath)) {
session.move(n.getPath(), dstPath);
}
oldVersion = n.getBaseVersion().getName();
} else if (n.getParent().isSame(this)) {
n.internalRemove(true);
} 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: "
+ n.safeGetJCRPath());
}
}
// get desired version from version selector
VersionImpl v = (VersionImpl) vsel.select(history);
// check existing version of item exists
if (!itemMgr.itemExists(nodeId)) {
if (v == null) {
// if version selector was unable to select version,
// choose the initial one
Version[] vs = history.getRootVersion().getSuccessors();
if (vs.length == 0) {
String msg = "Unable to select appropariate version for " +
child.getName() + " using " + vsel;
log.error(msg);
throw new VersionException(msg);
}
v = (VersionImpl) vs[0];
}
restoredChild = addNode(child.getName(), v.getFrozenNode());
} else {
restoredChild = session.getNodeById(nodeId);
if (v == null || oldVersion == null || v.getName().equals(oldVersion)) {
v = null;
}
}
if (v != null) {
try {
restoredChild.internalRestore(v, vsel, removeExisting);
} catch (RepositoryException e) {
log.error("Error while restoring node: " + e.toString());
log.error(" child path: " + restoredChild.safeGetJCRPath());
log.error(" selected version: " + v.getName());
StringBuffer avail = new StringBuffer();
VersionIterator vi = history.getAllVersions();
while (vi.hasNext()) {
avail.append(vi.nextVersion().getName());
if (vi.hasNext()) {
avail.append(", ");
}