Class HierarchyManagerImpl
- java.lang.Object
-
- org.apache.jackrabbit.core.HierarchyManagerImpl
-
- All Implemented Interfaces:
HierarchyManager
- Direct Known Subclasses:
CachingHierarchyManager
,ZombieHierarchyManager
public class HierarchyManagerImpl extends Object implements HierarchyManager
HierarchyManagerImpl
...
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
HierarchyManagerImpl.CycleDetector
Utility class used to detect path cycles with as little overhead as possible.
-
Field Summary
Fields Modifier and Type Field Description protected ItemStateManager
provider
protected NodeId
rootNodeId
-
Constructor Summary
Constructors Constructor Description HierarchyManagerImpl(NodeId rootNodeId, ItemStateManager provider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
buildPath(PathBuilder builder, ItemState state, HierarchyManagerImpl.CycleDetector detector)
Adds the path element of an item id to the path currently being built.protected ChildNodeEntry
getChildNodeEntry(NodeState parent, NodeId id)
Returns theChildNodeEntry
ofparent
with the specifieduuid
ornull
if there's no such entry.protected ChildNodeEntry
getChildNodeEntry(NodeState parent, Name name, int index)
Returns theChildNodeEntry
ofparent
with the specifiedname
andindex
ornull
if there's no such entry.int
getDepth(ItemId id)
Returns the depth of the specified item which is equivalent togetPath(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.Name
getName(NodeId id, NodeId parentId)
Returns the name of the specified item, with the given parent id.protected NodeId
getParentId(ItemState state)
Returns theparentUUID
of the given item.protected Set<NodeId>
getParentIds(ItemState state, boolean useOverlayed)
Return all parents of a node.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()
int
getShareRelativeDepth(NodeId ancestor, ItemId descendant)
Returns the depth of the specified share-descendant relative to the given share-ancestor.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 specifiednodeId
is an ancestor of the item denoted by the givenitemId
.boolean
isShareAncestor(NodeId ancestor, NodeId descendant)
Determines whether the node with the specifiedancestor
is a share ancestor of the item denoted by the givendescendant
.protected void
pathResolved(ItemId id, PathBuilder builder)
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.Element[] elements, int next, ItemId id, int typesAllowed)
Internal implementation that iteratively resolves a path into an item.protected ItemId
resolvePath(Path path, int typesAllowed)
Internal implementation ofresolvePath(Path)
that will either resolve to a node or a property.PropertyId
resolvePropertyPath(Path path)
Resolves a path into a property id.
-
-
-
Field Detail
-
rootNodeId
protected final NodeId rootNodeId
-
provider
protected final ItemStateManager provider
-
-
Constructor Detail
-
HierarchyManagerImpl
public HierarchyManagerImpl(NodeId rootNodeId, ItemStateManager provider)
-
-
Method Detail
-
getRootNodeId
public NodeId getRootNodeId()
-
resolvePath
protected ItemId resolvePath(Path.Element[] elements, int next, ItemId id, int typesAllowed) throws ItemStateException, MalformedPathException
Internal implementation that iteratively resolves a path into an item.- Parameters:
elements
- path elementsnext
- index of next item inelements
to inspectid
- id of item at pathelements[0]
..elements[next - 1]
typesAllowed
- one ofRETURN_ANY
,RETURN_NODE
orRETURN_PROPERTY
- Returns:
- id or
null
- Throws:
ItemStateException
- if an intermediate item state is not foundMalformedPathException
- if building an intermediate path fails
-
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 existItemStateException
- 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, otherwisefalse
- See Also:
ZombieHierarchyManager.hasItemState(ItemId)
-
getParentId
protected NodeId getParentId(ItemState state)
Returns theparentUUID
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)
-
getParentIds
protected Set<NodeId> getParentIds(ItemState state, boolean useOverlayed)
Return all parents of a node. A shareable node has possibly more than one parent.- Parameters:
state
- item stateuseOverlayed
- whether to use overlayed state for shareable nodes- Returns:
- set of parent
NodeId
s. If state has no parent, array has length0
.
-
getChildNodeEntry
protected ChildNodeEntry getChildNodeEntry(NodeState parent, NodeId id)
Returns theChildNodeEntry
ofparent
with the specifieduuid
ornull
if there's no such entry.Low-level hook provided for specialized derived classes.
- Parameters:
parent
- node stateid
- id of child node entry- Returns:
- the
ChildNodeEntry
ofparent
with the specifieduuid
ornull
if there's no such entry. - See Also:
ZombieHierarchyManager.getChildNodeEntry(NodeState, NodeId)
-
getChildNodeEntry
protected ChildNodeEntry getChildNodeEntry(NodeState parent, Name name, int index)
Returns theChildNodeEntry
ofparent
with the specifiedname
andindex
ornull
if there's no such entry.Low-level hook provided for specialized derived classes.
- Parameters:
parent
- node statename
- name of child node entryindex
- index of child node entry- Returns:
- the
ChildNodeEntry
ofparent
with the specifiedname
andindex
ornull
if there's no such entry. - See Also:
ZombieHierarchyManager.getChildNodeEntry(NodeState, Name, int)
-
buildPath
protected void buildPath(PathBuilder builder, ItemState state, HierarchyManagerImpl.CycleDetector detector) 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 ofstate
.- Parameters:
builder
- builder currently being usedstate
- item to find path ofdetector
- path cycle detector- Throws:
ItemStateException
RepositoryException
-
resolvePath
protected ItemId resolvePath(Path path, int typesAllowed) throws RepositoryException
Internal implementation ofresolvePath(Path)
that will either resolve to a node or a property. Should be overridden by a subclass that can resolve an intermediate path into anItemId
. This subclass can then invokeresolvePath(org.apache.jackrabbit.spi.Path.Element[], int, ItemId, int)
with a value ofnext
greater than1
.- Parameters:
path
- path to resolvetypesAllowed
- one ofRETURN_ANY
,RETURN_NODE
orRETURN_PROPERTY
- Returns:
- id or
null
- Throws:
RepositoryException
- if an error occurs
-
pathResolved
protected void pathResolved(ItemId id, PathBuilder builder) throws MalformedPathException
Called byresolvePath(org.apache.jackrabbit.spi.Path.Element[], int, ItemId, int)
. May be overridden by some subclass to process/cache intermediate state.- Parameters:
id
- id of resolved itembuilder
- path builder containing path resolved- Throws:
MalformedPathException
- if the path contained inbuilder
is malformed
-
resolvePath
public final 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 aPathNotFoundException
if there's no item to be found atpath
.- Specified by:
resolvePath
in interfaceHierarchyManager
- Parameters:
path
- path to resolve- Returns:
- item id referred to by
path
ornull
if there's no item atpath
. - 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 aPathNotFoundException
if there's no node to be found atpath
.- Specified by:
resolveNodePath
in interfaceHierarchyManager
- Parameters:
path
- path to resolve- Returns:
- node id referred to by
path
ornull
if there's no node atpath
. - 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 aPathNotFoundException
if there's no property to be found atpath
.- Specified by:
resolvePropertyPath
in interfaceHierarchyManager
- Parameters:
path
- path to resolve- Returns:
- property id referred to by
path
ornull
if there's no property atpath
. - 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 interfaceHierarchyManager
- Returns:
- Throws:
ItemNotFoundException
RepositoryException
-
getName
public Name getName(ItemId itemId) throws ItemNotFoundException, RepositoryException
Returns the name of the specified item.- Specified by:
getName
in interfaceHierarchyManager
- Parameters:
itemId
- id of item whose name should be returned- Returns:
- Throws:
ItemNotFoundException
RepositoryException
-
getName
public Name getName(NodeId id, NodeId parentId) throws ItemNotFoundException, RepositoryException
Returns the name of the specified item, with the given parent id. If the given item is not shareable, this is identical toHierarchyManager.getName(ItemId)
.- Specified by:
getName
in interfaceHierarchyManager
- Parameters:
id
- node idparentId
- parent node id- Returns:
- name
- Throws:
ItemNotFoundException
RepositoryException
-
getDepth
public int getDepth(ItemId id) throws ItemNotFoundException, RepositoryException
Returns the depth of the specified item which is equivalent togetPath(id).getAncestorCount()
. The depth reflects the absolute hierarchy level.- Specified by:
getDepth
in interfaceHierarchyManager
- Parameters:
id
- item id- Returns:
- the depth of the specified item
- Throws:
ItemNotFoundException
- if the specifiedid
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. IfancestorId
anddescendantId
denote the same item 0 is returned. IfancestorId
does not denote an ancestor -1 is returned.- Specified by:
getRelativeDepth
in interfaceHierarchyManager
- Parameters:
ancestorId
- ancestor iddescendantId
- descendant id- Returns:
- the relative depth; -1 if
ancestorId
does not denote an ancestor of the item denoted bydescendantId
(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 specifiednodeId
is an ancestor of the item denoted by the givenitemId
. This is equivalent togetPath(nodeId).isAncestorOf(getPath(itemId))
.- Specified by:
isAncestor
in interfaceHierarchyManager
- Parameters:
nodeId
- node iditemId
- item id- Returns:
true
if the node with the specifiednodeId
is an ancestor of the item denoted by the givenitemId
;false
otherwise- Throws:
ItemNotFoundException
- if any of the specified id's does not denote an existing item.RepositoryException
- if another error occurs
-
isShareAncestor
public boolean isShareAncestor(NodeId ancestor, NodeId descendant) throws ItemNotFoundException, RepositoryException
Determines whether the node with the specifiedancestor
is a share ancestor of the item denoted by the givendescendant
. This istrue
for two nodesA
,B
if either:A
is a (proper) ancestor ofB
- there is a non-empty sequence of nodes
N1
,... ,Nk
such thatA
=N1
andB
=Nk
andNi
is the parent or a share-parent ofNi+1
(for everyi
in1
...k-1
.
- Specified by:
isShareAncestor
in interfaceHierarchyManager
- Parameters:
ancestor
- node iddescendant
- item id- Returns:
true
if the node denoted byancestor
is a share ancestor of the item denoted bydescendant
,false
otherwise- Throws:
ItemNotFoundException
- if any of the specified id's does not denote an existing item.RepositoryException
- if another error occurs
-
getShareRelativeDepth
public int getShareRelativeDepth(NodeId ancestor, ItemId descendant) throws ItemNotFoundException, RepositoryException
Returns the depth of the specified share-descendant relative to the given share-ancestor. Ifancestor
anddescendant
denote the same item,0
is returned. Ifancestor
does not denote an share-ancestor-1
is returned.- Specified by:
getShareRelativeDepth
in interfaceHierarchyManager
- Parameters:
ancestor
- ancestor iddescendant
- descendant id- Returns:
- the relative depth;
-1
ifancestor
does not denote a share-ancestor of the item denoted bydescendant
(or itself). - Throws:
ItemNotFoundException
- if either of the specified id's does not denote an existing item.RepositoryException
- if another error occurs
-
-