org.apache.jackrabbit.core
Class CachingHierarchyManager

java.lang.Object
  extended byorg.apache.jackrabbit.core.HierarchyManagerImpl
      extended byorg.apache.jackrabbit.core.CachingHierarchyManager
All Implemented Interfaces:
HierarchyManager, ItemStateListener, NodeStateListener

public class CachingHierarchyManager
extends HierarchyManagerImpl
implements NodeStateListener

Implementation of a HierarchyManager that caches paths of items.


Field Summary
static int DEFAULT_UPPER_LIMIT
          Default upper limit of cached states
 
Fields inherited from class org.apache.jackrabbit.core.HierarchyManagerImpl
nsResolver, provider, rootNodeId
 
Constructor Summary
CachingHierarchyManager(NodeId rootNodeId, ItemStateManager provider, NamespaceResolver nsResolver)
          Create a new instance of this class.
 
Method Summary
protected  void buildPath(Path.PathBuilder builder, ItemState state)
          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.

Overridden method tries to find a mapping for the intermediate item state and add its path elements to the builder currently being used.

 int getDepth(ItemId id)
          Returns the depth of the specified item which is equivalent to getPath(id).getAncestorCount(). The depth reflects the absolute hierarchy level.
 QName getName(ItemId id)
          Returns the name of the specified item.
 Path getPath(ItemId id)
          Returns the path to the given item.

Overridden method simply checks whether we have an item matching the id and returns its path, otherwise calls base implementation.

 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. This is equivalent to getPath(nodeId).isAncestorOf(getPath(itemId)).
 void nodeAdded(NodeState state, QName name, int index, NodeId id)
          Called when a child node has been added
 void nodeRemoved(NodeState state, QName name, int index, NodeId id)
          Called when a child node has been removed
 void nodesReplaced(NodeState state)
          Called when the children nodes were replaced by other nodes, typically as result of a reorder operation.

Generate subsequent add and remove notifications for every replacement.

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

Check the path indicated inside our cache first.

protected  ItemId resolvePath(Path path, ItemState state, int next)
          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.

Cache the intermediate item inside our cache.

 void stateCreated(ItemState created)
          Called when an ItemState has successfully been created (i.e. its underlying persistent state was created).
 void stateDestroyed(ItemState destroyed)
          Called when an ItemState has successfully been removed (i.e. its underlying persistent state has been destroyed).
 void stateDiscarded(ItemState discarded)
          Called when an ItemState has been discarded (i.e. it has been rendered 'invalid').
 void stateModified(ItemState modified)
          Called when an ItemState has successfully been modified (i.e. its underlying persistent state has changed).
 void stateOverlaid(ItemState overlayer)
          Called when an ItemState has been overlaid by some other state that now takes its identity.
 void stateUncovered(ItemState overlayer)
          Called when an ItemState no longer overlayes some other item state.
 
Methods inherited from class org.apache.jackrabbit.core.HierarchyManagerImpl
getChildNodeEntry, getChildNodeEntry, getItemState, getNamespaceResolver, getParentId, getRelativeDepth, getRootNodeId, hasItemState, resolvePath, safeGetJCRPath, safeGetJCRPath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_UPPER_LIMIT

public static final int DEFAULT_UPPER_LIMIT
Default upper limit of cached states

See Also:
Constant Field Values
Constructor Detail

CachingHierarchyManager

public CachingHierarchyManager(NodeId rootNodeId,
                               ItemStateManager provider,
                               NamespaceResolver nsResolver)
Create a new instance of this class.

Parameters:
rootNodeId - root node id
provider - item state manager
nsResolver - namespace resolver
Method Detail

resolvePath

protected ItemId resolvePath(Path path,
                             ItemState state,
                             int next)
                      throws PathNotFoundException,
                             ItemStateException
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.

Cache the intermediate item inside our cache.

