001    /*
002     * Copyright (c) 2004 World Wide Web Consortium,
003     *
004     * (Massachusetts Institute of Technology, European Research Consortium for
005     * Informatics and Mathematics, Keio University). All Rights Reserved. This
006     * work is distributed under the W3C(r) Software License [1] in the hope that
007     * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
008     * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
009     *
010     * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
011     */
012    
013    package org.w3c.dom.xpath;
014    
015    import org.w3c.dom.Node;
016    import org.w3c.dom.DOMException;
017    
018    /**
019     * The <code>XPathResult</code> interface represents the result of the
020     * evaluation of an XPath 1.0 expression within the context of a particular
021     * node. Since evaluation of an XPath expression can result in various
022     * result types, this object makes it possible to discover and manipulate
023     * the type and value of the result.
024     * <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.
025     */
026    public interface XPathResult {
027        // XPathResultType
028        /**
029         * This code does not represent a specific type. An evaluation of an XPath
030         * expression will never produce this type. If this type is requested,
031         * then the evaluation returns whatever type naturally results from
032         * evaluation of the expression.
033         * <br>If the natural result is a node set when <code>ANY_TYPE</code> was
034         * requested, then <code>UNORDERED_NODE_ITERATOR_TYPE</code> is always
035         * the resulting type. Any other representation of a node set must be
036         * explicitly requested.
037         */
038        public static final short ANY_TYPE                  = 0;
039        /**
040         * The result is a <a href='http://www.w3.org/TR/1999/REC-xpath-19991116#numbers'>number</a> as defined by [<a href='http://www.w3.org/TR/1999/REC-xpath-19991116'>XPath 1.0</a>].
041         * Document modification does not invalidate the number, but may mean
042         * that reevaluation would not yield the same number.
043         */
044        public static final short NUMBER_TYPE               = 1;
045        /**
046         * The result is a <a href='http://www.w3.org/TR/1999/REC-xpath-19991116#strings'>string</a> as defined by [<a href='http://www.w3.org/TR/1999/REC-xpath-19991116'>XPath 1.0</a>].
047         * Document modification does not invalidate the string, but may mean
048         * that the string no longer corresponds to the current document.
049         */
050        public static final short STRING_TYPE               = 2;
051        /**
052         * The result is a <a href='http://www.w3.org/TR/1999/REC-xpath-19991116#booleans'>boolean</a> as defined by [<a href='http://www.w3.org/TR/1999/REC-xpath-19991116'>XPath 1.0</a>].
053         * Document modification does not invalidate the boolean, but may mean
054         * that reevaluation would not yield the same boolean.
055         */
056        public static final short BOOLEAN_TYPE              = 3;
057        /**
058         * The result is a <a href='http://www.w3.org/TR/1999/REC-xpath-19991116#node-sets'>node set</a> as defined by [<a href='http://www.w3.org/TR/1999/REC-xpath-19991116'>XPath 1.0</a>] that
059         * will be accessed iteratively, which may not produce nodes in a
060         * particular order. Document modification invalidates the iteration.
061         * <br>This is the default type returned if the result is a node set and
062         * <code>ANY_TYPE</code> is requested.
063         */
064        public static final short UNORDERED_NODE_ITERATOR_TYPE = 4;
065        /**
066         * The result is a node set as defined by [<a href='http://www.w3.org/TR/1999/REC-xpath-19991116'>XPath 1.0</a>] that
067         * will be accessed iteratively, which will produce document-ordered
068         * nodes. Document modification invalidates the iteration.
069         */
070        public static final short ORDERED_NODE_ITERATOR_TYPE = 5;
071        /**
072         * The result is a <a href='http://www.w3.org/TR/1999/REC-xpath-19991116#node-sets'>node set</a> as defined by [<a href='http://www.w3.org/TR/1999/REC-xpath-19991116'>XPath 1.0</a>] that
073         * will be accessed as a snapshot list of nodes that may not be in a
074         * particular order. Document modification does not invalidate the
075         * snapshot but may mean that reevaluation would not yield the same
076         * snapshot and nodes in the snapshot may have been altered, moved, or
077         * removed from the document.
078         */
079        public static final short UNORDERED_NODE_SNAPSHOT_TYPE = 6;
080        /**
081         * The result is a <a href='http://www.w3.org/TR/1999/REC-xpath-19991116#node-sets'>node set</a> as defined by [<a href='http://www.w3.org/TR/1999/REC-xpath-19991116'>XPath 1.0</a>] that
082         * will be accessed as a snapshot list of nodes that will be in original
083         * document order. Document modification does not invalidate the
084         * snapshot but may mean that reevaluation would not yield the same
085         * snapshot and nodes in the snapshot may have been altered, moved, or
086         * removed from the document.
087         */
088        public static final short ORDERED_NODE_SNAPSHOT_TYPE = 7;
089        /**
090         * The result is a <a href='http://www.w3.org/TR/1999/REC-xpath-19991116#node-sets'>node set</a> as defined by [<a href='http://www.w3.org/TR/1999/REC-xpath-19991116'>XPath 1.0</a>] and
091         * will be accessed as a single node, which may be <code>null</code>if
092         * the node set is empty. Document modification does not invalidate the
093         * node, but may mean that the result node no longer corresponds to the
094         * current document. This is a convenience that permits optimization
095         * since the implementation can stop once any node in the resulting set
096         * has been found.
097         * <br>If there is more than one node in the actual result, the single
098         * node returned might not be the first in document order.
099         */
100        public static final short ANY_UNORDERED_NODE_TYPE   = 8;
101        /**
102         * The result is a <a href='http://www.w3.org/TR/1999/REC-xpath-19991116#node-sets'>node set</a> as defined by [<a href='http://www.w3.org/TR/1999/REC-xpath-19991116'>XPath 1.0</a>] and
103         * will be accessed as a single node, which may be <code>null</code> if
104         * the node set is empty. Document modification does not invalidate the
105         * node, but may mean that the result node no longer corresponds to the
106         * current document. This is a convenience that permits optimization
107         * since the implementation can stop once the first node in document
108         * order of the resulting set has been found.
109         * <br>If there are more than one node in the actual result, the single
110         * node returned will be the first in document order.
111         */
112        public static final short FIRST_ORDERED_NODE_TYPE   = 9;
113    
114        /**
115         * A code representing the type of this result, as defined by the type
116         * constants.
117         */
118        public short getResultType();
119    
120        /**
121         * The value of this number result. If the native double type of the DOM
122         * binding does not directly support the exact IEEE 754 result of the
123         * XPath expression, then it is up to the definition of the binding to
124         * specify how the XPath number is converted to the native binding
125         * number.
126         * @exception XPathException
127         *   TYPE_ERR: raised if <code>resultType</code> is not
128         *   <code>NUMBER_TYPE</code>.
129         */
130        public double getNumberValue()
131                                 throws XPathException;
132    
133        /**
134         * The value of this string result.
135         * @exception XPathException
136         *   TYPE_ERR: raised if <code>resultType</code> is not
137         *   <code>STRING_TYPE</code>.
138         */
139        public String getStringValue()
140                                 throws XPathException;
141    
142        /**
143         * The value of this boolean result.
144         * @exception XPathException
145         *   TYPE_ERR: raised if <code>resultType</code> is not
146         *   <code>BOOLEAN_TYPE</code>.
147         */
148        public boolean getBooleanValue()
149                                 throws XPathException;
150    
151        /**
152         * The value of this single node result, which may be <code>null</code>.
153         * @exception XPathException
154         *   TYPE_ERR: raised if <code>resultType</code> is not
155         *   <code>ANY_UNORDERED_NODE_TYPE</code> or
156         *   <code>FIRST_ORDERED_NODE_TYPE</code>.
157         */
158        public Node getSingleNodeValue()
159                                 throws XPathException;
160    
161        /**
162         * Signifies that the iterator has become invalid. True if
163         * <code>resultType</code> is <code>UNORDERED_NODE_ITERATOR_TYPE</code>
164         * or <code>ORDERED_NODE_ITERATOR_TYPE</code> and the document has been
165         * modified since this result was returned.
166         */
167        public boolean getInvalidIteratorState();
168    
169        /**
170         * The number of nodes in the result snapshot. Valid values for
171         * snapshotItem indices are <code>0</code> to
172         * <code>snapshotLength-1</code> inclusive.
173         * @exception XPathException
174         *   TYPE_ERR: raised if <code>resultType</code> is not
175         *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
176         *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
177         */
178        public int getSnapshotLength()
179                                 throws XPathException;
180    
181        /**
182         * Iterates and returns the next node from the node set or
183         * <code>null</code>if there are no more nodes.
184         * @return Returns the next node.
185         * @exception XPathException
186         *   TYPE_ERR: raised if <code>resultType</code> is not
187         *   <code>UNORDERED_NODE_ITERATOR_TYPE</code> or
188         *   <code>ORDERED_NODE_ITERATOR_TYPE</code>.
189         * @exception DOMException
190         *   INVALID_STATE_ERR: The document has been mutated since the result was
191         *   returned.
192         */
193        public Node iterateNext()
194                                throws XPathException, DOMException;
195    
196        /**
197         * Returns the <code>index</code>th item in the snapshot collection. If
198         * <code>index</code> is greater than or equal to the number of nodes in
199         * the list, this method returns <code>null</code>. Unlike the iterator
200         * result, the snapshot does not become invalid, but may not correspond
201         * to the current document if it is mutated.
202         * @param index Index into the snapshot collection.
203         * @return The node at the <code>index</code>th position in the
204         *   <code>NodeList</code>, or <code>null</code> if that is not a valid
205         *   index.
206         * @exception XPathException
207         *   TYPE_ERR: raised if <code>resultType</code> is not
208         *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
209         *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
210         */
211        public Node snapshotItem(int index)
212                                 throws XPathException;
213    
214    }