Class TraversingItemVisitor
- java.lang.Object
-
- javax.jcr.util.TraversingItemVisitor
-
- All Implemented Interfaces:
ItemVisitor
- Direct Known Subclasses:
TraversingItemVisitor.Default
public abstract class TraversingItemVisitor extends java.lang.Object implements ItemVisitor
An implementation ofItemVisitor
.TraversingItemVisitor
is an abstract utility class which allows to easily traverse anItem
hierarchy.TraversingItemVisitor
makes use of the Visitor Pattern as described in the book 'Design Patterns' by the Gang Of Four (Gamma et al.).Tree traversal is done observing the left-to-right order of child
Item
s if such an order is supported and exists.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TraversingItemVisitor.Default
Convenience class providing default implementations of the abstract methods ofTraversingItemVisitor
.
-
Constructor Summary
Constructors Constructor Description TraversingItemVisitor()
Constructs a new instance of this class.TraversingItemVisitor(boolean breadthFirst)
Constructs a new instance of this class.TraversingItemVisitor(boolean breadthFirst, int maxLevel)
Constructs a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
visit(Node node)
Called when theVisitor
is passed to aNode
.void
visit(Property property)
Called when theVisitor
is passed to aProperty
.
-
-
-
Constructor Detail
-
TraversingItemVisitor
public TraversingItemVisitor()
Constructs a new instance of this class.The tree of
Item
s will be traversed in a depth-first manner (default behavior).
-
TraversingItemVisitor
public TraversingItemVisitor(boolean breadthFirst)
Constructs a new instance of this class.- Parameters:
breadthFirst
- ifbreadthFirst
is true then traversal is done in a breadth-first manner; otherwise it is done in a depth-first manner (which is the default behavior).
-
TraversingItemVisitor
public TraversingItemVisitor(boolean breadthFirst, int maxLevel)
Constructs a new instance of this class.- Parameters:
breadthFirst
- ifbreadthFirst
is true then traversal is done in a breadth-first manner; otherwise it is done in a depth-first manner (which is the default behavior).maxLevel
- the 0-based level up to which the hierarchy should be traversed (if it's -1, the hierarchy will be traversed until there are no more children of the current item).
-
-
Method Detail
-
visit
public void visit(Property property) throws RepositoryException
Called when theVisitor
is passed to aProperty
.It calls
TraversingItemVisitor.entering(Property, int)
followed byTraversingItemVisitor.leaving(Property, int)
. Implement these abstract methods to specify behavior on 'arrival at' and 'after leaving' theProperty
.If this method throws, the visiting process is aborted.
- Specified by:
visit
in interfaceItemVisitor
- Parameters:
property
- theProperty
that is accepting this visitor.- Throws:
RepositoryException
- if an error occurs.
-
visit
public void visit(Node node) throws RepositoryException
Called when theVisitor
is passed to aNode
.It calls
TraversingItemVisitor.entering(Node, int)
followed byTraversingItemVisitor.leaving(Node, int)
. Implement these abstract methods to specify behavior on 'arrival at' and 'after leaving' theNode
.If this method throws, the visiting process is aborted.
- Specified by:
visit
in interfaceItemVisitor
- Parameters:
node
- theNode
that is accepting this visitor.- Throws:
RepositoryException
- if an error occurs.
-
-