org.apache.xpath
public class NodeSetDTM extends NodeVector implements DTMIterator, Cloneable
The NodeSetDTM class can act as either a NodeVector, NodeList, or NodeIterator. However, in order for it to act as a NodeVector or NodeList, it's required that setShouldCacheNodes(true) be called before the first nextNode() is called, in order that nodes can be added as they are fetched. Derived classes that implement iterators must override runTo(int index), in order that they may run the iteration to the given index.
Note that we directly implement the DOM's NodeIterator interface. We do not emulate all the behavior of the standard NodeIterator. In particular, we do not guarantee to present a "live view" of the document ... but in XSLT, the source document should never be mutated, so this should never be an issue.
Thought: Should NodeSetDTM really implement NodeList and NodeIterator, or should there be specific subclasses of it which do so? The advantage of doing it all here is that all NodeSetDTMs will respond to the same calls; the disadvantage is that some of them may return less-than-enlightening results when you do so.
UNKNOWN: advanced
Constructor Summary | |
---|---|
NodeSetDTM(DTMManager dtmManager)
Create an empty nodelist. | |
NodeSetDTM(int blocksize, int dummy, DTMManager dtmManager)
Create an empty, using the given block size.
| |
NodeSetDTM(NodeSetDTM nodelist)
Create a NodeSetDTM, and copy the members of the
given NodeSetDTM into it.
| |
NodeSetDTM(DTMIterator ni)
Create a NodeSetDTM, and copy the members of the
given DTMIterator into it.
| |
NodeSetDTM(NodeIterator iterator, XPathContext xctxt)
Create a NodeSetDTM, and copy the members of the
given DTMIterator into it.
| |
NodeSetDTM(NodeList nodeList, XPathContext xctxt)
Create a NodeSetDTM, and copy the members of the
given DTMIterator into it.
| |
NodeSetDTM(int node, DTMManager dtmManager)
Create a NodeSetDTM which contains the given Node.
|
Method Summary | |
---|---|
void | addElement(int value)
Append a Node onto the vector.
|
void | addNode(int n)
Add a node to the NodeSetDTM. |
int | addNodeInDocOrder(int node, boolean test, XPathContext support)
Add the node into a vector of nodes where it should occur in
document order. |
int | addNodeInDocOrder(int node, XPathContext support)
Add the node into a vector of nodes where it should occur in
document order. |
void | addNodes(DTMIterator iterator)
Copy NodeList members into this nodelist, adding in
document order. |
void | addNodesInDocOrder(DTMIterator iterator, XPathContext support)
Copy NodeList members into this nodelist, adding in
document order. |
void | allowDetachToRelease(boolean allowRelease)
Specify if it's OK for detach to release the iterator for reuse.
|
void | appendNodes(NodeVector nodes)
Append the nodes to the list.
|
Object | clone()
Clone this NodeSetDTM.
|
DTMIterator | cloneWithReset()
Get a cloned Iterator, and reset its state to the beginning of the
iteration.
|
boolean | contains(int s)
Tell if the table contains the given node.
|
void | detach()
Detaches the iterator from the set which it iterated over, releasing
any computational resources and placing the iterator in the INVALID
state. |
int | elementAt(int i)
Get the nth element.
|
int | getAxis()
Returns the axis being iterated, if it is known.
|
int | getCurrentNode()
Return the last fetched node. |
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.
|
DTM | getDTM(int nodeHandle)
Get an instance of a DTM that "owns" a node handle. |
DTMManager | getDTMManager()
Get an instance of the DTMManager. |
boolean | getExpandEntityReferences()
The value of this flag determines whether the children of entity
reference nodes are visible to the iterator. |
DTMFilter | getFilter()
The filter object used to screen nodes. |
int | getLast() |
int | getLength()
The number of nodes in the list. |
int | getRoot() |
boolean | getShouldCacheNodes()
Get whether or not this is a cached node set.
|
int | getWhatToShow()
This attribute determines which node types are presented via the
iterator. |
int | indexOf(int elem, int index)
Searches for the first occurence of the given argument,
beginning the search at index, and testing for equality
using the equals method.
|
int | indexOf(int elem)
Searches for the first occurence of the given argument,
beginning the search at index, and testing for equality
using the equals method.
|
void | insertElementAt(int value, int at)
Inserts the specified node in this vector at the specified index.
|
void | insertNode(int n, int pos)
Insert a node at a given position.
|
boolean | isDocOrdered()
Returns true if all the nodes in the iteration well be returned in document
order.
|
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.
|
boolean | isMutable()
Tells if this iterator can have nodes added to it or set via
the setItem(int node, int index) method.
|
int | item(int index)
Returns the index th item in the collection. |
int | nextNode()
Returns the next node in the set and advances the position of the
iterator in the set. |
int | previousNode()
Returns the previous node in the set and moves the position of the
iterator backwards in the set. |
void | removeAllElements()
Inserts the specified node in this vector at the specified index.
|
boolean | removeElement(int s)
Removes the first occurrence of the argument from this vector.
|
void | removeElementAt(int i)
Deletes the component at the specified index. |
void | removeNode(int n)
Remove a node.
|
void | reset()
Reset the iterator. |
void | runTo(int index)
If an index is requested, NodeSetDTM will call this method
to run the iterator to the index. |
void | setCurrentPos(int i)
Set the current position in the node set. |
void | setElementAt(int node, int index)
Sets the component at the specified index of this vector to be the
specified object. |
void | setEnvironment(Object environment)
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.
|
void | setItem(int node, int index)
Same as setElementAt.
|
void | setLast(int last) |
void | setRoot(int context, Object environment)
Initialize the context values for this expression
after it is cloned.
|
void | setShouldCacheNodes(boolean b)
If setShouldCacheNodes(true) is called, then nodes will
be cached. |
int | size()
Get the length of the list.
|
Parameters: blocksize Size of blocks to allocate dummy pass zero for right now...
Parameters: nodelist Set of Nodes to be made members of the new set.
Parameters: ni Iterator which yields Nodes to be made members of the new set.
Parameters: iterator Iterator which yields Nodes to be made members of the new set.
Parameters: node Single node to be added to the new set.
Parameters: value The node to be added.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: n Node to be added
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: node The node to be added. test true if we should test for doc order support The XPath runtime context.
Returns: insertIndex.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: node The node to be added. support The XPath runtime context.
Returns: The index where it was inserted.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: iterator DTMIterator which yields the nodes to be added.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: iterator DTMIterator which yields the nodes to be added. support The XPath runtime context.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: allowRelease true if it is OK for detach to release this iterator for pooling.
Parameters: nodes The nodes to be appended to this node set.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Returns: a new NodeSetDTM of the same type, having the same state... though unless overridden in the subclasses, it may not copy all the state information.
Throws: CloneNotSupportedException if this subclass of NodeSetDTM does not support the clone() operation.
Returns: a new NodeSetDTM of the same type, having the same state... except that the reset() operation has been called.
Throws: CloneNotSupportedException if this subclass of NodeSetDTM does not support the clone() operation.
Parameters: s Node to look for
Returns: True if the given node was found.
detach
has been invoked, calls to
nextNode
orpreviousNode
will raise the
exception INVALID_STATE_ERR.
This operation is a no-op in NodeSetDTM, and will not cause INVALID_STATE_ERR to be raised by later operations.
Parameters: i The index of the requested node.
Returns: Node at specified index.
Returns: Axis.CHILD, etc., or -1 if the axis is not known or is of multiple types.
Returns: the last fetched node.
Throws: RuntimeException thrown if this NodeSetDTM is not of a cached type, and thus doesn't permit indexed access.
Returns: The the current position index.
Parameters: nodeHandle the nodeHandle.
Returns: a non-null DTM reference.
Returns: a non-null DTMManager reference.
Returns: true for all iterators based on NodeSetDTM, meaning that the contents of EntityRefrence nodes may be returned (though whatToShow says that the EntityReferences themselves are not shown.)
Returns: null, which is slightly misleading. True, there is no user-written filter object, but in fact we are doing some very sophisticated custom filtering. A DOM purist might suggest returning a placeholder object just to indicate that this is not going to return all nodes selected by whatToShow.
length-1
inclusive. Note that this operation requires
finding all the matching nodes, which may defeat attempts to defer
that work.
Returns: integer indicating how many nodes are represented by this list.
Returns: The root node of the Iterator, as specified when it was created. For non-Iterator NodeSetDTMs, this will be null.
Returns: True if this list is cached.
DTMFilter
interface. For NodeSetDTMs, the mask has been
hardcoded to show all nodes except EntityReference nodes, which have
no equivalent in the XPath data model.
Returns: integer used as a bit-array, containing flags defined in
the DOM's DTMFilter class. The value will be
SHOW_ALL & ~SHOW_ENTITY_REFERENCE
, meaning that
only entity references are suppressed.
Parameters: elem Node to look for index Index of where to start the search
Returns: the index of the first occurrence of the object argument in this vector at position index or later in the vector; returns -1 if the object is not found.
Parameters: elem Node to look for
Returns: the index of the first occurrence of the object argument in this vector at position index or later in the vector; returns -1 if the object is not found.
Parameters: value The node to be inserted. at The index where the insert should occur.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: n Node to be added pos Offset at which the node is to be inserted, with 0 being the first position.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Returns: true as a default.
Returns: true if nextNode() would return the first node in the set, false if it would return a later one.
setItem(int node, int index)
method.
Returns: True if the nodelist can be mutated.
index
th item in the collection. If
index
is greater than or equal to the number of nodes in
the list, this returns null
.
TODO: What happens if index is out of range?
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.
Returns: The next Node
in the set being iterated over, or
DTM.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.
Returns: The previous Node
in the set being iterated over,
orDTM.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. RuntimeException thrown if this NodeSetDTM is not of
a cached type, and hence doesn't know what the previous node was.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: s The node to be removed.
Returns: True if the node was successfully removed
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: i The index of the node to be removed.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: n Node to be added
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: index Position to advance (or retreat) to, with 0 requesting the reset ("fresh") position and -1 (or indeed any out-of-bounds value) requesting the final position.
Throws: RuntimeException thrown if this NodeSetDTM is not one of the types which supports indexing/counting.
Parameters: i Must be a valid index.
Throws: RuntimeException thrown if this NodeSetDTM is not of a cached type, and thus doesn't permit indexed access.
Parameters: node The node to be set. index The index of the node to be replaced.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
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.
Parameters: node The node to be set. index The index of the node to be replaced.
Throws: RuntimeException thrown if this NodeSetDTM is not of a mutable type.
Parameters: context The XPath runtime context for this transformation.
Parameters: b true if this node set should be cached.
Throws: RuntimeException thrown if an attempt is made to request caching after we've already begun stepping through the nodes in this set.
Returns: The size of this node set.