org.apache.jackrabbit.commons
Class AbstractItem

java.lang.Object
  extended by org.apache.jackrabbit.commons.AbstractItem
All Implemented Interfaces:
javax.jcr.Item
Direct Known Subclasses:
AbstractNode, AbstractProperty

public abstract class AbstractItem
extends Object
implements javax.jcr.Item

Abstract base class for implementing the JCR Item interface.

Item methods without a default implementation:


Constructor Summary
AbstractItem()
           
 
Method Summary
 javax.jcr.Item getAncestor(int depth)
          Returns the ancestor of this item at the given depth.
 int getDepth()
          Returns the depth of this item.
 String toString()
          Returns a string representation of this item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.jcr.Item
accept, getName, getParent, getPath, getSession, isModified, isNew, isNode, isSame, refresh, remove, save
 

Constructor Detail

AbstractItem

public AbstractItem()
Method Detail

getAncestor

public javax.jcr.Item getAncestor(int depth)
                           throws javax.jcr.ItemNotFoundException,
                                  javax.jcr.AccessDeniedException,
                                  javax.jcr.RepositoryException
Returns the ancestor of this item at the given depth.

The default implementation handles the root node at depth zero and this item at depth equal to the depth of this item as special cases, and uses Session.getItem(String) to retrieve other ancestors based on the ancestor path calculated from the path of this node as returned by Item.getPath().

Specified by:
getAncestor in interface javax.jcr.Item
Parameters:
depth - depth of the returned ancestor item
Returns:
ancestor item
Throws:
javax.jcr.ItemNotFoundException - if the given depth is negative or greater than the depth of this item
javax.jcr.AccessDeniedException - if access to the ancestor item is denied
javax.jcr.RepositoryException - if an error occurs

getDepth

public int getDepth()
             throws javax.jcr.RepositoryException
Returns the depth of this item.

The default implementation determines the depth by counting the slashes in the path returned by Item.getPath().

Specified by:
getDepth in interface javax.jcr.Item
Returns:
depth of this item
Throws:
javax.jcr.RepositoryException - if an error occurs

toString

public String toString()
Returns a string representation of this item.

The default implementation returns the path of this item and falls back to the Object.toString() implementation if the item path can not be retrieved.

Overrides:
toString in class Object
Returns:
string representation of this item


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.