org.apache.xpath.domapi
Class XPathResultImpl

java.lang.Object
  extended byorg.apache.xpath.domapi.XPathResultImpl
All Implemented Interfaces:
org.w3c.dom.events.EventListener

public class XPathResultImpl
extends Object
implements org.w3c.dom.events.EventListener

The class provides an implementation XPathResult according to the DOM L3 XPath Specification, Working Draft 28, March 2002.

See also the Document Object Model (DOM) Level 3 XPath Specification.

The XPathResult interface represents the result of the evaluation of an XPath expression within the context of a particular node. Since evaluation of an XPath expression can result in various result types, this object makes it possible to discover and manipulate the type and value of the result.

This implementation wraps an XObject.

See Also:
XObject, org.w3c.dom.xpath.XPathResult

Field Summary
private  org.w3c.dom.Node m_contextNode
          Only used to attach a mutation event handler when specified type is an iterator type.
private  boolean m_isInvalidIteratorState
           
private  org.w3c.dom.traversal.NodeIterator m_iterator
          The iterator, if this is an iterator type.
private  org.w3c.dom.NodeList m_list
          The list, if this is a snapshot type.
private  XObject m_resultObj
          The wrapped XObject
private  short m_resultType
          This the type specified by the user during construction.
 
Constructor Summary
(package private) XPathResultImpl(short type, XObject result, org.w3c.dom.Node contextNode)
          Constructor for XPathResultImpl.
 
Method Summary
 boolean getBooleanValue()
           
 boolean getInvalidIteratorState()
           
 double getNumberValue()
          The value of this number result.
 short getResultType()
           
 org.w3c.dom.Node getSingleNodeValue()
          The value of this single node result, which may be null.
 int getSnapshotLength()
          The number of nodes in the result snapshot.
 String getStringValue()
          The value of this string result.
private  short getTypeFromXObject(XObject object)
          Given an XObject, determine the corresponding DOM XPath type
 String getTypeString(int type)
          Given a request type, return the equivalent string.
 void handleEvent(org.w3c.dom.events.Event event)
           
private  boolean isNamespaceNode(org.w3c.dom.Node node)
          Given a node, determine if it is a namespace node.
static boolean isValidType(short type)
          Check if the specified type is one of the supported types.
 org.w3c.dom.Node iterateNext()
          Iterates and returns the next node from the node set or nullif there are no more nodes.
 org.w3c.dom.Node snapshotItem(int index)
          Returns the indexth item in the snapshot collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_resultObj

private XObject m_resultObj
The wrapped XObject


m_resultType

private short m_resultType
This the type specified by the user during construction. Typically the constructor will be called by org.apache.xpath.XPath.evaluate().


m_isInvalidIteratorState

private boolean m_isInvalidIteratorState

m_contextNode

private org.w3c.dom.Node m_contextNode
Only used to attach a mutation event handler when specified type is an iterator type.


m_iterator

private org.w3c.dom.traversal.NodeIterator m_iterator
The iterator, if this is an iterator type.


m_list

private org.w3c.dom.NodeList m_list
The list, if this is a snapshot type.

Constructor Detail

XPathResultImpl

XPathResultImpl(short type,
                XObject result,
                org.w3c.dom.Node contextNode)
Constructor for XPathResultImpl. For internal use only.

Method Detail

getResultType

public short getResultType()
See Also:
org.w3c.dom.xpath.XPathResult#getResultType()

getNumberValue

public double getNumberValue()
                      throws XPathException
The value of this number result.

Throws:
XPathException - TYPE_ERR: raised if resultType is not NUMBER_TYPE.
See Also:
org.w3c.dom.xpath.XPathResult#getNumberValue()

getStringValue

public String getStringValue()
                      throws XPathException
The value of this string result.

Throws:
XPathException - TYPE_ERR: raised if resultType is not STRING_TYPE.
See Also:
org.w3c.dom.xpath.XPathResult#getStringValue()

getBooleanValue

public boolean getBooleanValue()
                        throws XPathException
Throws:
XPathException
See Also:
org.w3c.dom.xpath.XPathResult#getBooleanValue()

getSingleNodeValue

public org.w3c.dom.Node getSingleNodeValue()
                                    throws XPathException
The value of this single node result, which may be null.

Throws:
XPathException - TYPE_ERR: raised if resultType is not ANY_UNORDERED_NODE_TYPE or FIRST_ORDERED_NODE_TYPE.
See Also:
org.w3c.dom.xpath.XPathResult#getSingleNodeValue()

getInvalidIteratorState

public boolean getInvalidIteratorState()
See Also:
org.w3c.dom.xpath.XPathResult#getInvalidIteratorState()

getSnapshotLength

public int getSnapshotLength()
                      throws XPathException
The number of nodes in the result snapshot. Valid values for snapshotItem indices are 0 to snapshotLength-1 inclusive.

Throws:
XPathException - TYPE_ERR: raised if resultType is not UNORDERED_NODE_SNAPSHOT_TYPE or ORDERED_NODE_SNAPSHOT_TYPE.
See Also:
org.w3c.dom.xpath.XPathResult#getSnapshotLength()

iterateNext

public org.w3c.dom.Node iterateNext()
                             throws XPathException,
                                    org.w3c.dom.DOMException
Iterates and returns the next node from the node set or nullif there are no more nodes.

Returns:
Returns the next node.
Throws:
XPathException - TYPE_ERR: raised if resultType is not UNORDERED_NODE_ITERATOR_TYPE or ORDERED_NODE_ITERATOR_TYPE.
org.w3c.dom.DOMException - INVALID_STATE_ERR: The document has been mutated since the result was returned.
See Also:
org.w3c.dom.xpath.XPathResult#iterateNext()

snapshotItem

public org.w3c.dom.Node snapshotItem(int index)
                              throws XPathException
Returns the indexth item in the snapshot collection. If index is greater than or equal to the number of nodes in the list, this method returns null. Unlike the iterator result, the snapshot does not become invalid, but may not correspond to the current document if it is mutated.

Parameters:
index - Index into the snapshot collection.
Returns:
The node at the indexth position in the NodeList, or null if that is not a valid index.
Throws:
XPathException - TYPE_ERR: raised if resultType is not UNORDERED_NODE_SNAPSHOT_TYPE or ORDERED_NODE_SNAPSHOT_TYPE.
See Also:
org.w3c.dom.xpath.XPathResult#snapshotItem(int)

isValidType

public static boolean isValidType(short type)
Check if the specified type is one of the supported types.

Parameters:
type - The specified type
Returns:
true If the specified type is supported; otherwise, returns false.

handleEvent

public void handleEvent(org.w3c.dom.events.Event event)
Specified by:
handleEvent in interface org.w3c.dom.events.EventListener
See Also:
EventListener.handleEvent(Event)

getTypeString

public String getTypeString(int type)
Given a request type, return the equivalent string. For diagnostic purposes.

Returns:
type string

getTypeFromXObject

private short getTypeFromXObject(XObject object)
Given an XObject, determine the corresponding DOM XPath type

Returns:
type string

isNamespaceNode

private boolean isNamespaceNode(org.w3c.dom.Node node)
Given a node, determine if it is a namespace node.

Parameters:
node -
Returns:
boolean Returns true if this is a namespace node; otherwise, returns false.