APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.org.apache.xpath.internal.axes

public Class NodeSequence

extends XObject
implements DTMIterator, Cloneable, PathComponent
Class Inheritance
All Implemented Interfaces
com.sun.org.apache.xpath.internal.axes.PathComponent, java.lang.Cloneable, com.sun.org.apache.xml.internal.dtm.DTMIterator
Known Direct Subclasses
com.sun.org.apache.xpath.internal.objects.XNodeSet
Imports
com.sun.org.apache.xml.internal.dtm.DTM, .DTMFilter, .DTMIterator, .DTMManager, com.sun.org.apache.xml.internal.utils.NodeVector, .QName, com.sun.org.apache.xpath.internal.NodeSetDTM, .XPathContext, com.sun.org.apache.xpath.internal.objects.XObject, java.util.List

This class is the dynamic wrapper for a Xalan DTMIterator instance, and provides random access capabilities.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
NodeSequence.IteratorCache

Each NodeSequence object has an iterator which is "walked".

Field Summary

Modifier and TypeField and Description
private NodeSequence.IteratorCache
m_cache

A cache of a list of nodes obtained from the iterator so far.

protected DTMManager
m_dtmMgr

The DTMManager to use if we're using a NodeVector only.

protected DTMIterator
m_iter

The functional iterator that fetches nodes.

protected int
m_last

The index of the last node in the iteration.

protected int
m_next

The index of the next node to be fetched.

pack-priv static final long
Inherited from com.sun.org.apache.xpath.internal.objects.XObject:
CLASS_BOOLEANCLASS_NODESETCLASS_NULLCLASS_NUMBERCLASS_RTREEFRAGCLASS_STRINGCLASS_UNKNOWNCLASS_UNRESOLVEDVARIABLEm_obj

Constructor Summary

AccessConstructor and Description
private
NodeSequence(DTMIterator
Cloned (not static) DTMIterator.
iter
,
int
The initial context node.
context
,
XPathContext
The execution context.
xctxt
,
boolean
True if this sequence can random access.
shouldCacheNodes
)

Create a new NodeSequence from a (already cloned) iterator.

public
NodeSequence(Object nodeVector)

Create a new NodeSequence from a (already cloned) iterator.

private
NodeSequence(DTMManager dtmMgr)

Construct an empty XNodeSet object.

public
NodeSequence()

Create a new NodeSequence in an invalid (null) state.

Method Summary

Modifier and TypeMethod and Description
protected int

Returns:

insertIndex.
addNodeInDocOrder
(int
The node to be added.
node
)

Add the node into a vector of nodes where it should occur in document order.

public void
allowDetachToRelease(boolean allowRelease)

Overrides com.sun.org.apache.xpath.internal.objects.XObject.allowDetachToRelease.

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.allowDetachToRelease.

Calling this with a value of false will cause the nodeset to be cached.

private boolean
cacheComplete()

If this NodeSequence has a cache, and that cache is fully populated then this method returns true, otherwise if there is no cache or it is not complete it returns false.

public Object

Returns:

A clone of this object.
clone
()

Overrides java.lang.Object.clone.

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.clone.

Get a clone of this iterator, but don't reset the iteration in the process, so that it may be used from the current position.

public DTMIterator
public void
detach()

Overrides com.sun.org.apache.xpath.internal.objects.XObject.detach.

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.detach.

Detaches the DTMIterator from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state.

public void
fixupVariables(List<QName> vars, int globalsSize)

Overrides com.sun.org.apache.xpath.internal.objects.XObject.fixupVariables.

XObjects should not normally need to fix up variables.

public int
getAnalysisBits()

Implements com.sun.org.apache.xpath.internal.axes.PathComponent.getAnalysisBits.

Get the analysis bits for this path component, as defined in the WalkerFactory.

public int
getAxis()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getAxis.

Returns the axis being iterated, if it is known.

private NodeSequence.IteratorCache
getCache()

Get the cache (if any) of nodes obtained from the iterator so far.

public final DTMIterator

Returns:

The contained iterator.
getContainedIter
()

Get the functional iterator that fetches nodes.

public int
getCurrentNode()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getCurrentNode.

Get the current node in the iterator.

public int
getCurrentPos()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getCurrentPos.

Get the current position within the cached list, which is one less than the next nextNode() call will retrieve.

public DTM
getDTM(int nodeHandle)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getDTM.

