public class PathTracker
extends java.lang.Object
Path
as a stream is moved through.
Can be linked to a HierarchicalStreamWriter
or
HierarchicalStreamReader
by wrapping them with a
PathTrackingWriter
or PathTrackingReader
.
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"
Path
,
PathTrackingReader
,
PathTrackingWriter
Constructor and Description |
---|
PathTracker() |
PathTracker(int initialCapacity) |
Modifier and Type | Method and Description |
---|---|
int |
depth()
Get the depth of the stack.
|
Path |
getPath()
Current Path in stream.
|
java.lang.String |
peekElement()
Get the last path element from the stack.
|
java.lang.String |
peekElement(int i)
Get a path element from the stack.
|
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.
|
public PathTracker()
public PathTracker(int initialCapacity)
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.public void pushElement(java.lang.String name)
name
- Name of the elementpublic void popElement()
public java.lang.String peekElement()
public java.lang.String peekElement(int i)
i
- path indexjava.lang.ArrayIndexOutOfBoundsException
- if the index is >= 0 or <= -depth()public int depth()
public Path getPath()
Copyright © 2004–2024 XStream. All rights reserved.