throw new InvalidItemStateException("Session has pending changes ");
if (((VersionImpl)version).getInternalName().equals(Constants.JCR_ROOTVERSION))
throw new VersionException("It is illegal to call restore() on jcr:rootVersion");
QPath destPath = locationFactory.parseRelPath(relPath).getInternalPath();
NodeImpl destParent =
(NodeImpl)dataManager.getItem(nodeData(), destPath.makeParentPath().getEntries(), false, ItemType.NODE);
if (destParent == null)
throw new PathNotFoundException("Parent not found for " + relPath);
if (!destParent.isNode())
throw new ConstraintViolationException("Parent item is not a node. Rel path " + relPath);
NodeImpl destNode =
(NodeImpl)dataManager.getItem(destParent.nodeData(),
new QPathEntry(destPath.getName(), destPath.getIndex()), false, ItemType.NODE);
if (destNode != null)
{
// Dest node exists
if (!destNode.isNode())
throw new ConstraintViolationException("Item at relPath is not a node " + destNode.getPath());
if (!destNode.isNodeType(Constants.MIX_VERSIONABLE))
throw new UnsupportedRepositoryOperationException("Node at relPath is not versionable "
+ destNode.getPath());
if (!destNode.versionHistory(false).isVersionBelongToThis(version))
throw new VersionException("Bad version " + version.getPath());
// Check locking
if (!destNode.parent().checkLocking())
throw new LockException("Node " + destNode.getPath() + " is locked ");
}
else
{
// Dest node not found
if (!destParent.checkedOut())
throw new VersionException("Parent of a node at relPath is versionable and checked-in "
+ destParent.getPath());
}
((VersionImpl)version).restore(session, destParent.nodeData(), destPath.getName(), removeExisting);
}
}