Get an instance of a DTM that "owns" a node handle.

public DTMManager
getDTMManager()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getDTMManager.

Get an instance of the DTMManager.

public boolean
getExpandEntityReferences()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getExpandEntityReferences.

The value of this flag determines whether the children of entity reference nodes are visible to the iterator.

protected NodeSequence.IteratorCache
getIteratorCache()

Get the cached list of nodes appended with values obtained from the iterator as a NodeSequence is walked when its nextNode() method is called.

public int
getLength()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getLength.

The number of nodes in the list.

public int
getRoot()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getRoot.

The root node of the DTMIterator, as specified when it was created.

protected NodeVector
getVector()

If this iterator needs to cache nodes that are fetched, they are stored in the Vector in the generic object.

public int
getWhatToShow()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getWhatToShow.

This attribute determines which node types are presented via the iterator.

public boolean
hasCache()

If the iterator needs to cache nodes as they are fetched, then this method returns true.

public boolean
isDocOrdered()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.isDocOrdered.

Returns true if all the nodes in the iteration well be returned in document order.

public boolean
isFresh()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.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.

public boolean
isMutable()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.isMutable.

Tells if this iterator can have nodes added to it or set via the setItem(int node, int index) method.

public int
item(int index)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.item.

Returns the node handle of an item in the collection.

private void
markCacheComplete()

If this NodeSequence has a cache, mark that it is complete.

public int
nextNode()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.nextNode.

Returns the next node in the set and advances the position of the iterator in the set.

public int
previousNode()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.previousNode.

Returns the previous node in the set and moves the position of the DTMIterator backwards in the set.

public void
public void
runTo(int index)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.runTo.

If an index is requested, NodeSetDTM will call this method to run the iterator to the index.

public void
setCurrentPos(int i)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.setCurrentPos.

Set the current position in the node set.

public void
setItem(int node, int index)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.setItem.

Sets the node at the specified index of this vector to be the specified node.

public final void
setIter(DTMIterator
The iterator that is to be contained.
iter
)

Set the functional iterator that fetches nodes.

protected void
setObject(Object obj)

Overrides com.sun.org.apache.xpath.internal.objects.XObject.setObject.

It used to be that many locations in the code simply did an assignment to this.m_obj directly, rather than calling the setObject(Object) method.

public void
setRoot(int nodeHandle, Object environment)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.setRoot.

Reset the root node of the DTMIterator, overriding the value specified when it was created.

public void
setShouldCacheNodes(boolean b)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.setShouldCacheNodes.

If setShouldCacheNodes(true) is called, then nodes will be cached, enabling random access, and giving the ability to do sorts and the like.

protected void
SetVector(NodeVector v)

Set the vector where nodes will be cached.

Inherited from com.sun.org.apache.xpath.internal.objects.XObject:
appendToFsbboolboolWithSideEffectscallVisitorscastToTypecreatecreatedeepEqualsdestructdispatchCharactersEventsequalserrorerrorexecutegetFreshgetTypegetTypeStringgreaterThangreaterThanOrEqualiterlessThanlessThanOrEqualmutableNodesetnodelistnodesetnotEqualsnumnumWithSideEffectsobjectrtfrtfrtreertreestrtoStringxstr

Field Detail

m_cacheback to summary
private NodeSequence.IteratorCache m_cache

A cache of a list of nodes obtained from the iterator so far. This list is appended to until the iterator is exhausted and the cache is complete.

Multiple NodeSequence objects may share the same cache.

Annotations
@SuppressWarnings:serial
m_dtmMgrback to summary
protected DTMManager m_dtmMgr

The DTMManager to use if we're using a NodeVector only. We may well want to do away with this, and store it in the NodeVector.

Annotations
@SuppressWarnings:serial
m_iterback to summary
protected DTMIterator m_iter

The functional iterator that fetches nodes.

Annotations
@SuppressWarnings:serial
m_lastback to summary
protected int m_last

The index of the last node in the iteration.

m_nextback to summary
protected int m_next

The index of the next node to be fetched. Useful if this is a cached iterator, and is being used as random access NodeList.

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides com.sun.org.apache.xpath.internal.objects.XObject.serialVersionUID.

Constructor Detail

NodeSequenceback to summary
private NodeSequence(DTMIterator iter, int context, XPathContext xctxt, boolean shouldCacheNodes)

