1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. Oracle designates this 7 * particular file as subject to the "Classpath" exception as provided 8 * by Oracle in the LICENSE file that accompanied this code. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 /* 26 * This file is available under and governed by the GNU General Public 27 * License version 2 only, as published by the Free Software Foundation. 28 * However, the following notice accompanied the original version of this 29 * file and, per its terms, should not be removed: 30 * 31 * Copyright (c) 2002 World Wide Web Consortium, 32 * (Massachusetts Institute of Technology, Institut National de 33 * Recherche en Informatique et en Automatique, Keio University). All 34 * Rights Reserved. This program is distributed under the W3C's Software 35 * Intellectual Property License. This program is distributed in the 36 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even 37 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 38 * PURPOSE. 39 * See W3C License http://www.w3.org/Consortium/Legal/ for more details. 40 */ 41 42 package org.w3c.dom.xpath; 43 44 45 import org.w3c.dom.Node; 46 import org.w3c.dom.DOMException; 47 48 /** 49 * The <code>XPathResult</code> interface represents the result of the 50 * evaluation of an XPath 1.0 expression within the context of a particular 51 * node. Since evaluation of an XPath expression can result in various 52 * result types, this object makes it possible to discover and manipulate 53 * the type and value of the result. 54 * <p>See also the <a href='http://www.w3.org/2002/08/WD-DOM-Level-3-XPath-20020820'>Document Object Model (DOM) Level 3 XPath Specification</a>. 55 */ 56 public interface XPathResult { 57 // XPathResultType 58 /** 59 * This code does not represent a specific type. An evaluation of an XPath 60 * expression will never produce this type. If this type is requested, 61 * then the evaluation returns whatever type naturally results from 62 * evaluation of the expression. 63 * <br>If the natural result is a node set when <code>ANY_TYPE</code> was 64 * requested, then <code>UNORDERED_NODE_ITERATOR_TYPE</code> is always 65 * the resulting type. Any other representation of a node set must be 66 * explicitly requested. 67 */ 68 public static final short ANY_TYPE = 0; 69 /** 70 * The result is a number as defined by . Document modification does not 71 * invalidate the number, but may mean that reevaluation would not yield 72 * the same number. 73 */ 74 public static final short NUMBER_TYPE = 1; 75 /** 76 * The result is a string as defined by . Document modification does not 77 * invalidate the string, but may mean that the string no longer 78 * corresponds to the current document. 79 */ 80 public static final short STRING_TYPE = 2; 81 /** 82 * The result is a boolean as defined by . Document modification does not 83 * invalidate the boolean, but may mean that reevaluation would not 84 * yield the same boolean. 85 */ 86 public static final short BOOLEAN_TYPE = 3; 87 /** 88 * The result is a node set as defined by that will be accessed 89 * iteratively, which may not produce nodes in a particular order. 90 * Document modification invalidates the iteration. 91 * <br>This is the default type returned if the result is a node set and 92 * <code>ANY_TYPE</code> is requested. 93 */ 94 public static final short UNORDERED_NODE_ITERATOR_TYPE = 4; 95 /** 96 * The result is a node set as defined by that will be accessed 97 * iteratively, which will produce document-ordered nodes. Document 98 * modification invalidates the iteration. 99 */ 100 public static final short ORDERED_NODE_ITERATOR_TYPE = 5; 101 /** 102 * The result is a node set as defined by that will be accessed as a 103 * snapshot list of nodes that may not be in a particular order. 104 * Document modification does not invalidate the snapshot but may mean 105 * that reevaluation would not yield the same snapshot and nodes in the 106 * snapshot may have been altered, moved, or removed from the document. 107 */ 108 public static final short UNORDERED_NODE_SNAPSHOT_TYPE = 6; 109 /** 110 * The result is a node set as defined by that will be accessed as a 111 * snapshot list of nodes that will be in original document order. 112 * Document modification does not invalidate the snapshot but may mean 113 * that reevaluation would not yield the same snapshot and nodes in the 114 * snapshot may have been altered, moved, or removed from the document. 115 */ 116 public static final short ORDERED_NODE_SNAPSHOT_TYPE = 7; 117 /** 118 * The result is a node set as defined by and will be accessed as a 119 * single node, which may be <code>null</code>if the node set is empty. 120 * Document modification does not invalidate the node, but may mean that 121 * the result node no longer corresponds to the current document. This 122 * is a convenience that permits optimization since the implementation 123 * can stop once any node in the in the resulting set has been found. 124 * <br>If there are more than one node in the actual result, the single 125 * node returned might not be the first in document order. 126 */ 127 public static final short ANY_UNORDERED_NODE_TYPE = 8; 128 /** 129 * The result is a node set as defined by and will be accessed as a 130 * single node, which may be <code>null</code> if the node set is empty. 131 * Document modification does not invalidate the node, but may mean that 132 * the result node no longer corresponds to the current document. This 133 * is a convenience that permits optimization since the implementation 134 * can stop once the first node in document order of the resulting set 135 * has been found. 136 * <br>If there are more than one node in the actual result, the single 137 * node returned will be the first in document order. 138 */ 139 public static final short FIRST_ORDERED_NODE_TYPE = 9; 140 141 /** 142 * A code representing the type of this result, as defined by the type 143 * constants. 144 */ 145 public short getResultType(); 146 147 /** 148 * The value of this number result. If the native double type of the DOM 149 * binding does not directly support the exact IEEE 754 result of the 150 * XPath expression, then it is up to the definition of the binding 151 * binding to specify how the XPath number is converted to the native 152 * binding number. 153 * @exception XPathException 154 * TYPE_ERR: raised if <code>resultType</code> is not 155 * <code>NUMBER_TYPE</code>. 156 */ 157 public double getNumberValue() 158 throws XPathException; 159 160 /** 161 * The value of this string result. 162 * @exception XPathException 163 * TYPE_ERR: raised if <code>resultType</code> is not 164 * <code>STRING_TYPE</code>. 165 */ 166 public String getStringValue() 167 throws XPathException; 168 169 /** 170 * The value of this boolean result. 171 * @exception XPathException 172 * TYPE_ERR: raised if <code>resultType</code> is not 173 * <code>BOOLEAN_TYPE</code>. 174 */ 175 public boolean getBooleanValue() 176 throws XPathException; 177 178 /** 179 * The value of this single node result, which may be <code>null</code>. 180 * @exception XPathException 181 * TYPE_ERR: raised if <code>resultType</code> is not 182 * <code>ANY_UNORDERED_NODE_TYPE</code> or 183 * <code>FIRST_ORDERED_NODE_TYPE</code>. 184 */ 185 public Node getSingleNodeValue() 186 throws XPathException; 187 188 /** 189 * Signifies that the iterator has become invalid. True if 190 * <code>resultType</code> is <code>UNORDERED_NODE_ITERATOR_TYPE</code> 191 * or <code>ORDERED_NODE_ITERATOR_TYPE</code> and the document has been 192 * modified since this result was returned. 193 */ 194 public boolean getInvalidIteratorState(); 195 196 /** 197 * The number of nodes in the result snapshot. Valid values for 198 * snapshotItem indices are <code>0</code> to 199 * <code>snapshotLength-1</code> inclusive. 200 * @exception XPathException 201 * TYPE_ERR: raised if <code>resultType</code> is not 202 * <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or 203 * <code>ORDERED_NODE_SNAPSHOT_TYPE</code>. 204 */ 205 public int getSnapshotLength() 206 throws XPathException; 207 208 /** 209 * Iterates and returns the next node from the node set or 210 * <code>null</code>if there are no more nodes. 211 * @return Returns the next node. 212 * @exception XPathException 213 * TYPE_ERR: raised if <code>resultType</code> is not 214 * <code>UNORDERED_NODE_ITERATOR_TYPE</code> or 215 * <code>ORDERED_NODE_ITERATOR_TYPE</code>. 216 * @exception DOMException 217 * INVALID_STATE_ERR: The document has been mutated since the result was 218 * returned. 219 */ 220 public Node iterateNext() 221 throws XPathException, DOMException; 222 223 /** 224 * Returns the <code>index</code>th item in the snapshot collection. If 225 * <code>index</code> is greater than or equal to the number of nodes in 226 * the list, this method returns <code>null</code>. Unlike the iterator 227 * result, the snapshot does not become invalid, but may not correspond 228 * to the current document if it is mutated. 229 * @param index Index into the snapshot collection. 230 * @return The node at the <code>index</code>th position in the 231 * <code>NodeList</code>, or <code>null</code> if that is not a valid 232 * index. 233 * @exception XPathException 234 * TYPE_ERR: raised if <code>resultType</code> is not 235 * <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or 236 * <code>ORDERED_NODE_SNAPSHOT_TYPE</code>. 237 */ 238 public Node snapshotItem(int index) 239 throws XPathException; 240 241 }