int ancestorCnt = absPath.getAncestorCount();
int ancestorCnt = absPath.getAncestorCount();
public Item perform(SessionContext context) throws RepositoryException { if (degree == 0) { return context.getItemManager().getRootNode(); } try { // Path.getAncestor requires relative degree, i.e. we need // to convert absolute to relative ancestor degree Path path = getPrimaryPath(); int relDegree = path.getAncestorCount() - degree; if (relDegree < 0) { throw new ItemNotFoundException(); } else if (relDegree == 0) { return ItemImpl.this; // shortcut } Path ancestorPath = path.getAncestor(relDegree); return context.getItemManager().getNode(ancestorPath); } catch (PathNotFoundException e) { throw new ItemNotFoundException("Ancestor not found", e); } } public String toString() {
public Item perform(SessionContext context) throws RepositoryException { if (degree == 0) { return context.getItemManager().getRootNode(); } try { // Path.getAncestor requires relative degree, i.e. we need // to convert absolute to relative ancestor degree Path path = getPrimaryPath(); int relDegree = path.getAncestorCount() - degree; if (relDegree < 0) { throw new ItemNotFoundException(); } else if (relDegree == 0) { return ItemImpl.this; // shortcut } Path ancestorPath = path.getAncestor(relDegree); return context.getItemManager().getNode(ancestorPath); } catch (PathNotFoundException e) { throw new ItemNotFoundException("Ancestor not found", e); } } public String toString() {
/** * @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); } }
/** * @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); } }