Create a new NodeSequence from a (already cloned) iterator.

Parameters
iter:DTMIterator

Cloned (not static) DTMIterator.

context:int

The initial context node.

xctxt:XPathContext

The execution context.

shouldCacheNodes:boolean

True if this sequence can random access.

NodeSequenceback to summary
public NodeSequence(Object nodeVector)

Create a new NodeSequence from a (already cloned) iterator.

NodeSequenceback to summary
private NodeSequence(DTMManager dtmMgr)

Construct an empty XNodeSet object. This is used to create a mutable nodeset to which random nodes may be added.

NodeSequenceback to summary
public NodeSequence()

Create a new NodeSequence in an invalid (null) state.

Method Detail

addNodeInDocOrderback to summary
protected int addNodeInDocOrder(int node)

Add the node into a vector of nodes where it should occur in document order.

Parameters
node:int

The node to be added.

Returns:int

insertIndex.

Exceptions
RuntimeException:
thrown if this NodeSetDTM is not of a mutable type.
allowDetachToReleaseback to summary
public void allowDetachToRelease(boolean allowRelease)

Overrides com.sun.org.apache.xpath.internal.objects.XObject.allowDetachToRelease.

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.allowDetachToRelease.

Calling this with a value of false will cause the nodeset to be cached.

See Also
DTMIterator#allowDetachToRelease(boolean)
cacheCompleteback to summary
private boolean cacheComplete()

If this NodeSequence has a cache, and that cache is fully populated then this method returns true, otherwise if there is no cache or it is not complete it returns false.

cloneback to summary
public Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.clone.

Get a clone of this iterator, but don't reset the iteration in the process, so that it may be used from the current position.

Note

Not a deep clone.

Returns:Object

A clone of this object.

Exceptions
CloneNotSupportedException:

Doc from java.lang.Object.clone.

if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.

cloneWithResetback to summary
public DTMIterator cloneWithReset() throws CloneNotSupportedException

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.cloneWithReset.

Note

Not a deep clone.

See Also
DTMIterator#cloneWithReset()
detachback to summary
public void detach()

Overrides com.sun.org.apache.xpath.internal.objects.XObject.detach.

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.detach.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.detach.

Detaches the DTMIterator from the set which it iterated over, releasing any computational resources and placing the iterator in the INVALID state. After detach has been invoked, calls to nextNode or previousNode will raise a runtime exception.

See Also
DTMIterator#detach()
fixupVariablesback to summary
public void fixupVariables(List<QName> vars, int globalsSize)

Overrides com.sun.org.apache.xpath.internal.objects.XObject.fixupVariables.

Doc from com.sun.org.apache.xpath.internal.objects.XObject.fixupVariables.

XObjects should not normally need to fix up variables.

See Also
org.apache.xpath.Expression#fixupVariables(Vector, int)
getAnalysisBitsback to summary
public int getAnalysisBits()

Implements com.sun.org.apache.xpath.internal.axes.PathComponent.getAnalysisBits.

Doc from com.sun.org.apache.xpath.internal.axes.PathComponent.getAnalysisBits.

Get the analysis bits for this path component, as defined in the WalkerFactory.

See Also
PathComponent#getAnalysisBits()
getAxisback to summary
public int getAxis()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getAxis.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.getAxis.

Returns the axis being iterated, if it is known.

See Also
DTMIterator#getAxis()
getCacheback to summary
private NodeSequence.IteratorCache getCache()

Get the cache (if any) of nodes obtained from the iterator so far. Note that the cache keeps growing until the iterator is walked to exhaustion, at which point the cache is "complete".

getContainedIterback to summary
public final DTMIterator getContainedIter()

Get the functional iterator that fetches nodes.

Returns:DTMIterator

The contained iterator.

getCurrentNodeback to summary
public int getCurrentNode()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getCurrentNode.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.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).

See Also
DTMIterator#getCurrentNode()
getCurrentPosback to summary
public int getCurrentPos()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getCurrentPos.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.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.

See Also
DTMIterator#getCurrentPos()
getDTMback to summary
public DTM getDTM(int nodeHandle)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getDTM.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.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.

See Also
DTMIterator#getDTM(int)
getDTMManagerback to summary
public DTMManager getDTMManager()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getDTMManager.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.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.

