| java.lang.Object org.apache.xpath.NodeSet
NodeSet | public class NodeSet implements NodeList,NodeIterator,Cloneable,ContextNodeList(Code) | | 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.
|
Field Summary | |
protected transient boolean | m_cacheNodes True if this list is cached. | protected int | m_firstFree Number of nodes in this NodeVector. | Node | m_map Array of nodes this points to. | protected transient boolean | m_mutable True if this list can be mutated. | protected transient int | m_next If this node is being used as an iterator, the next index that nextNode()
will return. |
Constructor Summary | |
public | NodeSet() Create an empty nodelist. | public | NodeSet(int blocksize) Create an empty, using the given block size. | public | NodeSet(NodeList nodelist) Create a NodeSet, and copy the members of the
given nodelist into it. | public | NodeSet(NodeSet nodelist) Create a NodeSet, and copy the members of the
given NodeSet into it. | public | NodeSet(NodeIterator ni) Create a NodeSet, and copy the members of the
given NodeIterator into it. | public | NodeSet(Node node) Create a NodeSet which contains the given Node. |
Method Summary | |
public void | addElement(Node value) Append a Node onto the vector. | public void | addNode(Node n) Add a node to the NodeSet. | public int | addNodeInDocOrder(Node node, boolean test, XPathContext support) Add the node into a vector of nodes where it should occur in
document order.
Parameters: node - The node to be added. Parameters: test - true if we should test for doc order Parameters: support - The XPath runtime context. | public int | addNodeInDocOrder(Node node, XPathContext support) Add the node into a vector of nodes where it should occur in
document order.
Parameters: node - The node to be added. Parameters: support - The XPath runtime context. | public void | addNodes(NodeList nodelist) Copy NodeList members into this nodelist, adding in
document order. | public void | addNodes(NodeSet ns) Copy NodeList members into this nodelist, adding in
document order. | public void | addNodes(NodeIterator iterator) Copy NodeList members into this nodelist, adding in
document order. | public void | addNodesInDocOrder(NodeList nodelist, XPathContext support) Copy NodeList members into this nodelist, adding in
document order. | public void | addNodesInDocOrder(NodeIterator iterator, XPathContext support) Copy NodeList members into this nodelist, adding in
document order. | public void | appendNodes(NodeSet nodes) Append the nodes to the list. | public Object | clone() Get a cloned LocPathIterator. | public NodeIterator | cloneWithReset() Get a cloned Iterator, and reset its state to the beginning of the
iteration. | public boolean | contains(Node s) Tell if the table contains the given node. | 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. | public Node | elementAt(int i) Get the nth element. | public Node | getCurrentNode() Return the last fetched node. | public int | getCurrentPos() Get the current position, which is one less than
the next nextNode() call will retrieve. | public boolean | getExpandEntityReferences() The value of this flag determines whether the children of entity
reference nodes are visible to the iterator. | public NodeFilter | getFilter() The filter object used to screen nodes. | public int | getLast() | public int | getLength() The number of nodes in the list. | public Node | getRoot() | public boolean | getShouldCacheNodes() Get whether or not this is a cached node set. | public int | getWhatToShow() This attribute determines which node types are presented via the
iterator. | public 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. | public 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. | public void | insertElementAt(Node value, int at) Inserts the specified node in this vector at the specified index. | public void | insertNode(Node n, int pos) Insert a node at a given position. | 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. | public Node | item(int index) Returns the index th item in the collection. | public Node | nextNode() Returns the next node in the set and advances the position of the
iterator in the set. | final public Node | peepOrNull() Return the node at the top of the stack without popping the stack.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
Node at the top of the stack or null if stack is empty. | final public Node | peepTail() Return the node at the tail of the vector without popping
Special purpose method for TransformerImpl, pushElemTemplateElement. | final public Node | peepTailSub1() Return the node one position from the tail without popping. | final public Node | pop() Pop a node from the tail of the vector and return the result. | final public Node | popAndTop() Pop a node from the tail of the vector and return the
top of the stack after the pop. | final public void | popPair() Pop a pair of nodes from the tail of the stack. | final public void | popQuick() Pop a node from the tail of the vector. | public Node | previousNode() Returns the previous node in the set and moves the position of the
iterator backwards in the set. | final public void | push(Node value) Append a Node onto the vector. | final public void | pushPair(Node v1, Node v2) Push a pair of nodes into the stack. | public void | removeAllElements() Inserts the specified node in this vector at the specified index. | public boolean | removeElement(Node s) Removes the first occurrence of the argument from this vector. | public void | removeElementAt(int i) Deletes the component at the specified index. | public void | removeNode(Node n) Remove a node. | public void | reset() Reset the iterator. | public void | runTo(int index) If an index is requested, NodeSet will call this method
to run the iterator to the index. | public void | setCurrentPos(int i) Set the current position in the node set. | public void | setElementAt(Node node, int index) Sets the component at the specified index of this vector to be the
specified object. | public void | setLast(int last) | public void | setShouldCacheNodes(boolean b) If setShouldCacheNodes(true) is called, then nodes will
be cached. | final public void | setTail(Node n) Set the tail of the stack to the given node. | final public void | setTailSub1(Node n) Set the given node one position from the tail. | public int | size() Get the length of the list. |
m_cacheNodes | protected transient boolean m_cacheNodes(Code) | | True if this list is cached.
|
m_firstFree | protected int m_firstFree(Code) | | Number of nodes in this NodeVector.
|
m_map | Node m_map(Code) | | Array of nodes this points to.
|
m_mutable | protected transient boolean m_mutable(Code) | | True if this list can be mutated.
|
m_next | protected transient int m_next(Code) | | If this node is being used as an iterator, the next index that nextNode()
will return.
|
NodeSet | public NodeSet()(Code) | | Create an empty nodelist.
|
NodeSet | public NodeSet(int blocksize)(Code) | | Create an empty, using the given block size.
Parameters: blocksize - Size of blocks to allocate |
NodeSet | public NodeSet(NodeList nodelist)(Code) | | Create a NodeSet, and copy the members of the
given nodelist into it.
Parameters: nodelist - List of Nodes to be made members of the new set. |
NodeSet | public NodeSet(NodeSet nodelist)(Code) | | Create a NodeSet, and copy the members of the
given NodeSet into it.
Parameters: nodelist - Set of Nodes to be made members of the new set. |
NodeSet | public NodeSet(NodeIterator ni)(Code) | | Create a NodeSet, and copy the members of the
given NodeIterator into it.
Parameters: ni - Iterator which yields Nodes to be made members of the new set. |
NodeSet | public NodeSet(Node node)(Code) | | Create a NodeSet which contains the given Node.
Parameters: node - Single node to be added to the new set. |
addElement | public void addElement(Node value)(Code) | | Append a Node onto the vector.
Parameters: value - Node to add to the vector |
addNode | public void addNode(Node n)(Code) | | Add a node to the NodeSet. Not all types of NodeSets support this
operation
Parameters: n - Node to be added throws: RuntimeException - thrown if this NodeSet is not of a mutable type. |
addNodeInDocOrder | public int addNodeInDocOrder(Node node, boolean test, XPathContext support)(Code) | | Add the node into a vector of nodes where it should occur in
document order.
Parameters: node - The node to be added. Parameters: test - true if we should test for doc order Parameters: support - The XPath runtime context. insertIndex. throws: RuntimeException - thrown if this NodeSet is not of a mutable type. |
addNodeInDocOrder | public int addNodeInDocOrder(Node node, XPathContext support)(Code) | | Add the node into a vector of nodes where it should occur in
document order.
Parameters: node - The node to be added. Parameters: support - The XPath runtime context. The index where it was inserted. throws: RuntimeException - thrown if this NodeSet is not of a mutable type. |
addNodes | public void addNodes(NodeList nodelist)(Code) | | Copy NodeList members into this nodelist, adding in
document order. If a node is null, don't add it.
Parameters: nodelist - List of nodes which should now be referenced bythis NodeSet. throws: RuntimeException - thrown if this NodeSet is not of a mutable type. |
addNodes | public void addNodes(NodeSet ns)(Code) | | 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.)
Parameters: ns - NodeSet whose members should be merged into this NodeSet. throws: RuntimeException - thrown if this NodeSet is not of a mutable type. |
addNodes | public void addNodes(NodeIterator iterator)(Code) | | Copy NodeList members into this nodelist, adding in
document order. Null references are not added.
Parameters: iterator - NodeIterator which yields the nodes to be added. throws: RuntimeException - thrown if this NodeSet is not of a mutable type. |
addNodesInDocOrder | public void addNodesInDocOrder(NodeList nodelist, XPathContext support)(Code) | | Copy NodeList members into this nodelist, adding in
document order. If a node is null, don't add it.
Parameters: nodelist - List of nodes to be added Parameters: support - The XPath runtime context. throws: RuntimeException - thrown if this NodeSet is not of a mutable type. |
addNodesInDocOrder | public void addNodesInDocOrder(NodeIterator iterator, XPathContext support)(Code) | | Copy NodeList members into this nodelist, adding in
document order. If a node is null, don't add it.
Parameters: iterator - NodeIterator which yields the nodes to be added. Parameters: support - The XPath runtime context. throws: RuntimeException - thrown if this NodeSet is not of a mutable type. |
appendNodes | public void appendNodes(NodeSet nodes)(Code) | | Append the nodes to the list.
Parameters: nodes - NodeVector to append to this list |
cloneWithReset | public NodeIterator cloneWithReset() throws CloneNotSupportedException(Code) | | Get a cloned Iterator, and reset its state to the beginning of the
iteration.
a new NodeSet of the same type, having the same state...except that the reset() operation has been called. throws: CloneNotSupportedException - if this subclass of NodeSetdoes not support the clone() operation. |
contains | public boolean contains(Node s)(Code) | | Tell if the table contains the given node.
Parameters: s - Node to look for True if the given node was found. |
detach | public void detach()(Code) | | 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.
This operation is a no-op in NodeSet, and will not cause
INVALID_STATE_ERR to be raised by later operations.
|
elementAt | public Node elementAt(int i)(Code) | | Get the nth element.
Parameters: i - Index of node to get Node at specified index |
getCurrentNode | public Node getCurrentNode()(Code) | | Return the last fetched node. Needed to support the UnionPathIterator.
the last fetched node. throws: RuntimeException - thrown if this NodeSet is not of a cached type, and thus doesn't permit indexed access. |
getCurrentPos | public int getCurrentPos()(Code) | | 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.
The the current position index. |
getExpandEntityReferences | public boolean getExpandEntityReferences()(Code) | | 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.
true for all iterators based on NodeSet, meaning that thecontents of EntityRefrence nodes may be returned (though whatToShowsays that the EntityReferences themselves are not shown.) |
getFilter | public NodeFilter getFilter()(Code) | | The filter object used to screen nodes. Filters are applied to
further reduce (and restructure) the NodeIterator's view of the
document. In our case, we will be using hardcoded filters built
into our iterators... but getFilter() is part of the DOM's
NodeIterator interface, so we have to support it.
null, which is slightly misleading. True, there is nouser-written filter object, but in fact we are doing some verysophisticated custom filtering. A DOM purist might suggestreturning a placeholder object just to indicate that this isnot going to return all nodes selected by whatToShow. |
getLast | public int getLast()(Code) | | |
getLength | public int getLength()(Code) | | The number of nodes in the list. The range of valid child node indices is
0 to length-1 inclusive. Note that this operation requires
finding all the matching nodes, which may defeat attempts to defer
that work.
integer indicating how many nodes are represented by this list. |
getRoot | public Node getRoot()(Code) | | The root node of the Iterator, as specified when it was created.For non-Iterator NodeSets, this will be null. |
getShouldCacheNodes | public boolean getShouldCacheNodes()(Code) | | Get whether or not this is a cached node set.
True if this list is cached. |
getWhatToShow | public int getWhatToShow()(Code) | | This attribute determines which node types are presented via the
iterator. The available set of constants is defined in the
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.
integer used as a bit-array, containing flags defined inthe DOM's NodeFilter class. The value will be SHOW_ALL & ~SHOW_ENTITY_REFERENCE , meaning thatonly entity references are suppressed. |
indexOf | public int indexOf(Node elem, int index)(Code) | | Searches for the first occurence of the given argument,
beginning the search at index, and testing for equality
using the equals method.
Parameters: elem - Node to look for Parameters: index - Index of where to start the search the index of the first occurrence of the objectargument in this vector at position index or later in thevector; returns -1 if the object is not found. |
indexOf | public int indexOf(Node elem)(Code) | | Searches for the first occurence of the given argument,
beginning the search at index, and testing for equality
using the equals method.
Parameters: elem - Node to look for the index of the first occurrence of the objectargument in this vector at position index or later in thevector; returns -1 if the object is not found. |
insertElementAt | public void insertElementAt(Node value, int at)(Code) | | Inserts the specified node in this vector at the specified index.
Each component in this vector with an index greater or equal to
the specified index is shifted upward to have an index one greater
than the value it had previously.
Parameters: value - Node to insert Parameters: at - Position where to insert |
insertNode | public void insertNode(Node n, int pos)(Code) | | Insert a node at a given position.
Parameters: n - Node to be added Parameters: pos - Offset at which the node is to be inserted,with 0 being the first position. throws: RuntimeException - thrown if this NodeSet is not of a mutable type. |
isFresh | public boolean isFresh()(Code) | | Tells if this NodeSet is "fresh", in other words, if
the first nextNode() that is called will return the
first node in the set.
true if nextNode() would return the first node in the set,false if it would return a later one. |
item | public Node item(int index)(Code) | | 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 .
TODO: What happens if index is out of range?
Parameters: index - Index into the collection. The node at the index th position in theNodeList , or null if that is not a validindex. |
nextNode | public Node nextNode() throws DOMException(Code) | | 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.
The next 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 thedetach method was invoked. |
peepOrNull | final public Node peepOrNull()(Code) | | Return the node at the top of the stack without popping the stack.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
Node at the top of the stack or null if stack is empty. |
peepTail | final public Node peepTail()(Code) | | Return the node at the tail of the vector without popping
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
Node at the tail of the vector |
peepTailSub1 | final public Node peepTailSub1()(Code) | | Return the node one position from the tail without popping.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
Node one away from the tail |
pop | final public Node pop()(Code) | | Pop a node from the tail of the vector and return the result.
the node at the tail of the vector |
popAndTop | final public Node popAndTop()(Code) | | Pop a node from the tail of the vector and return the
top of the stack after the pop.
The top of the stack after it's been popped |
popPair | final public void popPair()(Code) | | Pop a pair of nodes from the tail of the stack.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
|
popQuick | final public void popQuick()(Code) | | Pop a node from the tail of the vector.
|
previousNode | public Node previousNode() throws DOMException(Code) | | Returns the previous node in the set and moves the position of the
iterator backwards in the set.
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 thedetach method was invoked. throws: RuntimeException - thrown if this NodeSet is not of a cached type, and hence doesn't know what the previous node was. |
push | final public void push(Node value)(Code) | | Append a Node onto the vector.
Parameters: value - Node to add to the vector |
pushPair | final public void pushPair(Node v1, Node v2)(Code) | | Push a pair of nodes into the stack.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
Parameters: v1 - First node to add to vector Parameters: v2 - Second node to add to vector |
removeAllElements | public void removeAllElements()(Code) | | Inserts the specified node in this vector at the specified index.
Each component in this vector with an index greater or equal to
the specified index is shifted upward to have an index one greater
than the value it had previously.
|
removeElement | public boolean removeElement(Node s)(Code) | | Removes the first occurrence of the argument from this vector.
If the object is found in this vector, each component in the vector
with an index greater or equal to the object's index is shifted
downward to have an index one smaller than the value it had
previously.
Parameters: s - Node to remove from the list True if the node was successfully removed |
removeElementAt | public void removeElementAt(int i)(Code) | | Deletes the component at the specified index. Each component in
this vector with an index greater or equal to the specified
index is shifted downward to have an index one smaller than
the value it had previously.
Parameters: i - Index of node to remove |
removeNode | public void removeNode(Node n)(Code) | | Remove a node.
Parameters: n - Node to be added throws: RuntimeException - thrown if this NodeSet is not of a mutable type. |
reset | public void reset()(Code) | | Reset the iterator. May have no effect on non-iterator Nodesets.
|
runTo | public void runTo(int index)(Code) | | 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.
Parameters: index - Position to advance (or retreat) to, with0 requesting the reset ("fresh") position and -1 (or indeedany out-of-bounds value) requesting the final position. throws: RuntimeException - thrown if this NodeSet is notone of the types which supports indexing/counting. |
setCurrentPos | public void setCurrentPos(int i)(Code) | | Set the current position in the node set.
Parameters: i - Must be a valid index. throws: RuntimeException - thrown if this NodeSet is not of a cached type, and thus doesn't permit indexed access. |
setElementAt | public void setElementAt(Node node, int index)(Code) | | Sets the component at the specified index of this vector to be the
specified object. 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.
Parameters: node - Node to set Parameters: index - Index of where to set the node |
setLast | public void setLast(int last)(Code) | | |
setShouldCacheNodes | public void setShouldCacheNodes(boolean b)(Code) | | If setShouldCacheNodes(true) is called, then nodes will
be cached. They are not cached by default. This switch must
be set before the first call to nextNode is made, to ensure
that all nodes are cached.
Parameters: b - true if this node set should be cached. throws: RuntimeException - thrown if an attempt is made torequest caching after we've already begun stepping through thenodes in this set. |
setTail | final public void setTail(Node n)(Code) | | Set the tail of the stack to the given node.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
Parameters: n - Node to set at the tail of vector |
setTailSub1 | final public void setTailSub1(Node n)(Code) | | Set the given node one position from the tail.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
Parameters: n - Node to set |
size | public int size()(Code) | | Get the length of the list.
Number of nodes in this NodeVector |
|
|