org.apache.xpath.domapi
Class XPathResultImpl

java.lang.Object
  |
  +--org.apache.xpath.domapi.XPathResultImpl

public class XPathResultImpl
extends java.lang.Object
implements XPathResult, EventListener

**Experimental** 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, XPathResult

Method Summary
 boolean getBooleanValue()
           
 boolean getInvalidIteratorState()
           
 double getNumberValue()
          The value of this number result.
 short getResultType()
           
 Node getSingleNodeValue()
          The value of this single node result, which may be null.
 int getSnapshotLength()
          The number of nodes in the result snapshot.
 java.lang.String getStringValue()
          The value of this string result.
 java.lang.String getTypeString(int type)
          Given a request type, return the equivalent string.
 void handleEvent(Event event)
           
static boolean isValidType(short type)
          Check if the specified type is one of the supported types.
 Node iterateNext()
          Iterates and returns the next node from the node set or nullif there are no more nodes.
 Node snapshotItem(int index)
          Returns the indexth item in the snapshot collection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getResultType

public short getResultType()
Specified by:
getResultType in interface XPathResult
See Also:
XPathResult.getResultType()

getNumberValue

public double getNumberValue()
                      throws XPathException
The value of this number result.
Specified by:
getNumberValue in interface XPathResult
Throws:
XPathException - TYPE_ERR: raised if resultType is not NUMBER_TYPE.
See Also:
XPathResult.getNumberValue()

getStringValue

public java.lang.String getStringValue()
                                throws XPathException
The value of this string result.
Specified by:
getStringValue in interface XPathResult
Throws:
XPathException - TYPE_ERR: raised if resultType is not STRING_TYPE.
See Also:
XPathResult.getStringValue()

getBooleanValue

public boolean getBooleanValue()
                        throws XPathException
Specified by:
getBooleanValue in interface XPathResult
See Also:
XPathResult.getBooleanValue()

getSingleNodeValue

public Node getSingleNodeValue()
                        throws XPathException
The value of this single node result, which may be null.
Specified by:
getSingleNodeValue in interface XPathResult
Throws:
XPathException - TYPE_ERR: raised if resultType is not ANY_UNORDERED_NODE_TYPE or FIRST_ORDERED_NODE_TYPE.
See Also:
XPathResult.getSingleNodeValue()

getInvalidIteratorState

public boolean getInvalidIteratorState()
Specified by:
getInvalidIteratorState in interface XPathResult
See Also:
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.
Specified by:
getSnapshotLength in interface XPathResult
Throws:
XPathException - TYPE_ERR: raised if resultType is not UNORDERED_NODE_SNAPSHOT_TYPE or ORDERED_NODE_SNAPSHOT_TYPE.
See Also:
XPathResult.getSnapshotLength()

iterateNext

public Node iterateNext()
                 throws XPathException,
                        DOMException
Iterates and returns the next node from the node set or nullif there are no more nodes.
Specified by:
iterateNext in interface XPathResult
Returns:
Returns the next node.
Throws:
XPathException - TYPE_ERR: raised if resultType is not UNORDERED_NODE_ITERATOR_TYPE or ORDERED_NODE_ITERATOR_TYPE.
DOMException - INVALID_STATE_ERR: The document has been mutated since the result was returned.
See Also:
XPathResult.iterateNext()

snapshotItem

public 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.
Specified by:
snapshotItem in interface XPathResult
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:
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(Event event)
Specified by:
handleEvent in interface EventListener
See Also:
EventListener.handleEvent(Event)

getTypeString

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


Copyright © 2003 Apache XML Project. All Rights Reserved.