Package org.htmlunit.xpath.axes
Class PredicatedNodeTest
- java.lang.Object
-
- org.htmlunit.xpath.Expression
-
- org.htmlunit.xpath.patterns.NodeTest
-
- org.htmlunit.xpath.axes.PredicatedNodeTest
-
- All Implemented Interfaces:
javax.xml.transform.SourceLocator
,SubContextList
,ExpressionNode
,XPathVisitable
- Direct Known Subclasses:
AxesWalker
,LocPathIterator
public abstract class PredicatedNodeTest extends NodeTest implements SubContextList
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static boolean
DEBUG_PREDICATECOUNTING
If true, diagnostic messages about predicate execution will be posted.protected boolean
m_foundLast
This is true if nextNode returns null.protected LocPathIterator
m_lpi
The owning location path iterator.protected int
m_predCount
(package private) int
m_predicateIndex
Which predicate we are executing.protected int[]
m_proximityPositions
An array of counts that correspond to the number of predicates the step contains.private Expression[]
predicates_
The list of predicate expressions.-
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 PredicatedNodeTest()
Construct an AxesWalker.PredicatedNodeTest(LocPathIterator locPathIterator)
Construct an AxesWalker using a LocPathIterator.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description short
acceptNode(int n)
Test whether a specified node is visible in the logical view of a TreeWalker or NodeIterator.void
callPredicateVisitors(XPathVisitor visitor)
This will traverse the heararchy, calling the visitor for each member.boolean
canTraverseOutsideSubtree()
Tell if this expression or it's subexpressions can traverse outside the current subtree.java.lang.Object
clone()
protected void
countProximityPosition(int i)
Count forward one proximity position.boolean
deepEquals(Expression expr)
Compare this object with another object and see if they are equal, include the sub heararchy.(package private) boolean
executePredicates(int context, XPathContext xctxt)
Process the predicates.abstract 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.Expression
getPredicate(int index)
Get a predicate expression at the given index.int
getPredicateCount()
Get the number of predicates that this walker has.int
getProximityPosition()
Get the current sub-context position.protected int
getProximityPosition(int predicateIndex)
Get the current sub-context position.int
getProximityPosition(XPathContext xctxt)
Get the current sub-context position.protected void
initPredicateInfo(Compiler compiler, int opPos)
Init predicate info.void
initProximityPosition(int i)
Init the proximity position to zero for a forward axes.boolean
isReverseAxes()
Tells if this is a reverse axes.protected java.lang.String
nodeToString(int n)
Diagnostics.void
resetProximityPositions()
Reset the proximity positions counts.void
setLocPathIterator(LocPathIterator li)
Set the location path iterator owner for this walker.void
setPredicateCount(int count)
Set the number of predicates that this walker has.-
Methods inherited from class org.htmlunit.xpath.patterns.NodeTest
calcScore, callVisitors, 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_predCount
protected int m_predCount
-
m_foundLast
protected transient boolean m_foundLast
This is true if nextNode returns null.
-
m_lpi
protected LocPathIterator m_lpi
The owning location path iterator.
-
m_predicateIndex
transient int m_predicateIndex
Which predicate we are executing.
-
predicates_
private Expression[] predicates_
The list of predicate expressions. Is static and does not need to be deep cloned.
-
m_proximityPositions
protected transient int[] m_proximityPositions
An array of counts that correspond to the number of predicates the step contains.
-
DEBUG_PREDICATECOUNTING
static final boolean DEBUG_PREDICATECOUNTING
If true, diagnostic messages about predicate execution will be posted.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PredicatedNodeTest
PredicatedNodeTest(LocPathIterator locPathIterator)
Construct an AxesWalker using a LocPathIterator.- Parameters:
locPathIterator
- non-null reference to the parent iterator.
-
PredicatedNodeTest
PredicatedNodeTest()
Construct an AxesWalker. The location path iterator will have to be set before use.
-
-
Method Detail
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
getPredicateCount
public int getPredicateCount()
Get the number of predicates that this walker has.- Returns:
- the number of predicates that this walker has.
-
setPredicateCount
public void setPredicateCount(int count)
Set the number of predicates that this walker has. This does more that one would think, as it creates a new predicate array of the size of the count argument, and copies count predicates into the new one from the old, and then reassigns the predicates value. All this to keep from having to have a predicate count value.- Parameters:
count
- The number of predicates, which must be equal or less than the existing count.
-
initPredicateInfo
protected void initPredicateInfo(Compiler compiler, int opPos) throws javax.xml.transform.TransformerException
Init predicate info.- Parameters:
compiler
- The Compiler object that has information about this walker in the op map.opPos
- The op code position of this location step.- Throws:
javax.xml.transform.TransformerException
- if any
-
getPredicate
public Expression getPredicate(int index)
Get a predicate expression at the given index.- Parameters:
index
- Index of the predicate.- Returns:
- A predicate expression.
-
getProximityPosition
public int getProximityPosition()
Get the current sub-context position.- Returns:
- The node position of this walker in the sub-context node list.
-
getProximityPosition
public int getProximityPosition(XPathContext xctxt)
Get the current sub-context position.- Specified by:
getProximityPosition
in interfaceSubContextList
- Parameters:
xctxt
- The XPath runtime context.- Returns:
- The position of the current node in the list.
-
getLastPos
public abstract 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:
getLastPos
in interfaceSubContextList
- Parameters:
xctxt
- The XPath runtime context.- Returns:
- the number of nodes in the node list.
-
getProximityPosition
protected int getProximityPosition(int predicateIndex)
Get the current sub-context position.- Parameters:
predicateIndex
- The index of the predicate where the proximity should be taken from.- Returns:
- The node position of this walker in the sub-context node list.
-
resetProximityPositions
public void resetProximityPositions()
Reset the proximity positions counts.
-
initProximityPosition
public void initProximityPosition(int i)
Init the proximity position to zero for a forward axes.- Parameters:
i
- The index into the m_proximityPositions array.
-
countProximityPosition
protected void countProximityPosition(int i)
Count forward one proximity position.- Parameters:
i
- The index into the m_proximityPositions array, where the increment will occur.
-
isReverseAxes
public boolean isReverseAxes()
Tells if this is a reverse axes.- Returns:
- false, unless a derived class overrides.
-
executePredicates
boolean executePredicates(int context, XPathContext xctxt) throws javax.xml.transform.TransformerException
Process the predicates.- Parameters:
context
- The current context node.xctxt
- The XPath runtime context.- Returns:
- the result of executing the predicate expressions.
- Throws:
javax.xml.transform.TransformerException
- if any
-
nodeToString
protected java.lang.String nodeToString(int n)
Diagnostics.- Parameters:
n
- Node to give diagnostic information about, or null.- Returns:
- Informative string about the argument.
-
acceptNode
public short acceptNode(int n)
Test whether a specified node is visible in the logical view of a TreeWalker or NodeIterator. This function will be called by the implementation of TreeWalker and NodeIterator; it is not intended to be called directly from user code.- Parameters:
n
- The node to check to see if it passes the filter or not.- Returns:
- a constant to determine whether the node is accepted, rejected, or skipped, as defined above .
-
setLocPathIterator
public void setLocPathIterator(LocPathIterator li)
Set the location path iterator owner for this walker. Besides initialization, this function is called during cloning operations.- Parameters:
li
- non-null reference to the owning location path iterator.
-
canTraverseOutsideSubtree
public boolean canTraverseOutsideSubtree()
Tell if this expression or it's subexpressions can traverse outside the current subtree.- Overrides:
canTraverseOutsideSubtree
in classExpression
- Returns:
- true if traversal outside the context node's subtree can occur.
-
callPredicateVisitors
public void callPredicateVisitors(XPathVisitor visitor)
This will traverse the heararchy, calling the visitor for each member. If the called visitor method returns false, the subtree should not be called.- 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:
deepEquals
in classNodeTest
- 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.
-
-