Class ItemSequence
- java.lang.Object
-
- org.apache.jackrabbit.commons.flat.ItemSequence
-
- Direct Known Subclasses:
ItemSequence.NodeSequenceImpl
,ItemSequence.PropertySequenceImpl
public abstract class ItemSequence extends Object
This class serves as main entry point for obtaining sequences of
Node
s andProperty
s. It provides factory methods for creatingNodeSequence
s andPropertySequence
s.NodeSequence and PropertySequence instances provide a flat representation of a JCR hierarchy rooted at a certain node. They allow iterating over all items, retrieving items by key, checking whether a given key is mapped, adding new items and removing existing items.
The specifics of the mapping from the flat representation to the JCR hierarchy are delegated to a
TreeManager
. Particularly the TreeManager specifies the order of the items when retrieved as sequence and when and how to add and remove intermediate nodes when new items are inserted or removed.An
TreeTraverser.ErrorHandler
is used to handle exceptions which occur while traversing the hierarchy.- See Also:
TreeTraverser
,NodeSequence
,PropertySequence
,TreeManager
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ItemSequence.NodeSequenceImpl
protected static class
ItemSequence.PropertySequenceImpl
-
Field Summary
Fields Modifier and Type Field Description protected boolean
autoSave
protected TreeTraverser.ErrorHandler
errorHandler
TheTreeTraverser.ErrorHandler
instance used for handling exceptions occurring while traversing the hierarchy.protected Comparator<String>
order
protected Node
root
protected TreeManager
treeManager
TheTreeManager
instance managing the mapping between the sequence view and the JCR hierarchy.
-
Constructor Summary
Constructors Modifier Constructor Description protected
ItemSequence(TreeManager treeManager, TreeTraverser.ErrorHandler errorHandler)
Create a newItemSequence
instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static NodeSequence
createNodeSequence(TreeManager treeManager)
Create a newNodeSequence
instance.static NodeSequence
createNodeSequence(TreeManager treeManager, TreeTraverser.ErrorHandler errorHandler)
Create a newNodeSequence
instance.static PropertySequence
createPropertySequence(TreeManager treeManager)
Create a newPropertySequence
instance.static PropertySequence
createPropertySequence(TreeManager treeManager, TreeTraverser.ErrorHandler errorHandler)
Create a newPropertySequence
instance.protected Node
getMinimal()
Returns the node with the minimal key wrt.protected Node
getMinimal(Node node)
Returns the node amongst the child nodes ofnode
whose key is minimal wrt.NodeSequence
getNodeSequence()
Create a newNodeSequence
instance with the same parameterization as this instance.protected abstract Node
getParent(String key)
Returns the parent node for the given key.protected Node
getPredecessor(String key)
Returns the predecessor node for the givenkey
.protected Node
getPredecessor(Node node, String key)
Returns the direct predecessor ofkey
amongstnode
's child nodes wrt.PropertySequence
getPropertySequence()
Create a newPropertySequence
instance with the same parametrization as this instance.protected Node
getSuccessor(Node node, String key)
Returns the successor node for the givenkey
.protected void
renamePath(Node node, String key)
Rename the path of the node with the minimal key.
-
-
-
Field Detail
-
treeManager
protected final TreeManager treeManager
TheTreeManager
instance managing the mapping between the sequence view and the JCR hierarchy.
-
errorHandler
protected final TreeTraverser.ErrorHandler errorHandler
TheTreeTraverser.ErrorHandler
instance used for handling exceptions occurring while traversing the hierarchy.
-
root
protected final Node root
- See Also:
TreeManager.getRoot()
-
order
protected final Comparator<String> order
- See Also:
TreeManager.getOrder()
-
autoSave
protected final boolean autoSave
- See Also:
TreeManager.getAutoSave()
-
-
Constructor Detail
-
ItemSequence
protected ItemSequence(TreeManager treeManager, TreeTraverser.ErrorHandler errorHandler)
Create a newItemSequence
instance.- Parameters:
treeManager
- TheTreeManager
for managing the mapping between the sequence view and the JCR hierarchy.errorHandler
- TheTreeTraverser.ErrorHandler
for handling exceptions occurring while traversing the hierarchy.- Throws:
IllegalArgumentException
- If eithertreeManager
isnull
orTreeManager.getRoot()
returnnull
orTreeManager.getOrder()
returnnull
.
-
-
Method Detail
-
createNodeSequence
public static NodeSequence createNodeSequence(TreeManager treeManager, TreeTraverser.ErrorHandler errorHandler)
Create a newNodeSequence
instance.- Parameters:
treeManager
- TheTreeManager
for managing the mapping between the sequence view and the JCR hierarchy.errorHandler
- TheTreeTraverser.ErrorHandler
for handling exceptions occurring while- Returns:
-
createNodeSequence
public static NodeSequence createNodeSequence(TreeManager treeManager)
Create a newNodeSequence
instance.- Parameters:
treeManager
- TheTreeManager
for managing the mapping between the sequence view and the JCR hierarchy.- Returns:
-
createPropertySequence
public static PropertySequence createPropertySequence(TreeManager treeManager, TreeTraverser.ErrorHandler errorHandler)
Create a newPropertySequence
instance.- Parameters:
treeManager
- TheTreeManager
for managing the mapping between the sequence view and the JCR hierarchy.errorHandler
- TheTreeTraverser.ErrorHandler
for handling exceptions occurring while- Returns:
-
createPropertySequence
public static PropertySequence createPropertySequence(TreeManager treeManager)
Create a newPropertySequence
instance.- Parameters:
treeManager
- TheTreeManager
for managing the mapping between the sequence view and the JCR hierarchy.- Returns:
-
getNodeSequence
public NodeSequence getNodeSequence()
Create a newNodeSequence
instance with the same parameterization as this instance.- Returns:
-
getPropertySequence
public PropertySequence getPropertySequence()
Create a newPropertySequence
instance with the same parametrization as this instance.- Returns:
-
getParent
protected abstract Node getParent(String key) throws RepositoryException
Returns the parent node for the given key. When the key is not present in this sequence already, the returned node is the node that would contain that key if it where present.- Throws:
RepositoryException
-
getPredecessor
protected final Node getPredecessor(String key) throws RepositoryException
Returns the predecessor node for the givenkey
. That is the node whose key directly precedes the passedkey
in the order determined byTreeManager.getOrder()
. There are two cases:- A node with the given
key
is mapped: then that node is returned. - A node with the given
key
is not mapped: the the node where that would contain that key if present is returned.
- Throws:
RepositoryException
- A node with the given
-
getPredecessor
protected final Node getPredecessor(Node node, String key) throws RepositoryException
Returns the direct predecessor ofkey
amongstnode
's child nodes wrt. toTreeManager.getOrder()
. Returnsnull
if eithernode
has no child nodes ornode
is a leaf (seeTreeManager.isLeaf(Node)
) orkey
is smaller than all the keys of all child nodes ofnode
.- Throws:
RepositoryException
-
getSuccessor
protected final Node getSuccessor(Node node, String key) throws RepositoryException
Returns the successor node for the givenkey
. That is the node whose key directly succeeds the passedkey
in the order determined byTreeManager.getOrder()
. There are two cases:- A node with the given
key
is mapped: then that node is returned. - A node with the given
key
is not mapped: the the node where that would contain that key if present is returned.
- Throws:
RepositoryException
- A node with the given
-
getMinimal
protected final Node getMinimal() throws RepositoryException
Returns the node with the minimal key wrt.TreeManager.getOrder()
. For the empty sequence this isTreeManager.getRoot()
.- Throws:
RepositoryException
-
getMinimal
protected final Node getMinimal(Node node) throws RepositoryException
Returns the node amongst the child nodes ofnode
whose key is minimal wrt.TreeManager.getOrder()
. Returnsnull
id eithernode
has no child nodes ornode
is a leaf (seeTreeManager.isLeaf(Node)
).- Throws:
RepositoryException
-
renamePath
protected final void renamePath(Node node, String key) throws RepositoryException
Rename the path of the node with the minimal key. That is, assumingnode
is the node with the minimal key (seegetMinimal()
), this method renames every segment of the path ofnode
up toTreeManager.getRoot()
tokey
. Note: Ifnode
is not the node with the minimal key, the behavior of this method is not specified.- Throws:
RepositoryException
-
-