public class NodeSet extends Object implements NodeList, org.w3c.dom.traversal.NodeIterator, Cloneable, ContextNodeList
The NodeSet 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 NodeSet 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 NodeSets 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 int |
m_firstFree
Number of nodes in this NodeVector.
|
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.
|
Constructor and Description |
---|
NodeSet()
Create an empty nodelist.
|
NodeSet(int blocksize)
Create an empty, using the given block size.
|
NodeSet(Node node)
Create a NodeSet which contains the given Node.
|
NodeSet(org.w3c.dom.traversal.NodeIterator ni)
Create a NodeSet, and copy the members of the
given NodeIterator into it.
|
NodeSet(NodeList nodelist)
Create a NodeSet, and copy the members of the
given nodelist into it.
|
NodeSet(NodeSet nodelist)
Create a NodeSet, and copy the members of the
given NodeSet into it.
|
Modifier and Type | Method and Description |
---|---|
void |
addElement(Node value)
Append a Node onto the vector.
|
void |
addNode(Node n)
Add a node to the NodeSet.
|
int |
addNodeInDocOrder(Node node,
boolean test,
XPathContext support)
Add the node into a vector of nodes where it should occur in
document order.
|
int |
addNodeInDocOrder(Node node,
XPathContext support)
Add the node into a vector of nodes where it should occur in
document order.
|
void |
addNodes(org.w3c.dom.traversal.NodeIterator iterator)
Copy NodeList members into this nodelist, adding in
document order.
|
void |
addNodes(NodeList nodelist)
Copy NodeList members into this nodelist, adding in
document order.
|
void |
addNodes(NodeSet ns)
Copy NodeList members into this nodelist, adding in
document order.
|
void |
addNodesInDocOrder(org.w3c.dom.traversal.NodeIterator iterator,
XPathContext support)
Copy NodeList members into this nodelist, adding in
document order.
|
void |
addNodesInDocOrder(NodeList nodelist,
XPathContext support)
Copy NodeList members into this nodelist, adding in
document order.
|
void |
appendNodes(NodeSet nodes)
Append the nodes to the list.
|
Object |
clone()
Get a cloned LocPathIterator.
|
org.w3c.dom.traversal.NodeIterator |
cloneWithReset()
Get a cloned Iterator, and reset its state to the beginning of the
iteration.
|
boolean |
contains(Node 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.
|
Node |
elementAt(int i)
Get the nth element.
|
Node |
getCurrentNode()
Return the last fetched node.
|
int |
getCurrentPos()
Get the current position, which is one less than
the next nextNode() call will retrieve.
|
boolean |
getExpandEntityReferences()
The value of this flag determines whether the children of entity
reference nodes are visible to the iterator.
|
org.w3c.dom.traversal.NodeFilter |
getFilter()
The filter object used to screen nodes.
|
int |
getLast()
Get the index of the last node in this list.
|
int |
getLength()
The number of nodes in the list.
|
Node |
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(Node 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(Node 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(Node value,
int at)
Inserts the specified node in this vector at the specified index.
|
void |
insertNode(Node n,
int pos)
Insert a node at a given position.
|
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 |
peepOrNull()
Return the node at the top of the stack without popping the stack.
|
Node |
peepTail()
Return the node at the tail of the vector without popping
Special purpose method for TransformerImpl, pushElemTemplateElement.
|
Node |
peepTailSub1()
Return the node one position from the tail without popping.
|
Node |
pop()
Pop a node from the tail of the vector and return the result.
|
Node |
popAndTop()
Pop a node from the tail of the vector and return the
top of the stack after the pop.
|
void |
popPair()
Pop a pair of nodes from the tail of the stack.
|
void |
popQuick()
Pop a node from the tail of the vector.
|
Node |
previousNode()
Returns the previous node in the set and moves the position of the
iterator backwards in the set.
|
void |
push(Node value)
Append a Node onto the vector.
|
void |
pushPair(Node v1,
Node v2)
Push a pair of nodes into the stack.
|
void |
removeAllElements()
Inserts the specified node in this vector at the specified index.
|
boolean |
removeElement(Node s)
Removes the first occurrence of the argument from this vector.
|
void |
removeElementAt(int i)
Deletes the component at the specified index.
|
void |
removeNode(Node n)
Remove a node.
|
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 |
setCurrentPos(int i)
Set the current position in the node set.
|
void |
setElementAt(Node node,
int index)
Sets the component at the specified index of this vector to be the
specified object.
|
void |
setLast(int last)
Set the index of the last node in this list.
|
void |
setShouldCacheNodes(boolean b)
If setShouldCacheNodes(true) is called, then nodes will
be cached.
|
void |
setTail(Node n)
Set the tail of the stack to the given node.
|
void |
setTailSub1(Node n)
Set the given node one position from the tail.
|
int |
size()
Get the length of the list.
|
protected transient int m_next
protected transient boolean m_mutable
protected transient boolean m_cacheNodes
protected int m_firstFree
public NodeSet()
public NodeSet(int blocksize)
blocksize
- Size of blocks to allocatepublic NodeSet(NodeList nodelist)
nodelist
- List of Nodes to be made members of the new set.public NodeSet(NodeSet nodelist)
nodelist
- Set of Nodes to be made members of the new set.public NodeSet(org.w3c.dom.traversal.NodeIterator ni)
ni
- Iterator which yields Nodes to be made members of the new set.public NodeSet(Node node)
node
- Single node to be added to the new set.public Node getRoot()
getRoot
in interface org.w3c.dom.traversal.NodeIterator
public org.w3c.dom.traversal.NodeIterator cloneWithReset() throws CloneNotSupportedException
cloneWithReset
in interface ContextNodeList
CloneNotSupportedException
- if this subclass of NodeSet
does not support the clone() operation.public void reset()
reset
in interface ContextNodeList
public int getWhatToShow()
NodeFilter
interface. For NodeSets, the mask has been
hardcoded to show all nodes except EntityReference nodes, which have
no equivalent in the XPath data model.getWhatToShow
in interface org.w3c.dom.traversal.NodeIterator
SHOW_ALL & ~SHOW_ENTITY_REFERENCE
, meaning that
only entity references are suppressed.public org.w3c.dom.traversal.NodeFilter getFilter()
getFilter
in interface org.w3c.dom.traversal.NodeIterator
public boolean getExpandEntityReferences()
getExpandEntityReferences
in interface org.w3c.dom.traversal.NodeIterator
public Node nextNode() throws DOMException
nextNode
in interface org.w3c.dom.traversal.NodeIterator
Node
in the set being iterated over, or
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 Node previousNode() throws DOMException
previousNode
in interface org.w3c.dom.traversal.NodeIterator
Node
in the set being iterated over,
ornull
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 NodeSet 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 NodeSet, and will not cause INVALID_STATE_ERR to be raised by later operations.
detach
in interface org.w3c.dom.traversal.NodeIterator
public boolean isFresh()
isFresh
in interface ContextNodeList
public void runTo(int index)
runTo
in interface ContextNodeList
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 NodeSet is not
one of the types which supports indexing/counting.public Node 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?public int getLength()
length-1
inclusive. Note that this operation requires
finding all the matching nodes, which may defeat attempts to defer
that work.public void addNode(Node n)
n
- Node to be addedRuntimeException
- thrown if this NodeSet is not of
a mutable type.public void insertNode(Node 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 NodeSet is not of
a mutable type.public void removeNode(Node n)
n
- Node to be addedRuntimeException
- thrown if this NodeSet is not of
a mutable type.public void addNodes(NodeList nodelist)
nodelist
- List of nodes which should now be referenced by
this NodeSet.RuntimeException
- thrown if this NodeSet is not of
a mutable type.public void addNodes(NodeSet ns)
Copy NodeList members into this nodelist, adding in document order. Only genuine node references will be copied; nulls appearing in the source NodeSet will not be added to this one.
In case you're wondering why this function is needed: NodeSet implements both NodeIterator and NodeList. If this method isn't provided, Java can't decide which of those to use when addNodes() is invoked. Providing the more-explicit match avoids that ambiguity.)
ns
- NodeSet whose members should be merged into this NodeSet.RuntimeException
- thrown if this NodeSet is not of
a mutable type.public void addNodes(org.w3c.dom.traversal.NodeIterator iterator)
iterator
- NodeIterator which yields the nodes to be added.RuntimeException
- thrown if this NodeSet is not of
a mutable type.public void addNodesInDocOrder(NodeList nodelist, XPathContext support)
nodelist
- List of nodes to be addedsupport
- The XPath runtime context.RuntimeException
- thrown if this NodeSet is not of
a mutable type.public void addNodesInDocOrder(org.w3c.dom.traversal.NodeIterator iterator, XPathContext support)
iterator
- NodeIterator which yields the nodes to be added.support
- The XPath runtime context.RuntimeException
- thrown if this NodeSet is not of
a mutable type.public int addNodeInDocOrder(Node 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 NodeSet is not of
a mutable type.public int addNodeInDocOrder(Node node, XPathContext support)
node
- The node to be added.support
- The XPath runtime context.RuntimeException
- thrown if this NodeSet is not of
a mutable type.public int getCurrentPos()
getCurrentPos
in interface ContextNodeList
public void setCurrentPos(int i)
setCurrentPos
in interface ContextNodeList
i
- Must be a valid index.RuntimeException
- thrown if this NodeSet is not of
a cached type, and thus doesn't permit indexed access.public Node getCurrentNode()
getCurrentNode
in interface ContextNodeList
RuntimeException
- thrown if this NodeSet is not of
a cached type, and thus doesn't permit indexed access.public boolean getShouldCacheNodes()
public void setShouldCacheNodes(boolean b)
setShouldCacheNodes
in interface ContextNodeList
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 int getLast()
ContextNodeList
getLast
in interface ContextNodeList
public void setLast(int last)
ContextNodeList
setLast
in interface ContextNodeList
last
- the index of the last node in this list.public Object clone() throws CloneNotSupportedException
clone
in interface ContextNodeList
clone
in class Object
CloneNotSupportedException
public int size()
size
in interface ContextNodeList
public void addElement(Node value)
value
- Node to add to the vectorpublic final void push(Node value)
value
- Node to add to the vectorpublic final Node pop()
public final Node popAndTop()
public final void popQuick()
public final Node peepOrNull()
public final void pushPair(Node v1, Node v2)
v1
- First node to add to vectorv2
- Second node to add to vectorpublic final void popPair()
public final void setTail(Node n)
n
- Node to set at the tail of vectorpublic final void setTailSub1(Node n)
n
- Node to setpublic final Node peepTail()
public final Node peepTailSub1()
public void insertElementAt(Node value, int at)
value
- Node to insertat
- Position where to insertpublic void appendNodes(NodeSet nodes)
nodes
- NodeVector to append to this listpublic void removeAllElements()
public boolean removeElement(Node s)
s
- Node to remove from the listpublic void removeElementAt(int i)
i
- Index of node to removepublic void setElementAt(Node node, int index)
node
- Node to setindex
- Index of where to set the nodepublic Node elementAt(int i)
i
- Index of node to getpublic boolean contains(Node s)
s
- Node to look forpublic int indexOf(Node elem, int index)
elem
- Node to look forindex
- Index of where to start the searchpublic int indexOf(Node elem)
elem
- Node to look forCopyright © 2017 JBoss by Red Hat. All rights reserved.