Overrides:
resolvePath in class HierarchyManagerImpl
Parameters:
path - full path of item to resolve
state - intermediate state
next - next path element index to resolve
Returns:
the id of the item denoted by path
Throws:
PathNotFoundException
ItemStateException

buildPath

protected void buildPath(Path.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.

Overridden method tries to find a mapping for the intermediate item state and add its path elements to the builder currently being used. If no mapping is found, the item is cached instead after the base implementation has been invoked.

Overrides:
buildPath in class HierarchyManagerImpl
Parameters:
builder - builder currently being used
state - item to find path of
Throws:
ItemStateException
RepositoryException

resolvePath

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

Check the path indicated inside our cache first.

Specified by:
resolvePath in interface HierarchyManager
Overrides:
resolvePath in class HierarchyManagerImpl
Throws:
PathNotFoundException
RepositoryException

getPath

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

Overridden method simply checks whether we have an item matching the id and returns its path, otherwise calls base implementation.

Specified by:
getPath in interface HierarchyManager
Overrides:
getPath in class HierarchyManagerImpl
Throws:
ItemNotFoundException
RepositoryException

getName

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

Specified by:
getName in interface HierarchyManager
Overrides:
getName in class HierarchyManagerImpl
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
Overrides:
getDepth in class HierarchyManagerImpl
Throws:
ItemNotFoundException
RepositoryException

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
Overrides:
isAncestor in class HierarchyManagerImpl
Throws:
ItemNotFoundException
RepositoryException

stateCreated

public void stateCreated(ItemState created)
Called when an ItemState has successfully been created (i.e. its underlying persistent state was created).

Specified by:
stateCreated in interface ItemStateListener
Parameters:
created - the ItemState that has been 'created'

stateModified

public void stateModified(ItemState modified)
Called when an ItemState has successfully been modified (i.e. its underlying persistent state has changed).

Specified by:
stateModified in interface ItemStateListener
Parameters:
modified - the ItemState that has been 'modified'

stateDestroyed

public void stateDestroyed(ItemState destroyed)
Called when an ItemState has successfully been removed (i.e. its underlying persistent state has been destroyed).

Specified by:
stateDestroyed in interface ItemStateListener
Parameters:
destroyed - the ItemState that has been 'destroyed'

stateDiscarded

public void stateDiscarded(ItemState discarded)
Called when an ItemState has been discarded (i.e. it has been rendered 'invalid').

Specified by:
stateDiscarded in interface ItemStateListener
Parameters:
discarded - the ItemState that has been discarded
See Also:
ItemState.discard()

stateOverlaid

public void stateOverlaid(ItemState overlayer)
Called when an ItemState has been overlaid by some other state that now takes its identity. This notification is sent on the state being overlaid.

Parameters:
overlayer - the ItemState that overlays this state

stateUncovered

public void stateUncovered(ItemState overlayer)
Called when an ItemState no longer overlayes some other item state. This notification is sent on the state overlaying another state.

Parameters:
overlayer - the ItemState that overlaid another item state. To get the overlaid state, invoke ItemState.getOverlayedState()

nodeAdded

public void nodeAdded(NodeState state,
                      QName name,
                      int index,
                      NodeId id)
Called when a child node has been added

Specified by:
nodeAdded in interface NodeStateListener
Parameters:
state - node state that changed
name - name of node that was added
index - index of new node
id - id of new node

nodesReplaced

public void nodesReplaced(NodeState state)
Called when the children nodes were replaced by other nodes, typically as result of a reorder operation.

Generate subsequent add and remove notifications for every replacement.

Specified by:
nodesReplaced in interface NodeStateListener
Parameters:
state - node state that changed

nodeRemoved

public void nodeRemoved(NodeState state,
                        QName name,
                        int index,
                        NodeId id)
Called when a child node has been removed

Specified by:
nodeRemoved in interface NodeStateListener
Parameters:
state - node state that changed
name - name of node that was removed
index - index of removed node
id - id of removed node


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