code: public Item getAncestor(int degree) throws ItemNotFoundException, AccessDeniedException, RepositoryException
     {
        checkValid();
        try
        {
           // 6.2.8 If depth > n is specified then an ItemNotFoundException is
           // thrown.
           if (degree < 0)
           {
              throw new ItemNotFoundException("Can't get ancestor with ancestor's degree < 0.");
           }
  
           final QPath myPath = getData().getQPath();
           int n = myPath.getDepth() - degree;
           if (n == 0)
           {
              return this;
           }
           else if (n < 0)
           {
              throw new ItemNotFoundException("Can't get ancestor with ancestor's degree > depth of this item.");
           }
           else
           {
              final QPath ancestorPath = myPath.makeAncestorPath(n);
              return dataManager.getItem(ancestorPath, true);
           }
        }
        catch (PathNotFoundException e)
        {
           throw new ItemNotFoundException(e.getMessage(), e);
        }
     }
docs: {@inheritDoc}