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.
Modifier and Type | Field and Description |
---|---|
protected boolean |
m_cacheNodes
True if this list is cached.
|
protected boolean |
m_mutable
True if this list can be mutated.
|
protected int |
m_next
If this node is being used as an iterator, the next index that nextNode()
will return.
|
protected int |
m_root
The root of the iteration, if available.
|
m_firstFree
FILTER_ACCEPT, FILTER_REJECT, FILTER_SKIP
Constructor and Description |
---|
NodeSetDTM(DTMIterator ni)
Create a NodeSetDTM, and copy the members of the
given DTMIterator into it.
|
NodeSetDTM(DTMManager dtmManager)
Create an empty nodelist.
|
NodeSetDTM(int node,
DTMManager dtmManager)
Create a NodeSetDTM which contains the given Node.
|
NodeSetDTM(int blocksize,
int dummy,
DTMManager dtmManager)
Create an empty, using the given block size.
|
NodeSetDTM(org.w3c.dom.traversal.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(NodeSetDTM nodelist)
Create a NodeSetDTM, and copy the members of the
given NodeSetDTM into it.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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()
The root node of the
DTMIterator , as specified when it
was created. |
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)
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,
int index)
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...
|
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.
|
insertInOrder, peepOrNull, peepTail, peepTailSub1, pop, popAndTop, popPair, popQuick, push, pushPair, RemoveAllNoClear, setTail, setTailSub1, sort, sort
protected transient int m_next
protected transient boolean m_mutable
protected transient boolean m_cacheNodes
protected int m_root
public NodeSetDTM(DTMManager dtmManager)
public NodeSetDTM(int blocksize, int dummy, DTMManager dtmManager)
blocksize
- Size of blocks to allocatedummy
- pass zero for right now...public NodeSetDTM(NodeSetDTM nodelist)
nodelist
- Set of Nodes to be made members of the new set.public NodeSetDTM(DTMIterator ni)
ni
- Iterator which yields Nodes to be made members of the new set.public NodeSetDTM(org.w3c.dom.traversal.NodeIterator iterator, XPathContext xctxt)
iterator
- Iterator which yields Nodes to be made members of the new set.public NodeSetDTM(NodeList nodeList, XPathContext xctxt)
public NodeSetDTM(int node, DTMManager dtmManager)
node
- Single node to be added to the new set.public void setEnvironment(Object environment)
At this time the exact implementation of this environment is application dependent. Probably a proper interface will be created fairly soon.
environment
- The environment object.public int getRoot()
DTMIterator
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.getRoot
in interface DTMIterator
public void setRoot(int context, Object environment)
setRoot
in interface DTMIterator
context
- The XPath runtime context for this
transformation.environment
- The environment object.
The environment in which this iterator operates, which should provide:
At this time the exact implementation of this environment is application dependent. Probably a proper interface will be created fairly soon.
public Object clone() throws CloneNotSupportedException
clone
in interface DTMIterator
clone
in class NodeVector
CloneNotSupportedException
- if this subclass of NodeSetDTM
does not support the clone() operation.public DTMIterator cloneWithReset() throws CloneNotSupportedException
cloneWithReset
in interface DTMIterator
CloneNotSupportedException
- if this subclass of NodeSetDTM
does not support the clone() operation.public void reset()
reset
in interface DTMIterator
public int getWhatToShow()
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.getWhatToShow
in interface DTMIterator
SHOW_ALL & ~SHOW_ENTITY_REFERENCE
, meaning that
only entity references are suppressed.public DTMFilter getFilter()
public boolean getExpandEntityReferences()
getExpandEntityReferences
in interface DTMIterator
public DTM getDTM(int nodeHandle)
getDTM
in interface DTMIterator
nodeHandle
- the nodeHandle.public DTMManager getDTMManager()
getDTMManager
in interface DTMIterator
public int nextNode()
nextNode
in interface DTMIterator
Node
in the set being iterated over, or
DTM.NULL
if there are no more members in that set.DOMException
- INVALID_STATE_ERR: Raised if this method is called after the
detach
method was invoked.public int previousNode()
previousNode
in interface DTMIterator
Node
in the set being iterated over,
orDTM.NULL
if there are no more members in that set.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.public void detach()
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.
detach
in interface DTMIterator
public void allowDetachToRelease(boolean allowRelease)
allowDetachToRelease
in interface DTMIterator
allowRelease
- true if it is OK for detach to release this iterator
for pooling.public boolean isFresh()
isFresh
in interface DTMIterator
public void runTo(int index)
runTo
in interface DTMIterator
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.RuntimeException
- thrown if this NodeSetDTM is not
one of the types which supports indexing/counting.public int item(int index)
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?item
in interface DTMIterator
index
- Index into the collection.index
th position in the
NodeList
, or null
if that is not a valid
index.public int getLength()
length-1
inclusive. Note that this operation requires
finding all the matching nodes, which may defeat attempts to defer
that work.getLength
in interface DTMIterator
public void addNode(int n)
n
- Node to be addedRuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public void insertNode(int n, int pos)
n
- Node to be addedpos
- Offset at which the node is to be inserted,
with 0 being the first position.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public void removeNode(int n)
n
- Node to be addedRuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public void addNodes(DTMIterator iterator)
iterator
- DTMIterator which yields the nodes to be added.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public void addNodesInDocOrder(DTMIterator iterator, XPathContext support)
iterator
- DTMIterator which yields the nodes to be added.support
- The XPath runtime context.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public int addNodeInDocOrder(int node, boolean test, XPathContext support)
node
- The node to be added.test
- true if we should test for doc ordersupport
- The XPath runtime context.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public int addNodeInDocOrder(int node, XPathContext support)
node
- The node to be added.support
- The XPath runtime context.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public int size()
size
in class NodeVector
public void addElement(int value)
addElement
in class NodeVector
value
- The node to be added.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public void insertElementAt(int value, int at)
insertElementAt
in class NodeVector
value
- The node to be inserted.at
- The index where the insert should occur.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public void appendNodes(NodeVector nodes)
appendNodes
in class NodeVector
nodes
- The nodes to be appended to this node set.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public void removeAllElements()
removeAllElements
in class NodeVector
RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public boolean removeElement(int s)
removeElement
in class NodeVector
s
- The node to be removed.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public void removeElementAt(int i)
removeElementAt
in class NodeVector
i
- The index of the node to be removed.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public void setElementAt(int node, int index)
setElementAt
in class NodeVector
node
- The node to be set.index
- The index of the node to be replaced.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public void setItem(int node, int index)
setItem
in interface DTMIterator
node
- The node to be set.index
- The index of the node to be replaced.RuntimeException
- thrown if this NodeSetDTM is not of
a mutable type.public int elementAt(int i)
elementAt
in class NodeVector
i
- The index of the requested node.public boolean contains(int s)
contains
in class NodeVector
s
- Node to look forpublic int indexOf(int elem, int index)
indexOf
in class NodeVector
elem
- Node to look forindex
- Index of where to start the searchpublic int indexOf(int elem)
indexOf
in class NodeVector
elem
- Node to look forpublic int getCurrentPos()
getCurrentPos
in interface DTMIterator
public void setCurrentPos(int i)
setCurrentPos
in interface DTMIterator
i
- Must be a valid index.RuntimeException
- thrown if this NodeSetDTM is not of
a cached type, and thus doesn't permit indexed access.public int getCurrentNode()
getCurrentNode
in interface DTMIterator
RuntimeException
- thrown if this NodeSetDTM is not of
a cached type, and thus doesn't permit indexed access.public boolean getShouldCacheNodes()
public void setShouldCacheNodes(boolean b)
setShouldCacheNodes
in interface DTMIterator
b
- true if this node set should be cached.RuntimeException
- thrown if an attempt is made to
request caching after we've already begun stepping through the
nodes in this set.public boolean isMutable()
setItem(int node, int index)
method.isMutable
in interface DTMIterator
public int getLast()
public void setLast(int last)
public boolean isDocOrdered()
isDocOrdered
in interface DTMIterator
public int getAxis()
getAxis
in interface DTMIterator
Copyright © 2021 JBoss by Red Hat. All rights reserved.