Package org.htmlunit.xpath.axes
Class AxesWalker
- java.lang.Object
-
- org.htmlunit.xpath.Expression
-
- org.htmlunit.xpath.patterns.NodeTest
-
- org.htmlunit.xpath.axes.PredicatedNodeTest
-
- org.htmlunit.xpath.axes.AxesWalker
-
- All Implemented Interfaces:
java.lang.Cloneable,javax.xml.transform.SourceLocator,PathComponent,SubContextList,ExpressionNode,XPathVisitable
- Direct Known Subclasses:
FilterExprWalker,ReverseAxesWalker
public class AxesWalker extends PredicatedNodeTest implements java.lang.Cloneable, PathComponent
Serves as common interface for axes Walkers, and stores common state variables.
-
-
Field Summary
Fields Modifier and Type Field Description protected intm_axisThe traversal axis from where the nodes will be filtered.private intm_currentNodeThe node at which the TreeWalker is currently positioned.private DTMm_dtmThe DTM for the root.(package private) booleanm_isFreshTrue if an itteration has not begun.protected AxesWalkerm_nextWalkerThe next walker in the location step chain.(package private) AxesWalkerm_prevWalkerThe previous walker in the location step chain, or null.(package private) intm_rootThe root node of the TreeWalker, as specified when it was created.protected DTMAxisTraverserm_traverserThe DTM inner traversal class, that corresponds to the super axis.-
Fields inherited from class org.htmlunit.xpath.axes.PredicatedNodeTest
DEBUG_PREDICATECOUNTING, m_foundLast, m_lpi, m_predCount, m_predicateIndex, m_proximityPositions
-
Fields inherited from class org.htmlunit.xpath.patterns.NodeTest
m_name, m_whatToShow, SCORE_NODETEST, SCORE_NONE, SCORE_NSWILD, SCORE_OTHER, SCORE_QNAME, SHOW_BYFUNCTION, WILD
-
-
Constructor Summary
Constructors Constructor Description AxesWalker(LocPathIterator locPathIterator, int axis)Construct an AxesWalker using a LocPathIterator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcallVisitors(XPathVisitor visitor)This will traverse the hierarchy, calling the visitor for each member.java.lang.Objectclone()(package private) AxesWalkercloneDeep(WalkingIterator cloneOwner, java.util.Vector<AxesWalker> cloneList)Do a deep clone of this walker, including next and previous walkers.booleandeepEquals(Expression expr)Compare this object with another object and see if they are equal, include the sub heararchy.voiddetach()Detaches the walker from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.(package private) static AxesWalkerfindClone(AxesWalker key, java.util.Vector<AxesWalker> cloneList)Find a clone that corresponds to the key argument.intgetAnalysisBits()Get the analysis bits for this path component, as defined in the WalkerFactory.intgetAxis()Returns the axis being iterated, if it is known.DTMgetDTM(int node)Get the DTM for this walker.intgetLastPos(XPathContext xctxt)Get the number of nodes in the node list, which, in the XSLT 1 based counting system, is the last index position.protected intgetNextNode()Get the next node in document order on the axes.AxesWalkergetNextWalker()Get the next walker in the location step chain.intgetRoot()The root node of the TreeWalker, as specified in setRoot(int root).voidinit(Compiler compiler, int opPos, int stepType)Initialize an AxesWalker during the parse of the XPath expression.intnextNode()Moves theTreeWalkerto the next visible node in document order relative to the current node, and returns the new node.voidsetNextWalker(AxesWalker walker)Set the next walker in the location step chain.voidsetPrevWalker(AxesWalker walker)Set or clear the previous walker reference in the location step chain.voidsetRoot(int root)Set the root node of the TreeWalker.WalkingIteratorwi()-
Methods inherited from class org.htmlunit.xpath.axes.PredicatedNodeTest
acceptNode, callPredicateVisitors, canTraverseOutsideSubtree, countProximityPosition, executePredicates, getPredicate, getPredicateCount, getProximityPosition, getProximityPosition, getProximityPosition, initPredicateInfo, initProximityPosition, isReverseAxes, nodeToString, resetProximityPositions, setLocPathIterator, setPredicateCount
-
Methods inherited from class org.htmlunit.xpath.patterns.NodeTest
calcScore, execute, execute, execute, getLocalName, getNamespace, getNodeTypeTest, getStaticScore, getWhatToShow, initNodeTest, initNodeTest, setLocalName, setNamespace, setStaticScore, setWhatToShow
-
Methods inherited from class org.htmlunit.xpath.Expression
asIterator, asNode, assertion, bool, error, execute, exprGetParent, exprSetParent, getColumnNumber, getExpressionOwner, getLineNumber, getPublicId, getSystemId, isSameClass, isStableNumber, num
-
-
-
-
Field Detail
-
m_dtm
private DTM m_dtm
The DTM for the root. This can not be used, or must be changed, for the filter walker, or any walker that can have nodes from multiple documents. Never, ever, access this value without going through getDTM(int node).
-
m_root
transient int m_root
The root node of the TreeWalker, as specified when it was created.
-
m_currentNode
private transient int m_currentNode
The node at which the TreeWalker is currently positioned.
-
m_isFresh
transient boolean m_isFresh
True if an itteration has not begun.
-
m_nextWalker
protected AxesWalker m_nextWalker
The next walker in the location step chain.
-
m_prevWalker
AxesWalker m_prevWalker
The previous walker in the location step chain, or null.
-
m_axis
protected final int m_axis
The traversal axis from where the nodes will be filtered.
-
m_traverser
protected DTMAxisTraverser m_traverser
The DTM inner traversal class, that corresponds to the super axis.
-
-
Constructor Detail
-
AxesWalker
public AxesWalker(LocPathIterator locPathIterator, int axis)
Construct an AxesWalker using a LocPathIterator.- Parameters:
locPathIterator- non-null reference to the parent iterator.
-
-
Method Detail
-
wi
public final WalkingIterator wi()
-
init
public void init(Compiler compiler, int opPos, int stepType) throws javax.xml.transform.TransformerException
Initialize an AxesWalker during the parse of the XPath expression.- Parameters:
compiler- The Compiler object that has information about this walker in the op map.opPos- The op code position of this location step.stepType- The type of location step.- Throws:
javax.xml.transform.TransformerException- if any
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException- Overrides:
clonein classPredicatedNodeTest- Throws:
java.lang.CloneNotSupportedException
-
cloneDeep
AxesWalker cloneDeep(WalkingIterator cloneOwner, java.util.Vector<AxesWalker> cloneList) throws java.lang.CloneNotSupportedException
Do a deep clone of this walker, including next and previous walkers. If the this AxesWalker is on the clone list, don't clone but return the already cloned version.- Parameters:
cloneOwner- non-null reference to the cloned location path iterator to which this clone will be added.cloneList- non-null vector of sources in odd elements, and the corresponding clones in even vectors.- Returns:
- non-null clone, which may be a new clone, or may be a clone contained on the cloneList.
- Throws:
java.lang.CloneNotSupportedException
-
findClone
static AxesWalker findClone(AxesWalker key, java.util.Vector<AxesWalker> cloneList)
Find a clone that corresponds to the key argument.- Parameters:
key- The original AxesWalker for which there may be a clone.cloneList- vector of sources in odd elements, and the corresponding clones in even vectors, may be null.- Returns:
- A clone that corresponds to the key, or null if key not found.
-
detach
public void detach()
Detaches the walker from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.
-
getRoot
public int getRoot()
The root node of the TreeWalker, as specified in setRoot(int root). Note that this may actually be below the current node.- Returns:
- The context node of the step.
-
getAnalysisBits
public int getAnalysisBits()
Get the analysis bits for this path component, as defined in the WalkerFactory.- Specified by:
getAnalysisBitsin interfacePathComponent- Returns:
- One of WalkerFactory#BIT_DESCENDANT, etc.
-
setRoot
public void setRoot(int root)
Set the root node of the TreeWalker. (Not part of the DOM2 TreeWalker interface).- Parameters:
root- The context node of this step.
-
setNextWalker
public void setNextWalker(AxesWalker walker)
Set the next walker in the location step chain.- Parameters:
walker- Reference to AxesWalker derivative, or may be null.
-
getNextWalker
public AxesWalker getNextWalker()
Get the next walker in the location step chain.- Returns:
- Reference to AxesWalker derivative, or null.
-
setPrevWalker
public void setPrevWalker(AxesWalker walker)
Set or clear the previous walker reference in the location step chain.- Parameters:
walker- Reference to previous walker reference in the location step chain, or null.
-
getNextNode
protected int getNextNode()
Get the next node in document order on the axes.- Returns:
- the next node in document order on the axes, or null.
-
nextNode
public int nextNode()
Moves theTreeWalkerto the next visible node in document order relative to the current node, and returns the new node. If the current node has no next node, or if the search for nextNode attempts to step upward from the TreeWalker's root node, returnsnull, and retains the current node.- Returns:
- The new node, or
nullif the current node has no next node in the TreeWalker's logical view.
-
getLastPos
public int getLastPos(XPathContext xctxt)
Get the number of nodes in the node list, which, in the XSLT 1 based counting system, is the last index position.- Specified by:
getLastPosin interfaceSubContextList- Specified by:
getLastPosin classPredicatedNodeTest- Parameters:
xctxt- The XPath runtime context.- Returns:
- the number of nodes in the node list.
-
getDTM
public DTM getDTM(int node)
Get the DTM for this walker.- Returns:
- Non-null reference to a DTM.
-
getAxis
public int getAxis()
Returns the axis being iterated, if it is known.- Returns:
- Axis.CHILD, etc., or -1 if the axis is not known or is of multiple types.
-
callVisitors
public void callVisitors(XPathVisitor visitor)
This will traverse the hierarchy, calling the visitor for each member. If the called visitor method returns false, the subtree should not be called.- Specified by:
callVisitorsin interfaceXPathVisitable- Overrides:
callVisitorsin classNodeTest- Parameters:
visitor- The visitor whose appropriate method will be called.
-
deepEquals
public boolean deepEquals(Expression expr)
Compare this object with another object and see if they are equal, include the sub heararchy.- Overrides:
deepEqualsin classPredicatedNodeTest- Parameters:
expr- Another expression object.- Returns:
- true if this objects class and the expr object's class are the same, and the data contained within both objects are considered equal.
-
-