org.exist.dom
Class VirtualNodeSet

java.lang.Object
  extended byorg.exist.xquery.value.AbstractSequence
      extended byorg.exist.dom.AbstractNodeSet
          extended byorg.exist.dom.VirtualNodeSet
All Implemented Interfaces:
org.w3c.dom.NodeList, NodeSet, Sequence

public class VirtualNodeSet
extends AbstractNodeSet

This node set is called virtual because it is just a placeholder for the set of relevant nodes. For XPath expressions like //* or //node(), it would be totally unefficient to actually retrieve all descendant nodes. In many cases, the expression can be resolved at a later point in time without retrieving the whole node set. VirtualNodeSet basically provides method getFirstParent to retrieve the first matching descendant of its context according to the primary type axis. Class LocationStep will always return an instance of VirtualNodeSet if it finds something like descendant::* etc..

Author:
Wolfgang Meier, Timo Boehme

Field Summary
protected  int axis
           
protected  NodeSet context
           
protected  int contextId
           
protected  boolean inPredicate
           
protected  NodeSet realSet
           
protected  boolean realSetIsComplete
           
protected  NodeTest test
           
protected  boolean useSelfAsContext
           
 
Fields inherited from class org.exist.dom.AbstractNodeSet
hasMixedContent, hasTextIndex, indexType, LOG
 
Fields inherited from interface org.exist.dom.NodeSet
ANCESTOR, DESCENDANT, EMPTY_SET, FOLLOWING, PRECEDING
 
Fields inherited from interface org.exist.xquery.value.Sequence
EMPTY_SEQUENCE
 
Constructor Summary
VirtualNodeSet(int axis, NodeTest test, int contextId, NodeSet context)
           
 
Method Summary
 void add(DocumentImpl doc, long nodeId)
           
 void add(org.w3c.dom.Node node)
           
 void add(NodeProxy proxy)
          Add a new proxy object to the node set.
 void addAll(org.w3c.dom.NodeList other)
           
 void addAll(NodeSet other)
          Add all nodes from the given node set.
 void clearContext()
           
 boolean contains(DocumentImpl doc, long nodeId)
           
 boolean contains(NodeProxy p)
          Check if this node set contains a node matching the document and node-id of the given NodeProxy object.
 NodeProxy get(DocumentImpl doc, long gid)
          Get a node from this node set matching the document and node id.
 NodeProxy get(int pos)
          Get the node at position pos within this node set.
 NodeProxy get(NodeProxy proxy)
          Get a node from this node set matching the document and node id of the given NodeProxy.
 DocumentSet getDocumentSet()
          Returns the set of documents from which the node items in this sequence have been selected.
 int getLength()
          Return the number of nodes contained in this node set.
 boolean hasIndex()
           
 NodeSet intersection(NodeSet other)
          Return a new node set, which represents the intersection of the current node set with the given node set.
 org.w3c.dom.Node item(int pos)
           
 Item itemAt(int pos)
          Returns the item located at the specified position within this sequence.
 SequenceIterator iterate()
          Returns an iterator over all items in the sequence.
 NodeSetIterator iterator()
          Return an iterator on the nodes in this list.
 NodeProxy nodeHasParent(DocumentImpl doc, long gid, boolean directParent, boolean includeSelf)
           
 NodeProxy nodeHasParent(NodeProxy node, boolean directParent, boolean includeSelf)
           
 NodeProxy parentWithChild(DocumentImpl doc, long gid, boolean directParent, boolean includeSelf, int level)
          Check if the node identified by its node id has an ancestor contained in this node set and return the ancestor found.
 NodeProxy parentWithChild(NodeProxy proxy, boolean directParent, boolean includeSelf, int level)
          Check if the given node has an ancestor contained in this node set and return the ancestor found.
 void realize()
           
 void remove(NodeProxy node)
          Remove a node.
 void set(int position, DocumentImpl doc, long nodeId)
           
 void setContextId(int contextId)
           
 void setInPredicate(boolean predicate)
           
 void setNodeTest(NodeTest test)
           
 void setSelfIsContext()
           
 java.lang.String toString()
           
 NodeSet union(NodeSet other)
          Return a new node set which represents the union of the current node set and the given node set.
 SequenceIterator unorderedIterator()
          Returns an iterator over all items in the sequence.
 
