org.apache.jackrabbit.commons.flat
Class TreeTraverser

java.lang.Object
  extended by org.apache.jackrabbit.commons.flat.TreeTraverser
All Implemented Interfaces:
Iterable<Node>

public final class TreeTraverser
extends Object
implements Iterable<Node>

Utility class for traversing the Items of a JCR hierarchy rooted at a specific Node.

This class provides an Iterator of JCR items either through its implementation of Iterable 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 a Node has orderable child nodes.

Whether a specific node is included is determined by an #InclusionPolicy. Error occurring while traversing are delegated to an #ErrorHandler.


Nested Class Summary
static interface TreeTraverser.ErrorHandler
          Error handler for handling RepositoryExceptions occurring on traversal.
static interface TreeTraverser.InclusionPolicy<T extends Item>
          Inclusion policy to determine which items to include when traversing.
 
Constructor Summary
TreeTraverser(Node root)
          Create a new instance of a TreeTraverser rooted at node.
TreeTraverser(Node root, TreeTraverser.ErrorHandler errorHandler, TreeTraverser.InclusionPolicy<? super Node> inclusionPolicy)
          Create a new instance of a TreeTraverser rooted at node.
 
Method Summary
 Iterator<Node> iterator()
          Returns an iterator of Node for this instance.
static Iterator<Node> nodeIterator(Node root)
          Create an iterator for the nodes of the sub-tree rooted at root.
static Iterator<Node> nodeIterator(Node root, TreeTraverser.ErrorHandler errorHandler, TreeTraverser.InclusionPolicy<? super Node> inclusionPolicy)
          Create an iterator for the nodes of the sub-tree rooted at root.
static Iterator<Property> propertyIterator(Iterator<Node> nodes)
          Create an iterator of the properties for a given iterator of nodes.
static Iterator<Property> propertyIterator(Iterator<Node> nodes, TreeTraverser.ErrorHandler errorHandler, TreeTraverser.InclusionPolicy<? super Property> inclusionPolicy)
          Create an iterator of the properties for a given iterator of nodes.
static Iterator<Property> propertyIterator(Node root)
          Create an iterator of the properties of all nodes of the sub-tree rooted at root.
static 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 at root.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeTraverser

public TreeTraverser(Node root,
                     TreeTraverser.ErrorHandler errorHandler,
                     TreeTraverser.InclusionPolicy<? super Node> inclusionPolicy)
Create a new instance of a TreeTraverser rooted at node.

Parameters:
root - The root node of the sub-tree to traverse
errorHandler - Handler for errors while traversing
inclusionPolicy - Inclusion policy to determine which nodes to include

TreeTraverser

public TreeTraverser(Node root)
Create a new instance of a TreeTraverser rooted at node.

Parameters:
root - The root node of the sub-tree to traverse
Method Detail

nodeIterator

public static Iterator<Node> nodeIterator(Node root,
                                          TreeTraverser.ErrorHandler errorHandler,
                                          TreeTraverser.InclusionPolicy<? super Node> inclusionPolicy)
Create an iterator for the nodes of the sub-tree rooted at root.

Parameters:
root - root node of the sub-tree to traverse
errorHandler - handler for exceptions occurring on traversal
inclusionPolicy - inclusion policy to determine which nodes to include
Returns:
iterator of Node

nodeIterator

public static Iterator<Node> nodeIterator(Node root)
Create an iterator for the nodes of the sub-tree rooted at root. Exceptions occurring on traversal are ignored.

Parameters:
root - root node of the sub-tree to traverse
Returns:
iterator of Node

propertyIterator

public static Iterator<Property> propertyIterator(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 node n1 occurs before node n2 in the iterator of nodes, then any property of n1 will occur before any property of n2.

Parameters:
nodes - nodes whose properties to chain
errorHandler - handler for exceptions occurring on traversal
inclusionPolicy - inclusion policy to determine properties items to include
Returns:
iterator of Property

propertyIterator

public static Iterator<Property> propertyIterator(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 node n1 occurs before node n2 in the iterator of nodes, then any property of n1 will occur before any property of n2. Exceptions occurring on traversal are ignored.

Parameters:
nodes - nodes whose properties to chain
Returns:
iterator of Property

propertyIterator

public static 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 at root.

Parameters:
root - root node of the sub-tree to traverse
errorHandler - handler for exceptions occurring on traversal
inclusionPolicy - inclusion policy to determine which items to include
Returns:
iterator of Property

propertyIterator

public static Iterator<Property> propertyIterator(Node root)
Create an iterator of the properties of all nodes of the sub-tree rooted at root. Exceptions occurring on traversal are ignored.

Parameters:
root - root node of the sub-tree to traverse
Returns:
iterator of Property

iterator

public Iterator<Node> iterator()
Returns an iterator of Node for this instance.

Specified by:
iterator in interface Iterable<Node>
See Also:
TreeTraverser(Node, ErrorHandler, InclusionPolicy), Iterable.iterator()


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