org.apache.jackrabbit.core
Class HierarchyManagerImpl

java.lang.Object
  extended by org.apache.jackrabbit.core.HierarchyManagerImpl
All Implemented Interfaces:
HierarchyManager
Direct Known Subclasses:
CachingHierarchyManager, ZombieHierarchyManager

public class HierarchyManagerImpl
extends Object
implements HierarchyManager

HierarchyManagerImpl ...


Field Summary
protected  ItemStateManager provider
           
protected  PathResolver resolver
          Path resolver for outputting user-friendly paths in error messages.
protected  NodeId rootNodeId
           
 
Constructor Summary
HierarchyManagerImpl(NodeId rootNodeId, ItemStateManager provider, PathResolver resolver)
           
 
Method Summary
protected  void beforeResolvePath(Path path, ItemState state, int next)
          Called by recursively invoked method resolvePath(Path, ItemState, int, boolean); May be overridden by some subclass to process/cache intermediate state.
protected  void buildPath(PathBuilder builder, ItemState state)
          Adds the path element of an item id to the path currently being built.
protected  NodeState.ChildNodeEntry getChildNodeEntry(NodeState parent, Name name, int index)
          Returns the ChildNodeEntry of parent with the specified name and index or null if there's no such entry.
protected  NodeState.ChildNodeEntry getChildNodeEntry(NodeState parent, NodeId id)
          Returns the ChildNodeEntry of parent with the specified uuid or null if there's no such entry.
 int getDepth(ItemId id)
          Returns the depth of the specified item which is equivalent to getPath(id).getAncestorCount().
protected  ItemState getItemState(ItemId id)
          Return an item state, given its item id.
 Name getName(ItemId itemId)
          Returns the name of the specified item.
protected  NodeId getParentId(ItemState state)
          Returns the parentUUID of the given item.
 Path getPath(ItemId id)
          Returns the path to the given item.
 int getRelativeDepth(NodeId ancestorId, ItemId descendantId)
          Returns the depth of the specified descendant relative to the given ancestor.
 NodeId getRootNodeId()
           
protected  boolean hasItemState(ItemId id)
          Determines whether an item state for a given item id exists.
 boolean isAncestor(NodeId nodeId, ItemId itemId)
          Determines whether the node with the specified nodeId is an ancestor of the item denoted by the given itemId.
 NodeId resolveNodePath(Path path)
          Resolves a path into a node id.
 ItemId resolvePath(Path path)
          Resolves a path into an item id.
protected  ItemId resolvePath(Path path, ItemId id, int next, boolean denotesNode)
          Resolve a path into an item id.
 PropertyId resolvePropertyPath(Path path)
          Resolves a path into a property id.
 String safeGetJCRPath(ItemId id)
          Failsafe translation of internal ItemId to JCR path for use in error messages etc.
 String safeGetJCRPath(Path path)
          Failsafe conversion of internal Path to JCR path for use in error messages etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootNodeId

protected final NodeId rootNodeId

provider

protected final ItemStateManager provider

resolver

protected final PathResolver resolver
Path resolver for outputting user-friendly paths in error messages.

Constructor Detail

HierarchyManagerImpl

public HierarchyManagerImpl(NodeId rootNodeId,
                            ItemStateManager provider,
                            PathResolver resolver)
Method Detail

getRootNodeId

public NodeId getRootNodeId()

safeGetJCRPath

public String safeGetJCRPath(Path path)
Failsafe conversion of internal Path to JCR path for use in error messages etc.

Parameters:
path - path to convert
Returns:
JCR path

safeGetJCRPath

public String safeGetJCRPath(ItemId id)
Failsafe translation of internal ItemId to JCR path for use in error messages etc.

Parameters:
id - id to translate
Returns:
JCR path

getItemState

protected ItemState getItemState(ItemId id)
                          throws NoSuchItemStateException,
                                 ItemStateException
Return an item state, given its item id.

Low-level hook provided for specialized derived classes.

Parameters:
id - item id
Returns:
item state
Throws:
NoSuchItemStateException - if the item does not exist
ItemStateException - if an error occurs
See Also:
ZombieHierarchyManager.getItemState(ItemId)

hasItemState

protected boolean hasItemState(ItemId id)
Determines whether an item state for a given item id exists.

Low-level hook provided for specialized derived classes.

Parameters:
id - item id
Returns:
true if an item state exists, otherwise false
See Also:
ZombieHierarchyManager.hasItemState(ItemId)

getParentId

protected NodeId getParentId(ItemState state)
Returns the parentUUID of the given item.

Low-level hook provided for specialized derived classes.

Parameters:
state - item state
Returns:
parentUUID of the given item
See Also:
ZombieHierarchyManager.getParentId(ItemState)

getChildNodeEntry

protected NodeState.ChildNodeEntry getChildNodeEntry(NodeState parent,
                                                     NodeId id)
Returns the ChildNodeEntry of parent with the specified uuid or null if there's no such entry.

Low-level hook provided for specialized derived classes.

Parameters:
parent - node state
id - id of child node entry
Returns:
the ChildNodeEntry of parent with the specified uuid or null if there's no such entry.
See Also:
ZombieHierarchyManager.getChildNodeEntry(NodeState, NodeId)

getChildNodeEntry

protected NodeState.ChildNodeEntry getChildNodeEntry(NodeState parent,
                                                     Name name,
                                                     int index)
