Top Description Fields Constructors Methods
com.thoughtworks.xstream.io.path

public Class PathTracker

extends Object
Class Inheritance
Imports
java.util.HashMap, .Map

Maintains the current Path as a stream is moved through.

Can be linked to a com.thoughtworks.xstream.io.HierarchicalStreamWriter or com.thoughtworks.xstream.io.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

Field Summary

Modifier and TypeField and Description
private int
private Path
private Map<K, V>[]
private String[]
private int

Constructor Summary

AccessConstructor and Description
public
public
PathTracker(int
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.
initialCapacity
)

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the stack depth
depth
()

Get the depth of the stack.

public Path
getPath()

Current Path in stream.

public String

Returns:

the name of the path element
peekElement
()

Get the last path element from the stack.

public String

Returns:

the name of the path element
peekElement
(int
path index
i
)

Get a path element from the stack.

public void
popElement()

Notify the tracker that the stream has moved out of an element.

public void
pushElement(String
Name of the element
name
)

Notify the tracker that the stream has moved into a new element.

private void
resizeStacks(int newCapacity)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

capacityback to summary
private int capacity
currentPathback to summary
private Path currentPath
indexMapStackback to summary
private Map<K, V>[] indexMapStack
pathStackback to summary
private String[] pathStack
pointerback to summary
private int pointer

Constructor Detail

PathTrackerback to summary
public PathTracker()
PathTrackerback to summary
public PathTracker(int initialCapacity)
Parameters
initialCapacity:int

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

depthback to summary
public int depth()

Get the depth of the stack.

Returns:int

the stack depth

Since
1.4.2
getPathback to summary
public Path getPath()

Current Path in stream.

peekElementback to summary
public String peekElement()

Get the last path element from the stack.

Returns:String

the name of the path element

Since
1.4.2
peekElementback to summary
public String peekElement(int i)

Get a path element from the stack.

Parameters
i:int

path index

Returns:String

the name of the path element

Exceptions
ArrayIndexOutOfBoundsException:
if the index is >= 0 or <= -depth()
Since
1.4.2
popElementback to summary
public void popElement()

Notify the tracker that the stream has moved out of an element.

pushElementback to summary
public void pushElement(String name)

Notify the tracker that the stream has moved into a new element.

Parameters
name:String

Name of the element

resizeStacksback to summary
private void resizeStacks(int newCapacity)