See Also
DTMIterator#getDTMManager()
getExpandEntityReferencesback to summary
public boolean getExpandEntityReferences()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getExpandEntityReferences.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.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 over whatToShow and 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 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.

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.

See Also
DTMIterator#getExpandEntityReferences()
getIteratorCacheback to summary
protected NodeSequence.IteratorCache getIteratorCache()

Get the cached list of nodes appended with values obtained from the iterator as a NodeSequence is walked when its nextNode() method is called.

getLengthback to summary
public int getLength()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getLength.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.getLength.

The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive. Note that this requires running the iterator to completion, and presumably filling the cache.

See Also
DTMIterator#getLength()
getRootback to summary
public int getRoot()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getRoot.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.getRoot.

The root node of the DTMIterator, 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.

See Also
DTMIterator#getRoot()
getVectorback to summary
protected NodeVector getVector()

If this iterator needs to cache nodes that are fetched, they are stored in the Vector in the generic object.

getWhatToShowback to summary
public int getWhatToShow()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.getWhatToShow.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.getWhatToShow.

This attribute determines which node types are presented via the iterator. The available set of constants is defined above. Nodes not accepted by whatToShow will be skipped, but their children may still be considered.

See Also
DTMIterator#getWhatToShow()
hasCacheback to summary
public boolean hasCache()

If the iterator needs to cache nodes as they are fetched, then this method returns true.

isDocOrderedback to summary
public boolean isDocOrdered()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.isDocOrdered.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.isDocOrdered.

Returns true if all the nodes in the iteration well be returned in document order.

See Also
DTMIterator#isDocOrdered()
isFreshback to summary
public boolean isFresh()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.isFresh.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.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.

See Also
DTMIterator#isFresh()
isMutableback to summary
public boolean isMutable()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.isMutable.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.isMutable.

Tells if this iterator can have nodes added to it or set via the setItem(int node, int index) method.

See Also
DTMIterator#isMutable()
itemback to summary
public int item(int index)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.item.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.item.

Returns the node handle of an item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.

See Also
DTMIterator#item(int)
markCacheCompleteback to summary
private void markCacheComplete()

If this NodeSequence has a cache, mark that it is complete. This method should be called after the iterator is exhausted.

nextNodeback to summary
public int nextNode()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.nextNode.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.nextNode.

Returns the next node in the set and advances the position of the iterator in the set. After a DTMIterator has setRoot called, the first call to nextNode() returns that root or (if it is rejected by the filters) the first node within its subtree which is not filtered out.

See Also
DTMIterator#nextNode()
previousNodeback to summary
public int previousNode()

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.previousNode.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.previousNode.

Returns the previous node in the set and moves the position of the DTMIterator backwards in the set.

See Also
DTMIterator#previousNode()
resetback to summary
public void reset()

Overrides com.sun.org.apache.xpath.internal.objects.XObject.reset.

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.reset.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.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.

See Also
DTMIterator#reset()
runToback to summary
public void runTo(int index)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.runTo.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.runTo.

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.

See Also
DTMIterator#runTo(int)
setCurrentPosback to summary
public void setCurrentPos(int i)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.setCurrentPos.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.setCurrentPos.

Set the current position in the node set.

See Also
DTMIterator#setCurrentPos(int)
setItemback to summary
public void setItem(int node, int index)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.setItem.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.setItem.

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.

See Also
DTMIterator#setItem(int, int)
setIterback to summary
public final void setIter(DTMIterator iter)

Set the functional iterator that fetches nodes.

Parameters
iter:DTMIterator

The iterator that is to be contained.

setObjectback to summary
protected void setObject(Object obj)

Overrides com.sun.org.apache.xpath.internal.objects.XObject.setObject.

It used to be that many locations in the code simply did an assignment to this.m_obj directly, rather than calling the setObject(Object) method. The problem is that our super-class would be updated on what the cache associated with this NodeSequence, but we wouldn't know ourselves.

All setting of m_obj is done through setObject() now, and this method over-rides the super-class method. So now we are in the loop have an opportunity to update some caching information.

setRootback to summary
public void setRoot(int nodeHandle, Object environment)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.setRoot.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.setRoot.

Reset the root node of the DTMIterator, 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.

See Also
DTMIterator#setRoot(int, Object)
setShouldCacheNodesback to summary
public void setShouldCacheNodes(boolean b)

Implements com.sun.org.apache.xml.internal.dtm.DTMIterator.setShouldCacheNodes.