Returns the ChildNodeEntry of parent with the specified name and index or null if there's no such entry.

Low-level hook provided for specialized derived classes.

Parameters:
parent - node state
name - name of child node entry
index - index of child node entry
Returns:
the ChildNodeEntry of parent with the specified name and index or null if there's no such entry.
See Also:
ZombieHierarchyManager.getChildNodeEntry(NodeState, Name, int)

resolvePath

protected ItemId resolvePath(Path path,
                             ItemId id,
                             int next,
                             boolean denotesNode)
                      throws RepositoryException
Resolve a path into an item id. Recursively invoked method that may be overridden by some subclass to either return cached responses or add response to cache.

Parameters:
path - full path of item to resolve
id - intermediate item id
next - next path element index to resolve
denotesNode - flag indicating whether path refers to a node (true) or a property (false)
Returns:
the id of the item denoted by path
Throws:
RepositoryException - if an error occured

beforeResolvePath

protected void beforeResolvePath(Path path,
                                 ItemState state,
                                 int next)
Called by recursively invoked method resolvePath(Path, ItemState, int, boolean); May be overridden by some subclass to process/cache intermediate state.

Parameters:
path - full path of item to resolve
state - intermediate state
next - next path element index to resolve

buildPath

protected void buildPath(PathBuilder builder,
                         ItemState state)
                  throws ItemStateException,
                         RepositoryException
Adds the path element of an item id to the path currently being built. Recursively invoked method that may be overridden by some subclass to either return cached responses or add response to cache. On exit, builder contains the path of state.

Parameters:
builder - builder currently being used
state - item to find path of
Throws:
ItemStateException
RepositoryException

resolvePath

public ItemId resolvePath(Path path)
                   throws RepositoryException
Resolves a path into an item id.

If there is both a node and a property at the specified path, this method will return the id of the node.

Note that, for performance reasons, this method returns null rather than throwing a PathNotFoundException if there's no item to be found at path.

Specified by:
resolvePath in interface HierarchyManager
Parameters:
path - path to resolve
Returns:
item id refered to by path or null if there's no item at path.
Throws:
RepositoryException - if an error occurs

resolveNodePath

public NodeId resolveNodePath(Path path)
                       throws RepositoryException
Resolves a path into a node id.

Note that, for performance reasons, this method returns null rather than throwing a PathNotFoundException if there's no node to be found at path.

Specified by:
resolveNodePath in interface HierarchyManager
Parameters:
path - path to resolve
Returns:
node id refered to by path or null if there's no node at path.
Throws:
RepositoryException - if an error occurs

resolvePropertyPath

public PropertyId resolvePropertyPath(Path path)
                               throws RepositoryException
Resolves a path into a property id.

Note that, for performance reasons, this method returns null rather than throwing a PathNotFoundException if there's no property to be found at path.

Specified by:
resolvePropertyPath in interface HierarchyManager
Parameters:
path - path to resolve
Returns:
property id refered to by path or null if there's no property at path.
Throws:
RepositoryException - if an error occurs

getPath

public Path getPath(ItemId id)
             throws ItemNotFoundException,
                    RepositoryException
Returns the path to the given item.

Specified by:
getPath in interface HierarchyManager
Returns:
Throws:
ItemNotFoundException
RepositoryException

getName

public Name getName(ItemId itemId)
             throws ItemNotFoundException,
                    RepositoryException
Returns the name of the specified item.

Specified by:
getName in interface HierarchyManager
Parameters:
itemId - id of item whose name should be returned
Returns:
Throws:
ItemNotFoundException
RepositoryException

getDepth

public int getDepth(ItemId id)
             throws ItemNotFoundException,
                    RepositoryException
Returns the depth of the specified item which is equivalent to getPath(id).getAncestorCount(). The depth reflects the absolute hierarchy level.

Specified by:
getDepth in interface HierarchyManager
Parameters:
id - item id
Returns:
the depth of the specified item
Throws:
ItemNotFoundException - if the specified id does not denote an existing item.
RepositoryException - if another error occurs

getRelativeDepth

public int getRelativeDepth(NodeId ancestorId,
                            ItemId descendantId)
                     throws ItemNotFoundException,
                            RepositoryException
Returns the depth of the specified descendant relative to the given ancestor. If ancestorId and descendantId denote the same item 0 is returned. If ancestorId does not denote an ancestor -1 is returned.

Specified by:
getRelativeDepth in interface HierarchyManager
Parameters:
ancestorId - ancestor id
descendantId - descendant id
Returns:
the relative depth; -1 if ancestorId does not denote an ancestor of the item denoted by descendantId (or itself).
Throws:
ItemNotFoundException - if either of the specified id's does not denote an existing item.
RepositoryException - if another error occurs

isAncestor

public boolean isAncestor(NodeId nodeId,
                          ItemId itemId)
                   throws ItemNotFoundException,
                          RepositoryException
Determines whether the node with the specified nodeId is an ancestor of the item denoted by the given itemId. This is equivalent to getPath(nodeId).isAncestorOf(getPath(itemId)).

Specified by:
isAncestor in interface HierarchyManager
Parameters:
nodeId - node id
itemId - item id
Returns:
true if the node with the specified nodeId is an ancestor of the item denoted by the given itemIdfalse otherwise
Throws:
ItemNotFoundException - if any of the specified id's does not denote an existing item.
RepositoryException - if another error occurs


Copyright © 2004-2008 The Apache Software Foundation. All Rights Reserved.