Class LocPathIterator
- All Implemented Interfaces:
Serializable,Cloneable,SourceLocator,DTMIterator,PathComponent,SubContextList,ExpressionNode,XPathVisitable
- Direct Known Subclasses:
BasicTestIterator,ChildIterator,DescendantIterator,FilterExprIteratorSimple,MatchPatternIterator,SelfIteratorNoPredicate,UnionPathIterator,WalkingIterator
public abstract class LocPathIterator extends PredicatedNodeTest implements Cloneable, DTMIterator, Serializable, PathComponent
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected booleanm_allowDetachControl over whether it is OK for detach to reset the iterator.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.intm_lastFetchedThe last node that was fetched, usually by nextNode.protected intm_lengthprotected intm_posThe current position of the context node.Fields inherited from class org.apache.xpath.axes.PredicatedNodeTest
m_foundLast, m_lpi, m_predCount, m_proximityPositionsFields inherited from class org.apache.xpath.patterns.NodeTest
m_name, m_whatToShow, SCORE_NODETEST, SCORE_NONE, SCORE_NSWILD, SCORE_OTHER, SCORE_QNAME, SHOW_BYFUNCTION, SUPPORTS_PRE_STRIPPING, WILDFields inherited from interface org.apache.xml.dtm.DTMIterator
FILTER_ACCEPT, FILTER_REJECT, FILTER_SKIP -
Constructor Summary
Constructors Modifier Constructor Description protectedLocPathIterator()Create a LocPathIterator object.protectedLocPathIterator(PrefixResolver nscontext)Create a LocPathIterator object.protectedLocPathIterator(Compiler compiler, int opPos, 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(Compiler compiler, int opPos, 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. -
Method Summary
Modifier and Type Method Description voidallowDetachToRelease(boolean allowRelease)Specify if it's OK for detach to release the iterator for reuse.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 this operation directly to a boolean.voidcallVisitors(ExpressionOwner owner, XPathVisitor visitor)This will traverse the heararchy, calling the visitor for each member.DTMIteratorcloneWithReset()Get a cloned Iterator that is reset to the beginning of the query.voiddetach()Detaches the iterator from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.XObjectexecute(XPathContext xctxt)Execute this iterator, meaning create a clone that can store state, and initialize it for fast execution from the current runtime state.voidexecuteCharsToContentHandler(XPathContext xctxt, ContentHandler handler)Execute an expression in the XPath runtime context, and return the result of the expression.intgetAnalysisBits()Get the analysis bits for this walker, as defined in the WalkerFactory.intgetAxis()Returns the axis being iterated, if it is known.intgetContext()The node context for the iterator.intgetCurrentContextNode()The node context from where the expression is being executed from (i.e.intgetCurrentNode()Return the last fetched node.intgetCurrentPos()Get the current position, 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.DTMFiltergetFilter()The filter used to screen nodes.booleangetFoundLast()Tells if we've found the last node yet.booleangetIsTopLevel()Get if this is an iterator at the upper level of the XPath.intgetLastPos(XPathContext xctxt)Get the index of the last node that can be itterated to.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 the Iterator, as specified when it was created.intgetWhatToShow()This attribute determines which node types are presented via the iterator.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.booleanisMutable()Tells if this iterator can have nodes added to it or set via thesetItem(int node, int index)method.booleanisNodesetExpr()Tell if the expression is a nodeset expression.intitem(int index)Returns theindexth 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 the iterator backwards in the set.voidreset()Reset the iterator.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.voidsetCurrentContextNode(int n)Set the current context node for this iterator.voidsetCurrentPos(int i)Set the current position in the node set.voidsetEnvironment(Object environment)Set the environment in which this iterator operates, which should provide: a node (the context node...voidsetIsTopLevel(boolean b)Set if this is an iterator at the upper level of the XPath.voidsetItem(int node, int index)Sets the node at the specified index of this vector to be the specified node.protected voidsetNextPosition(int next)Set the next position index of this iterator.voidsetRoot(int context, Object environment)Initialize the context values for this expression after it is cloned.voidsetShouldCacheNodes(boolean b)If setShouldCacheNodes(true) is called, then nodes will be cached.intsize()Get the length of the cached nodes.Methods inherited from class org.apache.xpath.axes.PredicatedNodeTest
acceptNode, callPredicateVisitors, canTraverseOutsideSubtree, clone, countProximityPosition, deepEquals, fixupVariables, getLocPathIterator, getPredicate, getPredicateCount, getPredicateIndex, getProximityPosition, getProximityPosition, getProximityPosition, initPredicateInfo, initProximityPosition, isReverseAxes, nodeToString, resetProximityPositions, setLocPathIterator, setPredicateCountMethods inherited from class org.apache.xpath.patterns.NodeTest
calcScore, debugWhatToShow, execute, execute, getDefaultScore, getLocalName, getNamespace, getNodeTypeTest, getStaticScore, initNodeTest, initNodeTest, setLocalName, setNamespace, setStaticScore, setWhatToShowMethods inherited from class org.apache.xpath.Expression
asIteratorRaw, assertion, error, execute, exprAddChild, exprGetChild, exprGetNumChildren, exprGetParent, exprSetParent, getColumnNumber, getExpressionOwner, getLineNumber, getPublicId, getSystemId, isSameClass, isStableNumber, num, warn, xstrMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.xml.dtm.DTMIterator
clone
-
Field Details
-
m_allowDetach
protected boolean m_allowDetachControl over whether it is OK for detach to reset the iterator. -
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
The dtm of the context node. Careful about using this... it may not be the dtm of the current node. -
m_lastFetched
public transient int m_lastFetchedThe last node that was fetched, usually by nextNode. -
m_context
protected transient int m_contextThe context node for this iterator, which doesn't change through the course of the iteration. -
m_currentContextNode
protected transient int m_currentContextNodeThe 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_posThe current position of the context node. -
m_length
protected transient int m_length -
m_execContext
The XPathContext reference, needed for execution of many operations.
-
-
Constructor Details
-
LocPathIterator
protected LocPathIterator()Create a LocPathIterator object. -
LocPathIterator
Create a LocPathIterator object.- Parameters:
nscontext- The namespace context for this iterator, should be OK if null.
-
LocPathIterator
Create a LocPathIterator object, including creation of step walkers from the opcode list, and call back into the Compiler to create predicate expressions.- Parameters:
compiler- The Compiler which is creating this expression.opPos- The position of this iterator in the opcode list from the compiler.- Throws:
TransformerException
-
LocPathIterator
protected LocPathIterator(Compiler compiler, int opPos, int analysis, boolean shouldLoadWalkers) throws TransformerExceptionCreate a LocPathIterator object, including creation of step walkers from the opcode list, and call back into the Compiler to create predicate expressions.- Parameters:
compiler- The Compiler which is creating this expression.opPos- The position of this iterator in the opcode list from the compiler.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:
TransformerException
-
-
Method Details
-
getAnalysisBits
public int getAnalysisBits()Get the analysis bits for this walker, as defined in the WalkerFactory.- Specified by:
getAnalysisBitsin interfacePathComponent- Returns:
- One of WalkerFactory#BIT_DESCENDANT, etc.
-
setEnvironment
Set 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.
- Parameters:
environment- The environment object.
-
getDTM
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
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
Execute this iterator, meaning create a clone that can store state, and initialize it for fast execution from the current runtime state. When this is called, no actual query from the current context node is performed.- Overrides:
executein classNodeTest- Parameters:
xctxt- The XPath execution context.- Returns:
- An XNodeSet reference that holds this iterator.
- Throws:
TransformerException
-
executeCharsToContentHandler
public void executeCharsToContentHandler(XPathContext xctxt, ContentHandler handler) throws TransformerException, SAXExceptionExecute an expression in the XPath runtime context, and return the result of the expression.- Overrides:
executeCharsToContentHandlerin classExpression- Parameters:
xctxt- The XPath runtime context.handler- The target content handler.- Throws:
TransformerException- if a runtime exception occurs.SAXException
-
asIterator
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.
- Throws:
TransformerException- thrown if the active ProblemListener decides the error condition is severe enough to halt processing.TransformerException
-
isNodesetExpr
public boolean isNodesetExpr()Tell if the expression is a nodeset expression.- Overrides:
isNodesetExprin classExpression- Returns:
- true if the expression can be represented as a nodeset.
-
asNode
Return the first node out of the nodeset, if this expression is a nodeset expression. This is the default implementation for nodesets. Derived classes should try and override this and return a value without having to do a clone operation.- Overrides:
asNodein classExpression- Parameters:
xctxt- The XPath runtime context.- Returns:
- the first node out of the nodeset, or DTM.NULL.
- Throws:
TransformerException
-
bool
Evaluate this operation directly to a boolean.- Overrides:
boolin classExpression- Parameters:
xctxt- The runtime execution context.- Returns:
- The result of the operation as a boolean.
- Throws:
TransformerException
-
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
Initialize the context values for this expression after it is cloned.- Specified by:
setRootin interfaceDTMIterator- Parameters:
context- The XPath runtime context for this transformation.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.
-
setNextPosition
protected void setNextPosition(int next)Set the next position index of this iterator.- Parameters:
next- A value greater than or equal to zero that indicates the next node position to fetch.
-
getCurrentPos
public final int getCurrentPos()Get the current position, 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:
- A value greater than or equal to zero that indicates the next node position to fetch.
-
setShouldCacheNodes
public void setShouldCacheNodes(boolean b)If setShouldCacheNodes(true) is called, then nodes will be cached. They are not cached by default.- Specified by:
setShouldCacheNodesin interfaceDTMIterator- Parameters:
b- True if this iterator should cache nodes.
-
isMutable
public boolean isMutable()Tells if this iterator can have nodes added to it or set via thesetItem(int node, int index)method.- Specified by:
isMutablein interfaceDTMIterator- Returns:
- True if the nodelist can be mutated.
-
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 greater than or equal to zero and less than m_cachedNodes.size().
-
incrementCurrentPos
public void incrementCurrentPos()Increment the current position in the node set. -
size
public int size()Get the length of the cached nodes.Note: for the moment at least, this only returns the size of the nodes that have been fetched to date, it doesn't attempt to run to the end to make sure we have found everything. This should be reviewed.
- Returns:
- The size of the current cache list.
-
item
public int item(int index)Returns theindexth 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- Index into the collection.- Returns:
- The node at the
indexth position in theNodeList, ornullif that is not a valid index.
-
setItem
public void setItem(int node, int index)Sets the node at the specified index of this vector to be the specified node. The previous component at that position is discarded.The index must be a value greater than or equal to 0 and less than the current size of the vector. The iterator must be in cached mode.
Meant to be used for sorted iterators.
- Specified by:
setItemin interfaceDTMIterator- Parameters:
node- Node to setindex- Index of where to set the node
-
getLength
public int getLength()The number of nodes in the list. The range of valid child node indices is 0 tolength-1inclusive.- Specified by:
getLengthin interfaceDTMIterator- Returns:
- The number of nodes in the list, always greater or equal to zero.
-
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 of nextNode has not been called.
-
previousNode
public int previousNode()Returns the previous node in the set and moves the position of the iterator backwards in the set.- Specified by:
previousNodein interfaceDTMIterator- Returns:
- The previous
Nodein the set being iterated over, ornullif there are no more members in that set.
-
getWhatToShow
public int getWhatToShow()This attribute determines which node types are presented via the iterator. The available set of constants is defined in theNodeFilterinterface.This is somewhat useless at this time, since it doesn't really return information that tells what this iterator will show. It is here only to fullfill the DOM NodeIterator interface.
- Specified by:
getWhatToShowin interfaceDTMIterator- Overrides:
getWhatToShowin classNodeTest- Returns:
- For now, always NodeFilter.SHOW_ALL & ~NodeFilter.SHOW_ENTITY_REFERENCE.
- See Also:
NodeIterator
-
getFilter
The filter used to screen nodes. Not used at this time, this is here only to fullfill the DOM NodeIterator interface.- Returns:
- Always null.
- See Also:
NodeIterator
-
getRoot
public int getRoot()The root node of the Iterator, as specified when it was created.- Specified by:
getRootin interfaceDTMIterator- Returns:
- The "root" of this iterator, which, in XPath terms, is the node context for this iterator.
-
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 will be skipped over.
To produce a view of the document that has entity references expanded and does not expose the entity reference node itself, use the whatToShow flags to hide the entity reference node and set expandEntityReferences to true when creating the iterator. To produce a view of the document that has entity reference nodes but no entity expansion, use the whatToShow flags to show the entity reference node and set expandEntityReferences to false.- Specified by:
getExpandEntityReferencesin interfaceDTMIterator- Returns:
- Always true, since entity reference nodes are not visible in the XPath model.
-
allowDetachToRelease
public void allowDetachToRelease(boolean allowRelease)Specify if it's OK for detach to release the iterator for reuse.- Specified by:
allowDetachToReleasein interfaceDTMIterator- Parameters:
allowRelease- true if it is OK for detach to release this iterator for pooling.
-
detach
public void detach()Detaches the iterator from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state. Afterdetachhas been invoked, calls tonextNodeorpreviousNodewill raise the exception INVALID_STATE_ERR.- Specified by:
detachin interfaceDTMIterator
-
reset
public void reset()Reset the iterator.- Specified by:
resetin interfaceDTMIterator
-
cloneWithReset
Get a cloned Iterator that is reset to the beginning of the query.- Specified by:
cloneWithResetin interfaceDTMIterator- Returns:
- A cloned NodeIterator set of the start of the query.
- Throws:
CloneNotSupportedException
-
nextNode
public abstract int nextNode()Returns the next node in the set and advances the position of the iterator in the set. After a NodeIterator is created, the first call to nextNode() returns the first node in the set.- Specified by:
nextNodein interfaceDTMIterator- Returns:
- The next
Nodein the set being iterated over, ornullif 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()Return the last fetched node. Needed to support the UnionPathIterator.- Specified by:
getCurrentNodein interfaceDTMIterator- Returns:
- The last fetched node, or null if the last fetch was null.
-
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.- Specified by:
runToin interfaceDTMIterator- Parameters:
index- The index to run to, or -1 if the iterator should run to the end.
-
getFoundLast
public final boolean getFoundLast()Tells if we've found the last node yet.- Returns:
- true if the last nextNode returned null.
-
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.
-
getContext
public final int getContext()The node context for the iterator.- Returns:
- The node context, same as getRoot().
-
getCurrentContextNode
public final int getCurrentContextNode()The node context from where the expression is being executed from (i.e. for current() support).- Returns:
- The top-level node context of the entire expression.
-
setCurrentContextNode
public final void setCurrentContextNode(int n)Set the current context node for this iterator.- Parameters:
n- Must be a non-null reference to the node context.
-
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
Description copied from interface:XPathVisitableThis will traverse the heararchy, 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:
owner- The owner of the visitor, where that path may be rewritten if needed.visitor- The visitor whose appropriate method will be called.- See Also:
XPathVisitable.callVisitors(ExpressionOwner, XPathVisitor)
-
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 as a default.
-
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
Description copied from class:PredicatedNodeTestGet the index of the last node that can be itterated to.- Specified by:
getLastPosin interfaceSubContextList- Specified by:
getLastPosin classPredicatedNodeTest- Parameters:
xctxt- XPath runtime context.- Returns:
- the index of the last node that can be itterated to.
- See Also:
PredicatedNodeTest.getLastPos(XPathContext)
-