org.enhydra.xml.dom
Class DOMTraversal

java.lang.Object
  |
  +--org.enhydra.xml.dom.DOMTraversal
Direct Known Subclasses:
LazyDOMTraversal

public class DOMTraversal
extends Object

Class that traverse a DOM tree or subtree, calling handler methods for each node. It is up to the handler methods to make a decision on processing child and element nodes by explictly calling the methods to continue the traversal. This is gives the handler more control and actually kept the code simpler for both this class and the client.

While DOM traversal is straight-forward, traversing the LazyDOM while avoiding expansion made things tricker. This class, and the derived class for the LazyDOM, handles these special cases.


Inner Class Summary
static interface DOMTraversal.Handler
          Interface for node callback object.
 class DOMTraversal.NodeHandler
          Implementation of handler that calls a single method for all node types.
 
Field Summary
static int ALL_ATTRIBUTES
          Option flag to indicate that unspecified attributes should be included.
protected  int fDepth
          Current traversal tree depth
protected  DOMTraversal.Handler fHandler
          Handler object for the traversal
protected  int fOptions
          Options controlling the traversal.
protected  boolean fProcessingAttribute
          Are we processing an attribute or its children?
static int SORT_ATTRIBUTES
          Option flag to indicate that attributes should be sorted before calling the handlers.
 
Constructor Summary
DOMTraversal(DOMTraversal.Handler handler, int options)
          Constructor.
DOMTraversal(int options)
          Default constructor, set handler later.
 
Method Summary
 int getDepth()
          Get the current depth in the DOM tree that is being traversed.
static DOMTraversal getTraverser(DOMTraversal.Handler handler, int options, Node node)
          Factory method to create a traverser based on the type of a document.
 void processAttributes(Element element)
          Process the attributes of an element.
 void processChildren(Node node)
          Process the children of a node.
 void processDocumentType(Document document)
          Process a DocumentType attribute of a Document node, if it exists.
 void processDocumentTypeContents(DocumentType documentType)
          Process the contents of a DocumentType node,
 boolean processingAttribute()
          Are we currently processing an attribute node or its descendents?
protected  void processNode(Node node)
          Processing based on node type.
 void setHandler(DOMTraversal.Handler handler)
          Set the handler.
 void traverse(Node root)
          Traverse a DOM tree or subtree.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SORT_ATTRIBUTES

public static final int SORT_ATTRIBUTES
Option flag to indicate that attributes should be sorted before calling the handlers.

ALL_ATTRIBUTES

public static final int ALL_ATTRIBUTES
Option flag to indicate that unspecified attributes should be included.

fHandler

protected DOMTraversal.Handler fHandler
Handler object for the traversal

fOptions

protected int fOptions
Options controlling the traversal.

fDepth

protected int fDepth
Current traversal tree depth

fProcessingAttribute

protected boolean fProcessingAttribute
Are we processing an attribute or its children?
Constructor Detail

DOMTraversal

public DOMTraversal(DOMTraversal.Handler handler,
                    int options)
Constructor.
Parameters:
handler - The object that will be called to handle each node.
options - Bit set of the option flags.

DOMTraversal

public DOMTraversal(int options)
Default constructor, set handler later.
Method Detail

setHandler

public void setHandler(DOMTraversal.Handler handler)
Set the handler.

traverse

public void traverse(Node root)
Traverse a DOM tree or subtree.
Parameters:
root - The root of the DOM tree or subtree that is to be traversed.
Throws:
DOMError - Any internal exceptions are encapsulated in this error.

getDepth

public final int getDepth()
Get the current depth in the DOM tree that is being traversed.

processingAttribute

public final boolean processingAttribute()
Are we currently processing an attribute node or its descendents?

processChildren

public void processChildren(Node node)
Process the children of a node.

processAttributes

public void processAttributes(Element element)
Process the attributes of an element.

processDocumentType

public void processDocumentType(Document document)
Process a DocumentType attribute of a Document node, if it exists.

processDocumentTypeContents

public void processDocumentTypeContents(DocumentType documentType)
Process the contents of a DocumentType node,

processNode

protected void processNode(Node node)
Processing based on node type. All nodes go through here.

getTraverser

public static DOMTraversal getTraverser(DOMTraversal.Handler handler,
                                        int options,
                                        Node node)
Factory method to create a traverser based on the type of a document.


Copyright © 1999-2002 enhydra.org (Mark Diekhans, David Li, Richard Kunze). All Rights reserved.