com.google.gdata.model
Class CompositeElementVisitor

java.lang.Object
  extended by com.google.gdata.model.CompositeElementVisitor
All Implemented Interfaces:
ElementVisitor

public class CompositeElementVisitor
extends java.lang.Object
implements ElementVisitor

This class provides an ElementVisitor implementation that aggregates multiple nested ElementVisitor instances. This makes it possible to apply several different unrelated visitor implementations during a single data model tree traversal.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.google.gdata.model.ElementVisitor
ElementVisitor.StoppedException
 
Constructor Summary
CompositeElementVisitor(ElementVisitor... visitors)
          Constructs a new CompositeElementVisitor instance containing the array of visitor instances passed in.
 
Method Summary
 void addVisitor(ElementVisitor visitor)
          Adds a new ElementVisitor instance to the composite visitor.
 ElementVisitor.StoppedException getStoppedException(ElementVisitor visitor)
          Returns any StoppedException thrown by the specified visitor, or null if the visitor completed normally.
 java.util.List<ElementVisitor> getVisitors()
          Returns the list of active element visitor instances.
 boolean visit(Element parent, Element target, ElementMetadata<?,?> metadata)
          Called during Element tree traversal to allow the visitor instance to process an element in the tree.
 void visitComplete(Element parent, Element target, ElementMetadata<?,?> metadata)
          The visitComplete method is called when traversal for an Element and all of its nested children has been completed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeElementVisitor

public CompositeElementVisitor(ElementVisitor... visitors)
Constructs a new CompositeElementVisitor instance containing the array of visitor instances passed in. The order in which each visitor instance appears in the array is significant; it defines the order in which events for a given element will be delivered to the nested instances.

Parameters:
visitors - list of ElementVisitor instances to compose.
Method Detail

addVisitor

public void addVisitor(ElementVisitor visitor)
Adds a new ElementVisitor instance to the composite visitor. For any element, events will be delivered to the added visitor after events have been delivered to other visitors already contained in the composite visitor at the time of addition.

Parameters:
visitor - the new visitor to add.

getVisitors

public java.util.List<ElementVisitor> getVisitors()
Returns the list of active element visitor instances. Any stopped visitors will not appear in this list.

Returns:
list of visitor instances in order of event delivery.

getStoppedException

public ElementVisitor.StoppedException getStoppedException(ElementVisitor visitor)
Returns any StoppedException thrown by the specified visitor, or null if the visitor completed normally.


visit

public boolean visit(Element parent,
                     Element target,
                     ElementMetadata<?,?> metadata)
              throws ElementVisitor.StoppedException
Description copied from interface: ElementVisitor
Called during Element tree traversal to allow the visitor instance to process an element in the tree.

Specified by:
visit in interface ElementVisitor
Parameters:
parent - the parent of the target element
target - the target element being visited
metadata - the metadata for the target element
Returns:
boolean value indicating whether child elements (if any) should be visited.
Throws:
ElementVisitor.StoppedException - if the data model traversal should be stopped immediately. This may be the result of an unexpected error, or some visitor implementations may extend this exception type to signal specific exit conditions.

visitComplete

public void visitComplete(Element parent,
                          Element target,
                          ElementMetadata<?,?> metadata)
                   throws ElementVisitor.StoppedException
Description copied from interface: ElementVisitor
The visitComplete method is called when traversal for an Element and all of its nested children has been completed.

Specified by:
visitComplete in interface ElementVisitor
Parameters:
parent - the parent of the target element
target - the visited element
metadata - the metadata for the target element
Throws:
ElementVisitor.StoppedException - if the data model traversal should be stopped immediately. This may be the result of an unexpected error, or some visitor implementations may extend this exception type to signal specific exit conditions.