com.thoughtworks.xstream.io.path
Class PathTracker

java.lang.Object
  extended bycom.thoughtworks.xstream.io.path.PathTracker

public class PathTracker
extends java.lang.Object

Maintains the current Path as a stream is moved through.

Can be linked to a HierarchicalStreamWriter or HierarchicalStreamReader by wrapping them with a PathTrackingWriter or PathTrackingReader.

Example

 PathTracker tracker = new PathTracker();
 tracker.pushElement("table");
 tracker.pushElement("tr");
 tracker.pushElement("td");
 tracker.pushElement("form");
 tracker.popElement("form");
 tracker.popElement("td");
 tracker.pushElement("td");
 tracker.pushElement("div");

 Path path = tracker.getPath(); // returns "/table/tr/td[2]/div"
 

Author:
Joe Walnes
See Also:
Path, PathTrackingReader, PathTrackingWriter

Constructor Summary
PathTracker()
           
PathTracker(int initialCapacity)
           
 
Method Summary
 java.lang.String getCurrentPath()
          Deprecated. Use getPath() instead.
 Path getPath()
          Current Path in stream.
 void popElement()
          Notify the tracker that the stream has moved out of an element.
 void pushElement(java.lang.String name)
          Notify the tracker that the stream has moved into a new element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PathTracker

public PathTracker()

PathTracker

public PathTracker(int initialCapacity)
Parameters:
initialCapacity - Size of the initial stack of nodes (one level per depth in the tree). Note that this is only for optimizations - the stack will resize itself if it exceeds its capacity. If in doubt, use the other constructor.
Method Detail

pushElement

public void pushElement(java.lang.String name)
Notify the tracker that the stream has moved into a new element.

Parameters:
name - Name of the element

popElement

public void popElement()
Notify the tracker that the stream has moved out of an element.


getCurrentPath

public java.lang.String getCurrentPath()
Deprecated. Use getPath() instead.


getPath

public Path getPath()
Current Path in stream.



Joe Walnes, http://xstream.codehaus.org/