Class LocPathIterator
- java.lang.Object
-
- org.htmlunit.xpath.Expression
-
- org.htmlunit.xpath.patterns.NodeTest
-
- org.htmlunit.xpath.axes.PredicatedNodeTest
-
- org.htmlunit.xpath.axes.LocPathIterator
-
- All Implemented Interfaces:
java.lang.Cloneable,javax.xml.transform.SourceLocator,PathComponent,SubContextList,ExpressionNode,DTMIterator,XPathVisitable
- Direct Known Subclasses:
BasicTestIterator,ChildIterator,DescendantIterator,SelfIteratorNoPredicate,UnionPathIterator,WalkingIterator
public abstract class LocPathIterator extends PredicatedNodeTest implements java.lang.Cloneable, DTMIterator, PathComponent
This class extends NodeSetDTM, which implements NodeIterator, and fetches nodes one at a time in document order based on a XPath.
-
-
Field Summary
Fields Modifier and Type Field Description protected DTMm_cdtmThe dtm of the context node.protected IteratorPoolm_clonesThe pool for cloned iterators.protected intm_contextThe context node for this iterator, which doesn't change through the course of the iteration.protected intm_currentContextNodeThe node context from where the expression is being executed from (i.e.protected XPathContextm_execContextThe XPathContext reference, needed for execution of many operations.private booleanm_isTopLevelValue determined at compile time, indicates that this is an iterator at the top level of the expression, rather than inside a predicate.intm_lastFetchedThe last node that was fetched, usually by nextNode.protected intm_lengthprotected intm_posThe current position of the context node.private PrefixResolverm_prefixResolverFast access to the current prefix resolver.(package private) intm_stackFrameThe stack frame index for this iterator.-
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
-
Fields inherited from interface org.htmlunit.xpath.xml.dtm.DTMIterator
FILTER_ACCEPT, FILTER_SKIP
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedLocPathIterator()Create a LocPathIterator object.protectedLocPathIterator(int analysis)Create a LocPathIterator object, including creation of step walkers from the opcode list, and call back into the Compiler to create predicate expressions.protectedLocPathIterator(int analysis, boolean shouldLoadWalkers)Create a LocPathIterator object, including creation of step walkers from the opcode list, and call back into the Compiler to create predicate expressions.protectedLocPathIterator(PrefixResolver nscontext)Create a LocPathIterator object.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description DTMIteratorasIterator(XPathContext xctxt, int contextNode)Given an select expression and a context, evaluate the XPath and return the resulting iterator.intasNode(XPathContext xctxt)Return the first node out of the nodeset, if this expression is a nodeset expression.booleanbool(XPathContext xctxt)Evaluate expression to a boolean.voidcallVisitors(XPathVisitor visitor)This will traverse the hierarchy, calling the visitor for each member.DTMIteratorcloneWithReset()Get a cloned Iterator that is reset to the start of the iteration.voiddetach()Detaches theDTMIteratorfrom the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.XObjectexecute(XPathContext xctxt)Execute an expression in the XPath runtime context, and return the result of the expression.intgetAnalysisBits()Get the analysis bits for this path component, as defined in the WalkerFactory.intgetAxis()Returns the axis being iterated, if it is known.intgetCurrentNode()Get the current node in the iterator.intgetCurrentPos()Get the current position within the cached list, which is one less than the next nextNode() call will retrieve.DTMgetDTM(int nodeHandle)Get an instance of a DTM that "owns" a node handle.DTMManagergetDTMManager()Get an instance of the DTMManager.booleangetExpandEntityReferences()The value of this flag determines whether the children of entity reference nodes are visible to the iterator.booleangetIsTopLevel()Get if this is an iterator at the upper level of the XPath.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.intgetLength()The number of nodes in the list.PrefixResolvergetPrefixResolver()Return the saved reference to the prefix resolver that was in effect when this iterator was created.intgetRoot()The root node of theDTMIterator, as specified when it was created.intgetWhatToShow()This attribute determines which node types are accepted.XPathContextgetXPathContext()The XPath execution context we are operating on.voidincrementCurrentPos()Increment the current position in the node set.booleanisDocOrdered()Returns true if all the nodes in the iteration well be returned in document order.booleanisFresh()Tells if this NodeSetDTM is "fresh", in other words, if the first nextNode() that is called will return the first node in the set.intitem(int index)Returns thenode handleof an item in the collection.abstract intnextNode()Returns the next node in the set and advances the position of the iterator in the set.intpreviousNode()Returns the previous node in the set and moves the position of theDTMIteratorbackwards in the set.voidreset()Reset the iterator to the start.protected intreturnNextNode(int nextNode)Bottleneck the return of a next node, to make returns easier from nextNode().voidrunTo(int index)If an index is requested, NodeSetDTM will call this method to run the iterator to the index.voidsetCurrentPos(int i)Set the current position in the node set.voidsetIsTopLevel(boolean b)Set if this is an iterator at the upper level of the XPath.voidsetRoot(int context, java.lang.Object environment)Reset the root node of theDTMIterator, overriding the value specified when it was created.voidsetShouldCacheNodes(boolean b)If setShouldCacheNodes(true) is called, then nodes will be cached, enabling random access, and giving the ability to do sorts and the like.-
Methods inherited from class org.htmlunit.xpath.axes.PredicatedNodeTest
acceptNode, callPredicateVisitors, canTraverseOutsideSubtree, clone, countProximityPosition, deepEquals, 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, getLocalName, getNamespace, getNodeTypeTest, getStaticScore, initNodeTest, initNodeTest, setLocalName, setNamespace, setStaticScore, setWhatToShow
-
Methods inherited from class org.htmlunit.xpath.Expression
assertion, error, execute, exprGetParent, exprSetParent, getColumnNumber, getExpressionOwner, getLineNumber, getPublicId, getSystemId, isSameClass, isStableNumber, num
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.htmlunit.xpath.xml.dtm.DTMIterator
clone
-
-
-
-
Field Detail
-
m_clones
protected final transient IteratorPool m_clones
The pool for cloned iterators. Iterators need to be cloned because the hold running state, and thus the original iterator expression from the stylesheet pool can not be used.
-
m_cdtm
protected transient DTM m_cdtm
The dtm of the context node. Careful about using this... it may not be the dtm of the current node.
-
m_stackFrame
transient int m_stackFrame
The stack frame index for this iterator.
-
m_isTopLevel
private boolean m_isTopLevel
Value determined at compile time, indicates that this is an iterator at the top level of the expression, rather than inside a predicate.
-
m_lastFetched
public transient int m_lastFetched
The last node that was fetched, usually by nextNode.
-
m_context
protected transient int m_context
The context node for this iterator, which doesn't change through the course of the iteration.
-
m_currentContextNode
protected transient int m_currentContextNode
The node context from where the expression is being executed from (i.e. for current() support). Different from m_context in that this is the context for the entire expression, rather than the context for the subexpression.
-
m_pos
protected transient int m_pos
The current position of the context node.
-
m_length
protected transient int m_length
-
m_prefixResolver
private PrefixResolver m_prefixResolver
Fast access to the current prefix resolver. It isn't really clear that this is needed.
-
m_execContext
protected transient XPathContext m_execContext
The XPathContext reference, needed for execution of many operations.
-
-
Constructor Detail
-
LocPathIterator
protected LocPathIterator()
Create a LocPathIterator object.
-
LocPathIterator
protected LocPathIterator(PrefixResolver nscontext)
Create a LocPathIterator object.- Parameters:
nscontext- The namespace context for this iterator, should be OK if null.
-
LocPathIterator
protected LocPathIterator(int analysis) throws javax.xml.transform.TransformerExceptionCreate a LocPathIterator object, including creation of step walkers from the opcode list, and call back into the Compiler to create predicate expressions.- Throws:
javax.xml.transform.TransformerException- if any
-
LocPathIterator
protected LocPathIterator(int analysis, boolean shouldLoadWalkers) throws javax.xml.transform.TransformerExceptionCreate a LocPathIterator object, including creation of step walkers from the opcode list, and call back into the Compiler to create predicate expressions.- Parameters:
shouldLoadWalkers- True if walkers should be loaded, or false if this is a derived iterator and it doesn't wish to load child walkers.- Throws:
javax.xml.transform.TransformerException- if any
-
-
Method Detail
-
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.
-
getDTM
public DTM getDTM(int nodeHandle)
Get an instance of a DTM that "owns" a node handle. Since a node iterator may be passed without a DTMManager, this allows the caller to easily get the DTM using just the iterator.- Specified by:
getDTMin interfaceDTMIterator- Parameters:
nodeHandle- the nodeHandle.- Returns:
- a non-null DTM reference.
-
getDTMManager
public DTMManager getDTMManager()
Get an instance of the DTMManager. Since a node iterator may be passed without a DTMManager, this allows the caller to easily get the DTMManager using just the iterator.- Specified by:
getDTMManagerin interfaceDTMIterator- Returns:
- a non-null DTMManager reference.
-
execute
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
Execute an expression in the XPath runtime context, and return the result of the expression.
-
asIterator
public DTMIterator asIterator(XPathContext xctxt, int contextNode)
Given an select expression and a context, evaluate the XPath and return the resulting iterator.- Overrides:
asIteratorin classExpression- Parameters:
xctxt- The execution context.contextNode- The node that "." expresses.- Returns:
- A valid DTMIterator.
-
asNode
public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException
Return the first node out of the nodeset, if this expression is a nodeset expression.- Overrides:
asNodein classExpression- Parameters:
xctxt- The XPath runtime context.- Returns:
- the first node out of the nodeset, or DTM.NULL.
- Throws:
javax.xml.transform.TransformerException- if any
-
bool
public boolean bool(XPathContext xctxt) throws javax.xml.transform.TransformerException
Evaluate expression to a boolean.- Overrides:
boolin classExpression- Parameters:
xctxt- The XPath runtime context.- Returns:
- false
- Throws:
javax.xml.transform.TransformerException- if any
-
setIsTopLevel
public void setIsTopLevel(boolean b)
Set if this is an iterator at the upper level of the XPath.- Parameters:
b- true if this location path is at the top level of the expression.
-
getIsTopLevel
public boolean getIsTopLevel()
Get if this is an iterator at the upper level of the XPath.- Returns:
- true if this location path is at the top level of the expression.
-
setRoot
public void setRoot(int context, java.lang.Object environment)Reset the root node of theDTMIterator, overriding the value specified when it was created. Note the root node is not the root node of the document tree, but the context node from where the iteration begins.- Specified by:
setRootin interfaceDTMIterator- Parameters:
context- int Handle of the context node.environment- The environment object. The environment in which this iterator operates, which should provide:- a node (the context node... same value as "root" defined below)
- a pair of non-zero positive integers (the context position and the context size)
- a set of variable bindings
- a function library
- the set of namespace declarations in scope for the expression.
At this time the exact implementation of this environment is application dependent. Probably a proper interface will be created fairly soon.
-
getCurrentPos
public final int getCurrentPos()
Get the current position within the cached list, which is one less than the next nextNode() call will retrieve. i.e. if you call getCurrentPos() and the return is 0, the next fetch will take place at index 1.- Specified by:
getCurrentPosin interfaceDTMIterator- Returns:
- The position of the iteration.
-
setShouldCacheNodes
public void setShouldCacheNodes(boolean b)
If setShouldCacheNodes(true) is called, then nodes will be cached, enabling random access, and giving the ability to do sorts and the like. They are not cached by default.%REVIEW% Shouldn't the other random-access methods throw an exception if they're called on a DTMIterator with this flag set false?
- Specified by:
setShouldCacheNodesin interfaceDTMIterator- Parameters:
b- true if the nodes should be cached.
-
setCurrentPos
public void setCurrentPos(int i)
Set the current position in the node set.- Specified by:
setCurrentPosin interfaceDTMIterator- Parameters:
i- Must be a valid index.
-
incrementCurrentPos
public void incrementCurrentPos()
Increment the current position in the node set.
-
item
public int item(int index)
Returns thenode handleof an item in the collection. Ifindexis greater than or equal to the number of nodes in the list, this returnsnull.- Specified by:
itemin interfaceDTMIterator- Parameters:
index- of the item.- Returns:
- The node handle at the
indexth position in theDTMIterator, or-1if that is not a valid index.
-
getLength
public int getLength()
The number of nodes in the list. The range of valid child node indices is 0 tolength-1inclusive. Note that this requires running the iterator to completion, and presumably filling the cache.- Specified by:
getLengthin interfaceDTMIterator- Returns:
- The number of nodes in the list.
-
isFresh
public boolean isFresh()
Tells if this NodeSetDTM is "fresh", in other words, if the first nextNode() that is called will return the first node in the set.- Specified by:
isFreshin interfaceDTMIterator- Returns:
- true if the iteration of this list has not yet begun.
-
previousNode
public int previousNode()
Returns the previous node in the set and moves the position of theDTMIteratorbackwards in the set.- Specified by:
previousNodein interfaceDTMIterator- Returns:
- The previous node handle in the set being iterated over, or
DTM.NULLif there are no more members in that set.
-
getWhatToShow
public int getWhatToShow()
This attribute determines which node types are accepted. These constants are defined in theNodeFilterinterface.- Specified by:
getWhatToShowin interfaceDTMIterator- Overrides:
getWhatToShowin classNodeTest- Returns:
- bitset mainly defined in
NodeFilter.
-
getRoot
public int getRoot()
The root node of theDTMIterator, as specified when it was created. Note the root node is not the root node of the document tree, but the context node from where the iteration begins and ends.- Specified by:
getRootin interfaceDTMIterator- Returns:
- nodeHandle int Handle of the context node.
-
getExpandEntityReferences
public boolean getExpandEntityReferences()
The value of this flag determines whether the children of entity reference nodes are visible to the iterator. If false, they and their descendants will be rejected. Note that this rejection takes precedence overwhatToShowand the filter.To produce a view of the document that has entity references expanded and does not expose the entity reference node itself, use the
whatToShowflags to hide the entity reference node and setexpandEntityReferencesto true when creating the iterator. To produce a view of the document that has entity reference nodes but no entity expansion, use thewhatToShowflags to show the entity reference node and setexpandEntityReferencesto false.NOTE: In Xalan's use of DTM we will generally have fully expanded entity references when the document tree was built, and thus this flag will have no effect.
- Specified by:
getExpandEntityReferencesin interfaceDTMIterator- Returns:
- true if entity references will be expanded.
-
detach
public void detach()
Detaches theDTMIteratorfrom the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state. Afterdetachhas been invoked, calls tonextNodeorpreviousNodewill raise a runtime exception.- Specified by:
detachin interfaceDTMIterator
-
reset
public void reset()
Reset the iterator to the start. After resetting, the next node returned will be the root node -- or, if that's filtered out, the first node within the root's subtree which is _not_ skipped by the filters.- Specified by:
resetin interfaceDTMIterator
-
cloneWithReset
public DTMIterator cloneWithReset() throws java.lang.CloneNotSupportedException
Get a cloned Iterator that is reset to the start of the iteration.- Specified by:
cloneWithResetin interfaceDTMIterator- Returns:
- A clone of this iteration that has been reset.
- Throws:
java.lang.CloneNotSupportedException- if any
-
nextNode
public abstract int nextNode()
Returns the next node in the set and advances the position of the iterator in the set. After aDTMIteratorhas setRoot called, the first call tonextNode()returns that root or (if it is rejected by the filters) the first node within its subtree which is not filtered out.- Specified by:
nextNodein interfaceDTMIterator- Returns:
- The next node handle in the set being iterated over, or
DTM.NULLif there are no more members in that set.
-
returnNextNode
protected int returnNextNode(int nextNode)
Bottleneck the return of a next node, to make returns easier from nextNode().- Parameters:
nextNode- The next node found, may be null.- Returns:
- The same node that was passed as an argument.
-
getCurrentNode
public int getCurrentNode()
Get the current node in the iterator. Note that this differs from the DOM's NodeIterator, where the current position lies between two nodes (as part of the maintain-relative-position semantic).- Specified by:
getCurrentNodein interfaceDTMIterator- Returns:
- The current node handle, or -1.
-
runTo
public void runTo(int index)
If an index is requested, NodeSetDTM will call this method to run the iterator to the index. By default this sets m_next to the index. If the index argument is -1, this signals that the iterator should be run to the end and completely fill the cache.- Specified by:
runToin interfaceDTMIterator- Parameters:
index- The index to run to, or -1 if the iterator should be run to the end.
-
getXPathContext
public final XPathContext getXPathContext()
The XPath execution context we are operating on.- Returns:
- XPath execution context this iterator is operating on, or null if setRoot has not been called.
-
getPrefixResolver
public final PrefixResolver getPrefixResolver()
Return the saved reference to the prefix resolver that was in effect when this iterator was created.- Returns:
- The prefix resolver or this iterator, which may be null.
-
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.
-
isDocOrdered
public boolean isDocOrdered()
Returns true if all the nodes in the iteration well be returned in document order.- Specified by:
isDocOrderedin interfaceDTMIterator- Returns:
- true if all the nodes in the iteration well be returned in document order.
-
getAxis
public int getAxis()
Returns the axis being iterated, if it is known.- Specified by:
getAxisin interfaceDTMIterator- Returns:
- Axis.CHILD, etc., or -1 if the axis is not known or is of multiple types.
-
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.
-
-