Doc from com.sun.org.apache.xml.internal.dtm.DTMIterator.setShouldCacheNodes.

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?

See Also
DTMIterator#setShouldCacheNodes(boolean)
SetVectorback to summary
protected void SetVector(NodeVector v)

Set the vector where nodes will be cached.

com.sun.org.apache.xpath.internal.axes back to summary

private final Class NodeSequence.IteratorCache

extends Object
Class Inheritance
  • java.lang.Object
  • com.sun.org.apache.xpath.internal.axes.NodeSequence.IteratorCache

Each NodeSequence object has an iterator which is "walked". As an iterator is walked one obtains nodes from it. As those nodes are obtained they may be cached, making the next walking of a copy or clone of the iterator faster. This field (m_cache) is a reference to such a cache, which is populated as the iterator is walked.

Note that multiple NodeSequence objects may hold a reference to the same cache, and also (and this is important) the same iterator. The iterator and its cache may be shared among many NodeSequence objects.

If one of the NodeSequence objects walks ahead of the others it fills in the cache. As the others NodeSequence objects catch up they get their values from the cache rather than the iterator itself, so the iterator is only ever walked once and everyone benefits from the cache.

At some point the cache may be complete due to walking to the end of one of the copies of the iterator, and the cache is then marked as "complete". and the cache will have no more nodes added to it.

Its use-count is the number of NodeSequence objects that use it.

Field Summary

Modifier and TypeField and Description
private boolean
m_isComplete2

true if the associated iterator is exhausted and all nodes obtained from it are in the cache.

private int
private NodeVector
m_vec2

A list of nodes already obtained from the iterator.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private NodeVector
getVector()

Get the cached list of nodes obtained from the iterator so far.

private void
increaseUseCount()

This method is called when yet another NodeSequence object uses, or shares this same cache.

private boolean
isComplete()

Returns true if no cache is complete and immutable.

private void
setCacheComplete(boolean b)

Call this method with 'true' if the iterator is exhausted and the cached list is complete, or no longer growing.

private void
setVector(NodeVector nv)

Sets the NodeVector that holds the growing list of nodes as they are appended to the cached list.

private int
useCount()

Returns count of how many NodeSequence objects share this IteratorCache object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

m_isComplete2back to summary
private boolean m_isComplete2

true if the associated iterator is exhausted and all nodes obtained from it are in the cache.

m_useCount2back to summary
private int m_useCount2
m_vec2back to summary
private NodeVector m_vec2

A list of nodes already obtained from the iterator. As the iterator is walked the nodes obtained from it are appended to this list.

Both an iterator and its corresponding cache can be shared by multiple NodeSequence objects.

For example, consider three NodeSequence objects ns1, ns2 and ns3 doing such sharing, and the nodes to be obtaind from the iterator being the sequence { 33, 11, 44, 22, 55 }.

If ns3.nextNode() is called 3 times the the underlying iterator will have walked through 33, 11, 55 and these three nodes will have been put in the cache.

If ns2.nextNode() is called 2 times it will return 33 and 11 from the cache, leaving the iterator alone.

If ns1.nextNode() is called 6 times it will return 33 and 11 from the cache, then get 44, 22, 55 from the iterator, and appending 44, 22, 55 to the cache. On the sixth call it is found that the iterator is exhausted and the cache is marked complete.

Should ns2 or ns3 have nextNode() called they will know that the cache is complete, and they will obtain all subsequent nodes from the cache.

Note that the underlying iterator, though shared is only ever walked once.

Constructor Detail

IteratorCacheback to summary
pack-priv IteratorCache()

Method Detail

getVectorback to summary
private NodeVector getVector()

Get the cached list of nodes obtained from the iterator so far.

increaseUseCountback to summary
private void increaseUseCount()

This method is called when yet another NodeSequence object uses, or shares this same cache.

isCompleteback to summary
private boolean isComplete()

Returns true if no cache is complete and immutable.

setCacheCompleteback to summary
private void setCacheComplete(boolean b)

Call this method with 'true' if the iterator is exhausted and the cached list is complete, or no longer growing.

setVectorback to summary
private void setVector(NodeVector nv)

Sets the NodeVector that holds the growing list of nodes as they are appended to the cached list.

useCountback to summary
private int useCount()

Returns count of how many NodeSequence objects share this IteratorCache object.