use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class ItemImpl method getAncestor.
/**
* @see javax.jcr.Item#getAncestor(int)
*/
public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
checkStatus();
if (depth == 0) {
return session.getRootNode();
}
String msg = "No ancestor at depth = " + depth;
try {
// Path.getAncestor requires relative degree, i.e. we need
// to convert absolute to relative ancestor degree
Path path = getQPath();
int relDegree = path.getAncestorCount() - depth;
if (relDegree < 0) {
throw new ItemNotFoundException(msg);
}
Path ancestorPath = path.getAncestor(relDegree);
if (relDegree == 0) {
return this;
} else {
return getItemManager().getNode(ancestorPath);
}
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(msg);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class WorkspaceRestoreTest method setUp.
protected void setUp() throws Exception {
super.setUp();
VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
String path = versionableNode.getPath();
version = versionManager.checkin(path);
versionManager.checkout(path);
version2 = versionManager.checkin(path);
versionManager.checkout(path);
rootVersion = versionManager.getVersionHistory(path).getRootVersion();
// build a second versionable node below the testroot
try {
versionableNode2 = createVersionableNode(testRootNode, nodeName2, versionableNodeType);
} catch (RepositoryException e) {
fail("Failed to create a second versionable node: " + e.getMessage());
}
try {
wSuperuser = getHelper().getSuperuserSession(workspaceName);
} catch (RepositoryException e) {
fail("Failed to retrieve superuser session for second workspace '" + workspaceName + "': " + e.getMessage());
}
// test if the required nodes exist in the second workspace if not try to clone them
try {
testRootNode.getCorrespondingNodePath(workspaceName);
} catch (ItemNotFoundException e) {
// clone testRoot
wSuperuser.getWorkspace().clone(superuser.getWorkspace().getName(), testRoot, testRoot, true);
}
try {
versionableNode.getCorrespondingNodePath(workspaceName);
} catch (ItemNotFoundException e) {
// clone versionable node
wSuperuser.getWorkspace().clone(superuser.getWorkspace().getName(), versionableNode.getPath(), versionableNode.getPath(), true);
}
try {
versionableNode2.getCorrespondingNodePath(workspaceName);
} catch (ItemNotFoundException e) {
// clone second versionable node
wSuperuser.getWorkspace().clone(superuser.getWorkspace().getName(), versionableNode2.getPath(), versionableNode2.getPath(), true);
}
try {
// set node-fields (wTestRoot, wVersionableNode, wVersionableNode2)
// and check versionable nodes out.
wTestRoot = (Node) wSuperuser.getItem(testRootNode.getPath());
wVersionableNode = wSuperuser.getNodeByIdentifier(versionableNode.getIdentifier());
wVersionableNode.getSession().getWorkspace().getVersionManager().checkout(wVersionableNode.getPath());
wVersionableNode2 = wSuperuser.getNodeByIdentifier(versionableNode2.getIdentifier());
wVersionableNode2.getSession().getWorkspace().getVersionManager().checkout(wVersionableNode2.getPath());
} catch (RepositoryException e) {
fail("Failed to setup test environment in workspace: " + e.toString());
}
// that is not present in the default workspace.
try {
wVersionableChildNode = createVersionableNode(wVersionableNode, nodeName4, versionableNodeType);
} catch (RepositoryException e) {
fail("Failed to create versionable child node in second workspace: " + e.getMessage());
}
// create a version of the versionable child node
VersionManager wVersionManager = wVersionableChildNode.getSession().getWorkspace().getVersionManager();
String wPath = wVersionableChildNode.getPath();
wVersionManager.checkout(wPath);
wChildVersion = wVersionManager.checkin(wPath);
wVersionManager.checkout(wPath);
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class ItemManagerImpl method getItem.
/**
* @see ItemManager#getItem(HierarchyEntry)
*/
public Item getItem(HierarchyEntry hierarchyEntry) throws ItemNotFoundException, RepositoryException {
session.checkIsAlive();
ItemState state = hierarchyEntry.getItemState();
if (!state.isValid()) {
throw new ItemNotFoundException(LogUtil.safeGetJCRPath(state, session.getPathResolver()));
}
// first try to access item from cache
Item item = itemCache.getItem(state);
// not yet in cache, need to create instance
if (item == null) {
// create instance of item
if (hierarchyEntry.denotesNode()) {
item = createNodeInstance((NodeState) state);
} else {
item = createPropertyInstance((PropertyState) state);
}
}
return item;
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class ItemManagerImpl method hasChildProperties.
/**
* @see ItemManager#hasChildProperties(NodeEntry)
*/
public synchronized boolean hasChildProperties(NodeEntry parentEntry) throws ItemNotFoundException, RepositoryException {
// check sanity of session
session.checkIsAlive();
Iterator<PropertyEntry> iter = parentEntry.getPropertyEntries();
while (iter.hasNext()) {
try {
PropertyEntry entry = iter.next();
// check read access by accessing the propState (also implicit validation).
entry.getPropertyState();
return true;
} catch (ItemNotFoundException e) {
// should not occur. ignore
log.debug("Failed to access node state.", e);
}
}
return false;
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class ItemManagerImpl method hasChildNodes.
/**
* @see ItemManager#hasChildNodes(NodeEntry)
*/
public synchronized boolean hasChildNodes(NodeEntry parentEntry) throws ItemNotFoundException, RepositoryException {
// check sanity of session
session.checkIsAlive();
Iterator<NodeEntry> iter = parentEntry.getNodeEntries();
while (iter.hasNext()) {
try {
// check read access by accessing the nodeState (implicit validation check)
NodeEntry entry = iter.next();
entry.getNodeState();
return true;
} catch (ItemNotFoundException e) {
// should not occur. ignore
log.debug("Failed to access node state.", e);
}
}
return false;
}
Aggregations