Class TreeTraverser
- java.lang.Object
-
- org.apache.jackrabbit.commons.flat.TreeTraverser
-
- All Implemented Interfaces:
java.lang.Iterable<Node>
public final class TreeTraverser extends java.lang.Object implements java.lang.Iterable<Node>
Utility class for traversing the
Item
s of a JCR hierarchy rooted at a specificNode
.This class provides an
Iterator
of JCR items either through its implementation ofIterable
or through various static factory methods. The iterators return its elements in pre-order. That is, each node occurs before its child nodes are traversed. The order in which child nodes are traversed is determined by the underlying JCR implementation. Generally the order is not specified unless aNode
has orderable child nodes.Whether a specific node is included is determined by an
inclusionPolicy
. Error occurring while traversing are delegated to anerrorHandler
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TreeTraverser.ErrorHandler
Error handler for handlingRepositoryException
s occurring on traversal.static interface
TreeTraverser.InclusionPolicy<T extends Item>
Inclusion policy to determine which items to include when traversing.
-
Constructor Summary
Constructors Constructor Description TreeTraverser(Node root)
Create a new instance of a TreeTraverser rooted atnode
.TreeTraverser(Node root, TreeTraverser.ErrorHandler errorHandler, TreeTraverser.InclusionPolicy<? super Node> inclusionPolicy)
Create a new instance of a TreeTraverser rooted atnode
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<Node>
iterator()
Returns an iterator ofNode
for this instance.static java.util.Iterator<Node>
nodeIterator(Node root)
Create an iterator for the nodes of the sub-tree rooted atroot
.static java.util.Iterator<Node>
nodeIterator(Node root, TreeTraverser.ErrorHandler errorHandler, TreeTraverser.InclusionPolicy<? super Node> inclusionPolicy)
Create an iterator for the nodes of the sub-tree rooted atroot
.static java.util.Iterator<Property>
propertyIterator(java.util.Iterator<Node> nodes)
Create an iterator of the properties for a given iterator of nodes.static java.util.Iterator<Property>
propertyIterator(java.util.Iterator<Node> nodes, TreeTraverser.ErrorHandler errorHandler, TreeTraverser.InclusionPolicy<? super Property> inclusionPolicy)
Create an iterator of the properties for a given iterator of nodes.static java.util.Iterator<Property>
propertyIterator(Node root)
Create an iterator of the properties of all nodes of the sub-tree rooted atroot
.static java.util.Iterator<Property>
propertyIterator(Node root, TreeTraverser.ErrorHandler errorHandler, TreeTraverser.InclusionPolicy<Item> inclusionPolicy)
Create an iterator of the properties of all nodes of the sub-tree rooted atroot
.
-
-
-
Constructor Detail
-
TreeTraverser
public TreeTraverser(Node root, TreeTraverser.ErrorHandler errorHandler, TreeTraverser.InclusionPolicy<? super Node> inclusionPolicy)
Create a new instance of a TreeTraverser rooted atnode
.- Parameters:
root
- The root node of the sub-tree to traverseerrorHandler
- Handler for errors while traversinginclusionPolicy
- Inclusion policy to determine which nodes to include
-
TreeTraverser
public TreeTraverser(Node root)
Create a new instance of a TreeTraverser rooted atnode
.- Parameters:
root
- The root node of the sub-tree to traverse
-
-
Method Detail
-
nodeIterator
public static java.util.Iterator<Node> nodeIterator(Node root, TreeTraverser.ErrorHandler errorHandler, TreeTraverser.InclusionPolicy<? super Node> inclusionPolicy)
Create an iterator for the nodes of the sub-tree rooted atroot
.- Parameters:
root
- root node of the sub-tree to traverseerrorHandler
- handler for exceptions occurring on traversalinclusionPolicy
- inclusion policy to determine which nodes to include- Returns:
- iterator of
Node
-
nodeIterator
public static java.util.Iterator<Node> nodeIterator(Node root)
Create an iterator for the nodes of the sub-tree rooted atroot
. Exceptions occurring on traversal are ignored.- Parameters:
root
- root node of the sub-tree to traverse- Returns:
- iterator of
Node
-
propertyIterator
public static java.util.Iterator<Property> propertyIterator(java.util.Iterator<Node> nodes, TreeTraverser.ErrorHandler errorHandler, TreeTraverser.InclusionPolicy<? super Property> inclusionPolicy)
Create an iterator of the properties for a given iterator of nodes. The order of the returned properties is only specified so far that if noden1
occurs before noden2
in the iterator of nodes, then any property ofn1
will occur before any property ofn2
.- Parameters:
nodes
- nodes whose properties to chainerrorHandler
- handler for exceptions occurring on traversalinclusionPolicy
- inclusion policy to determine properties items to include- Returns:
- iterator of
Property
-
propertyIterator
public static java.util.Iterator<Property> propertyIterator(java.util.Iterator<Node> nodes)
Create an iterator of the properties for a given iterator of nodes. The order of the returned properties is only specified so far that if noden1
occurs before noden2
in the iterator of nodes, then any property ofn1
will occur before any property ofn2
. Exceptions occurring on traversal are ignored.- Parameters:
nodes
- nodes whose properties to chain- Returns:
- iterator of
Property
-
propertyIterator
public static java.util.Iterator<Property> propertyIterator(Node root, TreeTraverser.ErrorHandler errorHandler, TreeTraverser.InclusionPolicy<Item> inclusionPolicy)
Create an iterator of the properties of all nodes of the sub-tree rooted atroot
.- Parameters:
root
- root node of the sub-tree to traverseerrorHandler
- handler for exceptions occurring on traversalinclusionPolicy
- inclusion policy to determine which items to include- Returns:
- iterator of
Property
-
propertyIterator
public static java.util.Iterator<Property> propertyIterator(Node root)
Create an iterator of the properties of all nodes of the sub-tree rooted atroot
. Exceptions occurring on traversal are ignored.- Parameters:
root
- root node of the sub-tree to traverse- Returns:
- iterator of
Property
-
iterator
public java.util.Iterator<Node> iterator()
Returns an iterator ofNode
for this instance.- Specified by:
iterator
in interfacejava.lang.Iterable<Node>
- See Also:
TreeTraverser(Node, ErrorHandler, InclusionPolicy)
,Iterable.iterator()
-
-