org.apache.jackrabbit.core
Class CachingHierarchyManager

java.lang.Object
  extended by org.apache.jackrabbit.core.HierarchyManagerImpl
      extended by org.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
provider, rootNodeId
 
Constructor Summary
CachingHierarchyManager(NodeId rootNodeId, ItemStateManager provider)
          Create a new instance of this class.
 
Method Summary
protected  void buildPath(PathBuilder builder, ItemState state)
          Adds the path element of an item id to the path currently being built.
 void enableConsistencyChecks(boolean enable)
          Enable or disable consistency checks in this instance.
 int getDepth(ItemId id)
          Returns the depth of the specified item which is equivalent to getPath(id).getAncestorCount().
 Name getName(ItemId id)
          Returns the name of the specified item.
 Path getPath(ItemId id)
          Returns the path to the given item.
 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.
 void nodeAdded(NodeState state, Name name, int index, NodeId id)
          Called when a child node has been added
 void nodeModified(NodeState modified)
          Called when a node has been modified, typically as a result of removal or addition of a child node.
 void nodeRemoved(NodeState state, Name 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.
protected  void pathResolved(ItemId id, PathBuilder builder)
          Called by HierarchyManagerImpl.resolvePath(org.apache.jackrabbit.spi.Path.Element[], int, ItemId, int).
protected  ItemId resolvePath(Path path, int typesAllowed)
          Internal implementation of HierarchyManagerImpl.resolvePath(Path) that will either resolve to a node or a property.
 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).
 String toString()
          Dump contents of path map and elements included to a string.
 
Methods inherited from class org.apache.jackrabbit.core.HierarchyManagerImpl
getChildNodeEntry, getChildNodeEntry, getItemState, getName, getParentId, getParentIds, getRelativeDepth, getRootNodeId, getShareRelativeDepth, hasItemState, isShareAncestor, resolveNodePath, resolvePath, resolvePath, resolvePropertyPath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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)
Create a new instance of this class.

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

enableConsistencyChecks

public void enableConsistencyChecks(boolean enable)
Enable or disable consistency checks in this instance.

Parameters:
enable - true to enable consistency checks; false to disable

resolvePath

protected ItemId resolvePath(Path path,
                             int typesAllowed)
                      throws RepositoryException
Internal implementation of HierarchyManagerImpl.resolvePath(Path) that will either resolve to a node or a property. Should be overridden by a subclass that can resolve an intermediate path into an ItemId. This subclass can then invoke HierarchyManagerImpl.resolvePath(org.apache.jackrabbit.spi.Path.Element[], int, ItemId, int) with a value of next greater than 1.

Overrides:
resolvePath in class HierarchyManagerImpl
Parameters:
path - path to resolve
typesAllowed - one of RETURN_ANY, RETURN_NODE or RETURN_PROPERTY
Returns:
id or null
Throws:
RepositoryException - if an error occurs

pathResolved

protected void pathResolved(ItemId id,
                            PathBuilder builder)
                     throws MalformedPathException
Called by HierarchyManagerImpl.resolvePath(org.apache.jackrabbit.spi.Path.Element[], int, ItemId, int). May be overridden by some subclass to process/cache intermediate state.

Overrides:
pathResolved in class HierarchyManagerImpl
Parameters:
id - id of resolved item
builder - path builder containing path resolved
Throws:
MalformedPathException - if the path contained in builder is malformed

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.

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

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
Returns:
Throws:
ItemNotFoundException
RepositoryException

getName

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

Specified by:
getName in interface HierarchyManager
Overrides:
getName in class HierarchyManagerImpl
Parameters:
id - 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
Overrides:
getDepth in class HierarchyManagerImpl
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

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
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

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'

nodeModified

public void nodeModified(NodeState modified)
Called when a node has been modified, typically as a result of removal or addition of a child node.

Please note, that this method is not called if ItemStateListener.stateModified(ItemState) was called. If path information is cached for modified, this iterates over all child nodes in the path map, evicting the ones that do not (longer) exist in the underlying NodeState.

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

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()

nodeAdded

public void nodeAdded(NodeState state,
                      Name 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.

Iterate over all cached children of this state and verify each child's position.

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

nodeRemoved

public void nodeRemoved(NodeState state,
                        Name 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

toString

public String toString()
Dump contents of path map and elements included to a string.

Overrides:
toString in class Object


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