Methods inherited from class org.exist.dom.AbstractNodeSet
add, add, addAll, clearContext, containsDoc, deepIntersection, directSelectAttribute, except, getAncestors, getContextNodes, getIndexType, getItemType, getParents, getRange, getSizeHint, getState, hasChanged, hasChildrenInSet, hasMixedContent, hasTextIndex, isCached, isPersistentSet, parentWithChild, parentWithChild, removeDuplicates, selectAncestorDescendant, selectAncestors, selectFollowing, selectFollowingSiblings, selectParentChild, selectParentChild, selectPreceding, selectPrecedingSiblings, setIsCached, toNodeSet
 
Methods inherited from class org.exist.xquery.value.AbstractSequence
conversionPreference, convertTo, effectiveBooleanValue, getCardinality, getStringValue, setSelfAsContext, toJavaObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.exist.xquery.value.Sequence
conversionPreference, convertTo, effectiveBooleanValue, getCardinality, getStringValue, setSelfAsContext, toJavaObject
 

Field Detail

axis

protected int axis

test

protected NodeTest test

context

protected NodeSet context

realSet

protected NodeSet realSet

realSetIsComplete

protected boolean realSetIsComplete

inPredicate

protected boolean inPredicate

useSelfAsContext

protected boolean useSelfAsContext

contextId

protected int contextId
Constructor Detail

VirtualNodeSet

public VirtualNodeSet(int axis,
                      NodeTest test,
                      int contextId,
                      NodeSet context)
Method Detail

setNodeTest

public void setNodeTest(NodeTest test)

contains

public boolean contains(DocumentImpl doc,
                        long nodeId)

contains

public boolean contains(NodeProxy p)
Description copied from class: AbstractNodeSet
Check if this node set contains a node matching the document and node-id of the given NodeProxy object.

Specified by:
contains in interface NodeSet
Specified by:
contains in class AbstractNodeSet
Parameters:
p -
Returns:

setInPredicate

public void setInPredicate(boolean predicate)

getDocumentSet

public DocumentSet getDocumentSet()
Description copied from interface: Sequence
Returns the set of documents from which the node items in this sequence have been selected. This is for internal use only.

Specified by:
getDocumentSet in interface NodeSet
Overrides:
getDocumentSet in class AbstractNodeSet

nodeHasParent

public NodeProxy nodeHasParent(DocumentImpl doc,
                               long gid,
                               boolean directParent,
                               boolean includeSelf)

nodeHasParent

public NodeProxy nodeHasParent(NodeProxy node,
                               boolean directParent,
                               boolean includeSelf)

parentWithChild

public NodeProxy parentWithChild(DocumentImpl doc,
                                 long gid,
                                 boolean directParent,
                                 boolean includeSelf,
                                 int level)
Description copied from class: AbstractNodeSet
Check if the node identified by its node id has an ancestor contained in this node set and return the ancestor found. If directParent is true, only immediate ancestors (parents) are considered. Otherwise the method will call itself recursively for all the node's parents. If includeSelf is true, the method returns also true if the node itself is contained in the node set.

Specified by:
parentWithChild in interface NodeSet
Overrides:
parentWithChild in class AbstractNodeSet

parentWithChild

public NodeProxy parentWithChild(NodeProxy proxy,
                                 boolean directParent,
                                 boolean includeSelf,
                                 int level)
Description copied from class: AbstractNodeSet
Check if the given node has an ancestor contained in this node set and return the ancestor found. If directParent is true, only immediate ancestors (parents) are considered. Otherwise the method will call itself recursively for all the node's parents. If includeSelf is true, the method returns also true if the node itself is contained in the node set.

Specified by:
parentWithChild in interface NodeSet
Overrides:
parentWithChild in class AbstractNodeSet

realize

public final void realize()

setSelfIsContext

public void setSelfIsContext()

setContextId

public void setContextId(int contextId)

hasIndex

public boolean hasIndex()

