org.apache.xpath.axes
Class LocPathIterator

java.lang.Object
  |
  +--org.apache.xpath.Expression
        |
        +--org.apache.xpath.patterns.NodeTest
              |
              +--org.apache.xpath.axes.PredicatedNodeTest
                    |
                    +--org.apache.xpath.axes.LocPathIterator
Direct Known Subclasses:
AttributeIterator, ChildIterator, ChildTestIterator, DescendantIterator, KeyIterator, KeyRefIterator

public class LocPathIterator
extends PredicatedNodeTest
implements java.lang.Cloneable, NodeIterator, ContextNodeList, NodeList, java.io.Serializable

**For advanced use only** This class extends NodeSet, which implements NodeIterator, and fetches nodes one at a time in document order based on a XPath

See Also:
Serialized Form

Field Summary
 Node m_lastFetched
          The last node that was fetched, usually by nextNode.
 
Fields inherited from class org.apache.xpath.patterns.NodeTest
SCORE_NODETEST, SCORE_NONE, SCORE_NSWILD, SCORE_OTHER, SCORE_QNAME, SHOW_BYFUNCTION, SHOW_NAMESPACE, SUPPORTS_PRE_STRIPPING, WILD
 
Constructor Summary
LocPathIterator(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.
LocPathIterator(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.
LocPathIterator(PrefixResolver nscontext)
          Create a LocPathIterator object.
 
Method Summary
 void addToWaitList(AxesWalker walker)
          **For advanced use only** Add a walker to the waiting list.
 boolean canTraverseOutsideSubtree()
          Tell if this expression or it's subexpressions can traverse outside the current subtree.
 java.lang.Object clone()
          Get a cloned LocPathIterator that holds the same position as this iterator.
 NodeIterator cloneWithReset()
          Get a cloned Iterator that is reset to the beginning of the query.
 void detach()
          Detaches the iterator from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.
 XObject execute(XPathContext xctxt)
          Execute this iterator, meaning create a clone that can store state, and initialize it for fast execution from the current runtime state.
 NodeSet getCachedNodes()
          Get cached nodes.
 Node getContext()
          The node context for the iterator.
 Node getCurrentContextNode()
          The node context from where the expression is being executed from (i.e.
 Node getCurrentNode()
          Return the last fetched node.
 int getCurrentPos()
          Get the current position, which is one less than the next nextNode() call will retrieve.
 DOMHelper getDOMHelper()
          The DOM helper for the given context;
 boolean getExpandEntityReferences()
          The value of this flag determines whether the children of entity reference nodes are visible to the iterator.
 NodeFilter getFilter()
          The filter used to screen nodes.
 AxesWalker getFirstWalker()
          **For advanced use only** Get the head of the walker list.
 boolean getFoundLast()
          Tells if we've found the last node yet.
 boolean getIsTopLevel()
          **For advanced use only** Get if this is an iterator at the upper level of the XPath.
 int getLast()
          Get the index of the last node in the iteration.
 int getLastPos(XPathContext xctxt)
          Get the index of the last node that can be itterated to.
 AxesWalker getLastUsedWalker()
          **For advanced use only** Get the last used walker.
 int getLength()
          The number of nodes in the list.
 PrefixResolver getPrefixResolver()
          Return the saved reference to the prefix resolver that was in effect when this iterator was created.
 Node getRoot()
          The root node of the Iterator, as specified when it was created.
 int getWhatToShow()
          This attribute determines which node types are presented via the iterator.
 XPathContext getXPathContext()
          The XPath execution context we are operating on.
 void initContext(XPathContext execContext)
          Initialize the context values for this expression after it is cloned.
 boolean isFresh()
          Tells if this NodeSet is "fresh", in other words, if the first nextNode() that is called will return the first node in the set.
 Node item(int index)
          Returns the index th item in the collection.
 Node nextNode()
          Returns the next node in the set and advances the position of the iterator in the set.
 Node previousNode()
          Returns the previous node in the set and moves the position of the iterator backwards in the set.
 void removeFromWaitList(AxesWalker walker)
          **For advanced use only** Remove a walker from the waiting list.
 void reset()
          Reset the iterator.
 void runTo(int index)
          If an index is requested, NodeSet will call this method to run the iterator to the index.
 void setCurrentContextNode(Node n)
          Set the current context node for this iterator.
 void setCurrentPos(int i)
          Set the current position in the node set.
 void setIsTopLevel(boolean b)
          **For advanced use only** Set if this is an iterator at the upper level of the XPath.
 void setLast(int last)
          Set the index of the last node in the iteration.
 void setLastUsedWalker(AxesWalker walker)
          **For advanced use only** Set the last used walker.
 void setShouldCacheNodes(boolean b)
          If setShouldCacheNodes(true) is called, then nodes will be cached.
 int size()
          Get the length of the cached nodes.
 
Methods inherited from class org.apache.xpath.axes.PredicatedNodeTest
acceptNode, getLocPathIterator, getPredicateCount, getPredicateIndex, getProximityPosition, getProximityPosition, initProximityPosition, isReverseAxes, resetProximityPositions, setLocPathIterator, setPredicateCount
 
Methods inherited from class org.apache.xpath.patterns.NodeTest
debugWhatToShow, execute, getDefaultScore, getLocalName, getNamespace, initNodeTest, initNodeTest
 
Methods inherited from class org.apache.xpath.Expression
assert, error, setSourceLocator, warn
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_lastFetched

public transient Node m_lastFetched
The last node that was fetched, usually by nextNode.
Constructor Detail

LocPathIterator

public LocPathIterator(PrefixResolver nscontext)
Create a LocPathIterator object.
Parameters:
nscontext - The namespace context for this iterator, should be OK if null.

LocPathIterator

public LocPathIterator(Compiler compiler,
                       int opPos,
                       int analysis)
                throws TransformerException
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

public LocPathIterator(Compiler compiler,
                       int opPos,
                       int analysis,
                       boolean shouldLoadWalkers)
                throws TransformerException
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.
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 Detail

execute

public XObject execute(XPathContext xctxt)
                throws TransformerException
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.
Parameters:
xctxt - The XPath execution context.
Returns:
An XNodeSet reference that holds this iterator.
Throws:
TransformerException -  
Overrides:
execute in class NodeTest

setIsTopLevel

public void setIsTopLevel(boolean b)
**For advanced use only** 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()
**For advanced use only** 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.

initContext

public void initContext(XPathContext execContext)
Initialize the context values for this expression after it is cloned.
Parameters:
execContext - The XPath runtime context for this transformation.

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:
getCurrentPos in interface ContextNodeList
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:
setShouldCacheNodes in interface ContextNodeList
Parameters:
b - True if this iterator should cache nodes.

getCachedNodes

public NodeSet getCachedNodes()
Get cached nodes.
Returns:
Cached nodes.

setCurrentPos

public void setCurrentPos(int i)
Set the current position in the node set.
Specified by:
setCurrentPos in interface ContextNodeList
Parameters:
i - Must be a valid index greater than or equal to zero and less than m_cachedNodes.size().

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.

Specified by:
size in interface ContextNodeList
Returns:
The size of the current cache list.

item

public Node item(int index)
Returns the index th item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null .
Specified by:
item in interface NodeList
Parameters:
index - Index into the collection.
Returns:
The node at the index th position in the NodeList , or null if 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 to length-1 inclusive.
Specified by:
getLength in interface NodeList
Returns:
The number of nodes in the list, always greater or equal to zero.

isFresh

public boolean isFresh()
Tells if this NodeSet is "fresh", in other words, if the first nextNode() that is called will return the first node in the set.
Specified by:
isFresh in interface ContextNodeList
Returns:
true of nextNode has not been called.

previousNode

public Node previousNode()
                  throws DOMException
Returns the previous node in the set and moves the position of the iterator backwards in the set.
Specified by:
previousNode in interface NodeIterator
Returns:
The previous Node in the set being iterated over, ornull if there are no more members in that set.
Throws:
DOMException - INVALID_STATE_ERR: Raised if this method is called after the detach method was invoked.

getWhatToShow

public int getWhatToShow()
This attribute determines which node types are presented via the iterator. The available set of constants is defined in the NodeFilter interface.

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:
getWhatToShow in interface NodeIterator
Returns:
For now, always NodeFilter.SHOW_ALL & ~NodeFilter.SHOW_ENTITY_REFERENCE.
Overrides:
getWhatToShow in class NodeTest
See Also:
NodeIterator

getFilter

public NodeFilter getFilter()
The filter used to screen nodes. Not used at this time, this is here only to fullfill the DOM NodeIterator interface.
Specified by:
getFilter in interface NodeIterator
Returns:
Always null.
See Also:
NodeIterator

getRoot

public Node getRoot()
The root node of the Iterator, as specified when it was created.
Specified by:
getRoot in interface NodeIterator
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:
getExpandEntityReferences in interface NodeIterator
Returns:
Always true, since entity reference nodes are not visible in the XPath model.

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. Afterdetach has been invoked, calls to nextNode orpreviousNode will raise the exception INVALID_STATE_ERR.
Specified by:
detach in interface NodeIterator

cloneWithReset

public NodeIterator cloneWithReset()
                            throws java.lang.CloneNotSupportedException
Get a cloned Iterator that is reset to the beginning of the query.
Specified by:
cloneWithReset in interface ContextNodeList
Returns:
A cloned NodeIterator set of the start of the query.
Throws:
java.lang.CloneNotSupportedException -  

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Get a cloned LocPathIterator that holds the same position as this iterator.
Specified by:
clone in interface ContextNodeList
Returns:
A clone of this iterator that holds the same node position.
Throws:
java.lang.CloneNotSupportedException -  
Overrides:
clone in class PredicatedNodeTest

reset

public void reset()
Reset the iterator.
Specified by:
reset in interface ContextNodeList

nextNode

public Node nextNode()
              throws DOMException
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:
nextNode in interface NodeIterator
Returns:
The next Node in the set being iterated over, or null if there are no more members in that set.
Throws:
DOMException - INVALID_STATE_ERR: Raised if this method is called after the detach method was invoked.

getCurrentNode

public Node getCurrentNode()
Return the last fetched node. Needed to support the UnionPathIterator.
Specified by:
getCurrentNode in interface ContextNodeList
Returns:
The last fetched node, or null if the last fetch was null.

runTo

public void runTo(int index)
If an index is requested, NodeSet 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:
runTo in interface ContextNodeList
Parameters:
index - The index to run to, or -1 if the iterator should run to the end.

getFirstWalker

public final AxesWalker getFirstWalker()
**For advanced use only** Get the head of the walker list.
Returns:
The head of the walker list, or null if this iterator does not implement walkers.

setLastUsedWalker

public final void setLastUsedWalker(AxesWalker walker)
**For advanced use only** Set the last used walker.
Parameters:
walker - The last used walker, or null.

getLastUsedWalker

public final AxesWalker getLastUsedWalker()
**For advanced use only** Get the last used walker.
Returns:
The last used walker, or null.

addToWaitList

public final void addToWaitList(AxesWalker walker)
**For advanced use only** Add a walker to the waiting list.
Parameters:
walker - A walker that is waiting for other step walkers to complete, before it can continue.
See Also:
AxesWalker

removeFromWaitList

public final void removeFromWaitList(AxesWalker walker)
**For advanced use only** Remove a walker from the waiting list.
Parameters:
walker - A walker that is no longer waiting.
See Also:
AxesWalker

getFoundLast

public final boolean getFoundLast()
Tells if we've found the last node yet.
Returns:
true if the last nextNode returned null.

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 initContext has not been called.

getDOMHelper

public final DOMHelper getDOMHelper()
The DOM helper for the given context;
Returns:
The DOMHelper that should be used, or null if initContext has not been called.

getContext

public final Node getContext()
The node context for the iterator.
Returns:
The node context, same as getRoot().

getCurrentContextNode

public final Node 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(Node n)
Set the current context node for this iterator.
Parameters:
n - Must be a non-null reference to the node context.

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.

getLast

public int getLast()
Get the index of the last node in the iteration.
Specified by:
getLast in interface ContextNodeList
Returns:
the index of the last node in the iteration.

setLast

public void setLast(int last)
Set the index of the last node in the iteration.
Specified by:
setLast in interface ContextNodeList
Parameters:
last - the index of the last node in the iteration.

getLastPos

public int getLastPos(XPathContext xctxt)
Get the index of the last node that can be itterated to. This probably will need to be overridded by derived classes.
Parameters:
xctxt - XPath runtime context.
Returns:
the index of the last node that can be itterated to.
Overrides:
getLastPos in class PredicatedNodeTest

canTraverseOutsideSubtree

public boolean canTraverseOutsideSubtree()
Tell if this expression or it's subexpressions can traverse outside the current subtree.
Returns:
true if traversal outside the context node's subtree can occur.
Overrides:
canTraverseOutsideSubtree in class PredicatedNodeTest


Copyright � 2000 Apache XML Project. All Rights Reserved.