}
@Override
public Item getAncestor(final int depth) throws RepositoryException {
if (depth < 0) {
throw new ItemNotFoundException(
getPath() + "Invalid ancestor depth " + depth);
} else if (depth == 0) {
return sessionContext.getSession().getRootNode();
}
ItemDelegate ancestor = perform(new ItemOperation<ItemDelegate>(dlg) {
@Override
public ItemDelegate perform() throws RepositoryException {
String path = item.getPath();
int slash = 0;
for (int i = 0; i < depth - 1; i++) {
slash = PathUtils.getNextSlash(path, slash + 1);
if (slash == -1) {
throw new ItemNotFoundException(
path + ": Invalid ancestor depth " + depth);
}
}
slash = PathUtils.getNextSlash(path, slash + 1);
if (slash == -1) {