com.bowstreet.util
Class XmlTreeWalker

java.lang.Object
  extended by com.bowstreet.util.XmlTreeWalker
All Implemented Interfaces:
java.util.Iterator

public class XmlTreeWalker
extends java.lang.Object
implements java.util.Iterator

Walker for IXml elements in tree. This is useful for walking through an entire tree of XML elements. Does "preorder" depth-first walking.


Constructor Summary
XmlTreeWalker(IXml initial)
          Constructs a tree walker starting at the specified XML element.
 
Method Summary
 IXml getCurrent()
          Returns the current element.
 IXml getNext()
          Advances to the next element, and makes that current.
 IXml getNext(java.lang.String name)
          Convenience method to walk only through elements with the specified tag name.
 boolean hasNext()
          Returns true if the iteration has more elements.
 java.lang.Object next()
          Returns the next element in the interation.
 void remove()
          Removes the current node from the tree and backs up the current so that the next call to getNext() will continue without skipping any nodes
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlTreeWalker

public XmlTreeWalker(IXml initial)
Constructs a tree walker starting at the specified XML element.

Method Detail

getCurrent

public IXml getCurrent()
Returns the current element.


getNext

public IXml getNext()
Advances to the next element, and makes that current. Returns null if there are no more elements through which to walk, because the initial element was reached or because a null parent was reached.

Returns:
the next element (which becomes current), else null.

getNext

public IXml getNext(java.lang.String name)
Convenience method to walk only through elements with the specified tag name. This just calls getNext() and filters out the nodes which aren't desired. It returns null when the iteration completes.

Parameters:
name - The tag to match.
Returns:
the next matching element, else null.

hasNext

public boolean hasNext()
Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Specified by:
hasNext in interface java.util.Iterator
Returns:
true if the iterator has more elements.

next

public java.lang.Object next()
Returns the next element in the interation.

Specified by:
next in interface java.util.Iterator
Returns:
the next element in the iteration.
Throws:
java.util.NoSuchElementException - iteration has no more elements.

remove

public void remove()
Removes the current node from the tree and backs up the current so that the next call to getNext() will continue without skipping any nodes

Specified by:
remove in interface java.util.Iterator


Copyright © 2009 IBM. All Rights Reserved.