|
|||||||||
| Home >> All >> org >> apache >> [ xpath overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.xpath
Class NodeSet

java.lang.Objectorg.apache.xpath.NodeSet
- All Implemented Interfaces:
- java.lang.Cloneable, org.apache.xpath.axes.ContextNodeList, org.w3c.dom.traversal.NodeIterator, org.w3c.dom.NodeList
- public class NodeSet
- extends java.lang.Object
- implements org.w3c.dom.NodeList, org.w3c.dom.traversal.NodeIterator, java.lang.Cloneable, org.apache.xpath.axes.ContextNodeList
- extends java.lang.Object
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 | |
private int |
m_blocksize
Size of blocks to allocate. |
protected boolean |
m_cacheNodes
True if this list is cached. |
protected int |
m_firstFree
Number of nodes in this NodeVector. |
private int |
m_last
|
(package private) org.w3c.dom.Node[] |
m_map
Array of nodes this points to. |
private int |
m_mapSize
Size of the array this points to. |
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 Summary | |
NodeSet()
Create an empty nodelist. |
|
NodeSet(int blocksize)
Create an empty, using the given block size. |
|
NodeSet(org.w3c.dom.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(org.w3c.dom.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. |
|
| Method Summary | |
void |
addElement(org.w3c.dom.Node value)
Append a Node onto the vector. |
void |
addNode(org.w3c.dom.Node n)
Add a node to the NodeSet. |
int |
addNodeInDocOrder(org.w3c.dom.Node node,
boolean test,
XPathContext support)
Add the node into a vector of nodes where it should occur in document order. |
int |
addNodeInDocOrder(org.w3c.dom.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(org.w3c.dom.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. |
private boolean |
addNodesInDocOrder(int start,
int end,
int testIndex,
org.w3c.dom.NodeList nodelist,
XPathContext support)
Add the node list to this node set 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(org.w3c.dom.NodeList nodelist,
XPathContext support)
Copy NodeList members into this nodelist, adding in document order. |
void |
appendNodes(NodeSet nodes)
Append the nodes to the list. |
java.lang.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(org.w3c.dom.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. |
org.w3c.dom.Node |
elementAt(int i)
Get the nth element. |
org.w3c.dom.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. |
org.w3c.dom.Node |
getRoot()
The root node of the NodeIterator, 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(org.w3c.dom.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(org.w3c.dom.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(org.w3c.dom.Node value,
int at)
Inserts the specified node in this vector at the specified index. |
void |
insertNode(org.w3c.dom.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. |
org.w3c.dom.Node |
item(int index)
Returns the indexth item in the collection. |
org.w3c.dom.Node |
nextNode()
Returns the next node in the set and advances the position of the iterator in the set. |
org.w3c.dom.Node |
peepOrNull()
Return the node at the top of the stack without popping the stack. |
org.w3c.dom.Node |
peepTail()
Return the node at the tail of the vector without popping Special purpose method for TransformerImpl, pushElemTemplateElement. |
org.w3c.dom.Node |
peepTailSub1()
Return the node one position from the tail without popping. |
org.w3c.dom.Node |
pop()
Pop a node from the tail of the vector and return the result. |
org.w3c.dom.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. |
org.w3c.dom.Node |
previousNode()
Returns the previous node in the set and moves the position of the iterator backwards in the set. |
void |
push(org.w3c.dom.Node value)
Append a Node onto the vector. |
void |
pushPair(org.w3c.dom.Node v1,
org.w3c.dom.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(org.w3c.dom.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(org.w3c.dom.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(org.w3c.dom.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(org.w3c.dom.Node n)
Set the tail of the stack to the given node. |
void |
setTailSub1(org.w3c.dom.Node n)
Set the given node one position from the tail. |
int |
size()
Get the length of the list. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
m_next
protected transient int m_next
- If this node is being used as an iterator, the next index that nextNode()
will return.
m_mutable
protected transient boolean m_mutable
- True if this list can be mutated.
m_cacheNodes
protected transient boolean m_cacheNodes
- True if this list is cached.
m_last
private transient int m_last
m_blocksize
private int m_blocksize
- Size of blocks to allocate.
m_map
org.w3c.dom.Node[] m_map
- Array of nodes this points to.
m_firstFree
protected int m_firstFree
- Number of nodes in this NodeVector.
m_mapSize
private int m_mapSize
- Size of the array this points to.
| Constructor Detail |
NodeSet
public NodeSet()
- Create an empty nodelist.
NodeSet
public NodeSet(int blocksize)
- Create an empty, using the given block size.
NodeSet
public NodeSet(org.w3c.dom.NodeList nodelist)
- Create a NodeSet, and copy the members of the
given nodelist into it.
NodeSet
public NodeSet(NodeSet nodelist)
- Create a NodeSet, and copy the members of the
given NodeSet into it.
NodeSet
public NodeSet(org.w3c.dom.traversal.NodeIterator ni)
- Create a NodeSet, and copy the members of the
given NodeIterator into it.
NodeSet
public NodeSet(org.w3c.dom.Node node)
- Create a NodeSet which contains the given Node.
| Method Detail |
getRoot
public org.w3c.dom.Node getRoot()
- Description copied from interface:
org.w3c.dom.traversal.NodeIterator - The root node of the
NodeIterator, as specified when it was created.- Specified by:
getRootin interfaceorg.w3c.dom.traversal.NodeIterator
cloneWithReset
public org.w3c.dom.traversal.NodeIterator cloneWithReset() throws java.lang.CloneNotSupportedException
- Get a cloned Iterator, and reset its state to the beginning of the
iteration.
- Specified by:
cloneWithResetin interfaceorg.apache.xpath.axes.ContextNodeList
reset
public void reset()
- Reset the iterator. May have no effect on non-iterator Nodesets.
- Specified by:
resetin interfaceorg.apache.xpath.axes.ContextNodeList
getWhatToShow
public int getWhatToShow()
- This attribute determines which node types are presented via the
iterator. The available set of constants is defined in the
NodeFilterinterface. For NodeSets, the mask has been hardcoded to show all nodes except EntityReference nodes, which have no equivalent in the XPath data model.- Specified by:
getWhatToShowin interfaceorg.w3c.dom.traversal.NodeIterator
getFilter
public org.w3c.dom.traversal.NodeFilter getFilter()
- 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.
- Specified by:
getFilterin interfaceorg.w3c.dom.traversal.NodeIterator
getExpandEntityReferences
public boolean getExpandEntityReferences()
- 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.- Specified by:
getExpandEntityReferencesin interfaceorg.w3c.dom.traversal.NodeIterator
nextNode
public org.w3c.dom.Node nextNode() throws org.w3c.dom.DOMException
- 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.
- Specified by:
nextNodein interfaceorg.w3c.dom.traversal.NodeIterator
previousNode
public org.w3c.dom.Node previousNode() throws org.w3c.dom.DOMException
- Returns the previous node in the set and moves the position of the
iterator backwards in the set.
- Specified by:
previousNodein interfaceorg.w3c.dom.traversal.NodeIterator
detach
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. After
detachhas been invoked, calls tonextNodeorpreviousNodewill 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.
- Specified by:
detachin interfaceorg.w3c.dom.traversal.NodeIterator
isFresh
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.
- Specified by:
isFreshin interfaceorg.apache.xpath.axes.ContextNodeList
runTo
public void runTo(int index)
- 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.
- Specified by:
runToin interfaceorg.apache.xpath.axes.ContextNodeList
item
public org.w3c.dom.Node item(int index)
- Returns the
indexth item in the collection. Ifindexis greater than or equal to the number of nodes in the list, this returnsnull. TODO: What happens if index is out of range?- Specified by:
itemin interfaceorg.w3c.dom.NodeList
getLength
public int getLength()
- The number of nodes in the list. The range of valid child node indices is
0 to
length-1inclusive. Note that this operation requires finding all the matching nodes, which may defeat attempts to defer that work.- Specified by:
getLengthin interfaceorg.w3c.dom.NodeList
addNode
public void addNode(org.w3c.dom.Node n)
- Add a node to the NodeSet. Not all types of NodeSets support this
operation
insertNode
public void insertNode(org.w3c.dom.Node n, int pos)
- Insert a node at a given position.
removeNode
public void removeNode(org.w3c.dom.Node n)
- Remove a node.
addNodes
public void addNodes(org.w3c.dom.NodeList nodelist)
- Copy NodeList members into this nodelist, adding in
document order. If a node is null, don't add it.
addNodes
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.)
addNodes
public void addNodes(org.w3c.dom.traversal.NodeIterator iterator)
- Copy NodeList members into this nodelist, adding in
document order. Null references are not added.
addNodesInDocOrder
public void addNodesInDocOrder(org.w3c.dom.NodeList nodelist, XPathContext support)
- Copy NodeList members into this nodelist, adding in
document order. If a node is null, don't add it.
addNodesInDocOrder
public void addNodesInDocOrder(org.w3c.dom.traversal.NodeIterator iterator, XPathContext support)
- Copy NodeList members into this nodelist, adding in
document order. If a node is null, don't add it.
addNodesInDocOrder
private boolean addNodesInDocOrder(int start,
int end,
int testIndex,
org.w3c.dom.NodeList nodelist,
XPathContext support)
- Add the node list to this node set in document order.
addNodeInDocOrder
public int addNodeInDocOrder(org.w3c.dom.Node node, boolean test, XPathContext support)
- Add the node into a vector of nodes where it should occur in
document order.
addNodeInDocOrder
public int addNodeInDocOrder(org.w3c.dom.Node node, XPathContext support)
- Add the node into a vector of nodes where it should occur in
document order.
getCurrentPos
public 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.
- Specified by:
getCurrentPosin interfaceorg.apache.xpath.axes.ContextNodeList
setCurrentPos
public void setCurrentPos(int i)
- Set the current position in the node set.
- Specified by:
setCurrentPosin interfaceorg.apache.xpath.axes.ContextNodeList
getCurrentNode
public org.w3c.dom.Node getCurrentNode()
- Return the last fetched node. Needed to support the UnionPathIterator.
- Specified by:
getCurrentNodein interfaceorg.apache.xpath.axes.ContextNodeList
getShouldCacheNodes
public boolean getShouldCacheNodes()
- Get whether or not this is a cached node set.
setShouldCacheNodes
public void setShouldCacheNodes(boolean b)
- 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.
- Specified by:
setShouldCacheNodesin interfaceorg.apache.xpath.axes.ContextNodeList
getLast
public int getLast()
- Description copied from interface:
org.apache.xpath.axes.ContextNodeList - Get the index of the last node in this list.
- Specified by:
getLastin interfaceorg.apache.xpath.axes.ContextNodeList
setLast
public void setLast(int last)
- Description copied from interface:
org.apache.xpath.axes.ContextNodeList - Set the index of the last node in this list.
- Specified by:
setLastin interfaceorg.apache.xpath.axes.ContextNodeList
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Get a cloned LocPathIterator.
- Specified by:
clonein interfaceorg.apache.xpath.axes.ContextNodeList
size
public int size()
- Get the length of the list.
- Specified by:
sizein interfaceorg.apache.xpath.axes.ContextNodeList
addElement
public void addElement(org.w3c.dom.Node value)
- Append a Node onto the vector.
push
public final void push(org.w3c.dom.Node value)
- Append a Node onto the vector.
pop
public final org.w3c.dom.Node pop()
- Pop a node from the tail of the vector and return the result.
popAndTop
public final org.w3c.dom.Node popAndTop()
- Pop a node from the tail of the vector and return the
top of the stack after the pop.
popQuick
public final void popQuick()
- Pop a node from the tail of the vector.
peepOrNull
public final org.w3c.dom.Node peepOrNull()
- Return the node at the top of the stack without popping the stack.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
pushPair
public final void pushPair(org.w3c.dom.Node v1, org.w3c.dom.Node v2)
- Push a pair of nodes into the stack.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
popPair
public final void popPair()
- Pop a pair of nodes from the tail of the stack.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
setTail
public final void setTail(org.w3c.dom.Node n)
- Set the tail of the stack to the given node.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
setTailSub1
public final void setTailSub1(org.w3c.dom.Node n)
- Set the given node one position from the tail.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
peepTail
public final org.w3c.dom.Node peepTail()
- Return the node at the tail of the vector without popping
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
peepTailSub1
public final org.w3c.dom.Node peepTailSub1()
- Return the node one position from the tail without popping.
Special purpose method for TransformerImpl, pushElemTemplateElement.
Performance critical.
insertElementAt
public void insertElementAt(org.w3c.dom.Node value, int at)
- 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.
appendNodes
public void appendNodes(NodeSet nodes)
- Append the nodes to the list.
removeAllElements
public void removeAllElements()
- 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(org.w3c.dom.Node s)
- 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.
removeElementAt
public void removeElementAt(int i)
- 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.
setElementAt
public void setElementAt(org.w3c.dom.Node node, int index)
- 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.
elementAt
public org.w3c.dom.Node elementAt(int i)
- Get the nth element.
contains
public boolean contains(org.w3c.dom.Node s)
- Tell if the table contains the given node.
indexOf
public int indexOf(org.w3c.dom.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.
indexOf
public int indexOf(org.w3c.dom.Node elem)
- Searches for the first occurence of the given argument,
beginning the search at index, and testing for equality
using the equals method.
|
|||||||||
| Home >> All >> org >> apache >> [ xpath overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.xpath.NodeSet