add

public void add(DocumentImpl doc,
                long nodeId)

add

public void add(org.w3c.dom.Node node)

add

public void add(NodeProxy proxy)
Description copied from class: AbstractNodeSet
Add a new proxy object to the node set. Please note: node set implementations may allow duplicates.

Specified by:
add in interface NodeSet
Specified by:
add in class AbstractNodeSet
Parameters:
proxy -

addAll

public void addAll(org.w3c.dom.NodeList other)

addAll

public void addAll(NodeSet other)
Description copied from class: AbstractNodeSet
Add all nodes from the given node set.

Specified by:
addAll in interface NodeSet
Specified by:
addAll in class AbstractNodeSet
Parameters:
other -

set

public void set(int position,
                DocumentImpl doc,
                long nodeId)

remove

public void remove(NodeProxy node)
Description copied from class: AbstractNodeSet
Remove a node. By default, this method throws a RuntimeException.

Overrides:
remove in class AbstractNodeSet
Parameters:
node -

getLength

public int getLength()
Description copied from class: AbstractNodeSet
Return the number of nodes contained in this node set.

Specified by:
getLength in interface NodeSet
Specified by:
getLength in class AbstractNodeSet

item

public org.w3c.dom.Node item(int pos)
Specified by:
item in interface org.w3c.dom.NodeList
Specified by:
item in class AbstractNodeSet

get

public NodeProxy get(int pos)
Description copied from class: AbstractNodeSet
Get the node at position pos within this node set.

Specified by:
get in interface NodeSet
Specified by:
get in class AbstractNodeSet
Parameters:
pos -
Returns:

itemAt

public Item itemAt(int pos)
Description copied from interface: Sequence
Returns the item located at the specified position within this sequence. Items are counted beginning at 0.

Specified by:
itemAt in interface Sequence
Specified by:
itemAt in class AbstractSequence

get

public NodeProxy get(DocumentImpl doc,
                     long gid)
Description copied from class: AbstractNodeSet
Get a node from this node set matching the document and node id.

Specified by:
get in interface NodeSet
Specified by:
get in class AbstractNodeSet
Parameters:
doc -
gid -
Returns:

get

public NodeProxy get(NodeProxy proxy)
Description copied from class: AbstractNodeSet
Get a node from this node set matching the document and node id of the given NodeProxy.

Specified by:
get in interface NodeSet
Specified by:
get in class AbstractNodeSet
Parameters:
proxy -
Returns:

iterator

public NodeSetIterator iterator()
Description copied from class: AbstractNodeSet
Return an iterator on the nodes in this list. The iterator returns nodes according to the internal ordering of nodes (i.e. level first), not in document- order.

Specified by:
iterator in interface NodeSet
Specified by:
iterator in class AbstractNodeSet
Returns:

iterate

public SequenceIterator iterate()
Description copied from interface: Sequence
Returns an iterator over all items in the sequence. The items are returned in document order where applicable.

Specified by:
iterate in interface Sequence
Specified by:
iterate in class AbstractNodeSet

unorderedIterator

public SequenceIterator unorderedIterator()
Description copied from interface: Sequence
Returns an iterator over all items in the sequence. The returned items may - but need not - to be in document order.

Specified by:
unorderedIterator in interface Sequence
Specified by:
unorderedIterator in class AbstractNodeSet

intersection

public NodeSet intersection(NodeSet other)
Description copied from class: AbstractNodeSet
Return a new node set, which represents the intersection of the current node set with the given node set.

Specified by:
intersection in interface NodeSet
Overrides:
intersection in class AbstractNodeSet
Parameters:
other -
Returns:

union

public NodeSet union(NodeSet other)
Description copied from class: AbstractNodeSet
Return a new node set which represents the union of the current node set and the given node set.

Specified by:
union in interface NodeSet
Overrides:
union in class AbstractNodeSet
Parameters:
other -
Returns:

clearContext

public void clearContext()

toString

public java.lang.String toString()
Overrides:
toString in class AbstractNodeSet


<oXygen/> XML Editor provides support for editing and debugging XQuery expressions against the eXist XML Database.