Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/w3c/dom/xpath/XPathResult.java
86410 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* This file is available under and governed by the GNU General Public26* License version 2 only, as published by the Free Software Foundation.27* However, the following notice accompanied the original version of this28* file and, per its terms, should not be removed:29*30* Copyright (c) 2002 World Wide Web Consortium,31* (Massachusetts Institute of Technology, Institut National de32* Recherche en Informatique et en Automatique, Keio University). All33* Rights Reserved. This program is distributed under the W3C's Software34* Intellectual Property License. This program is distributed in the35* hope that it will be useful, but WITHOUT ANY WARRANTY; without even36* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR37* PURPOSE.38* See W3C License http://www.w3.org/Consortium/Legal/ for more details.39*/4041package org.w3c.dom.xpath;424344import org.w3c.dom.Node;45import org.w3c.dom.DOMException;4647/**48* The <code>XPathResult</code> interface represents the result of the49* evaluation of an XPath 1.0 expression within the context of a particular50* node. Since evaluation of an XPath expression can result in various51* result types, this object makes it possible to discover and manipulate52* the type and value of the result.53* <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>.54*/55public interface XPathResult {56// XPathResultType57/**58* This code does not represent a specific type. An evaluation of an XPath59* expression will never produce this type. If this type is requested,60* then the evaluation returns whatever type naturally results from61* evaluation of the expression.62* <br>If the natural result is a node set when <code>ANY_TYPE</code> was63* requested, then <code>UNORDERED_NODE_ITERATOR_TYPE</code> is always64* the resulting type. Any other representation of a node set must be65* explicitly requested.66*/67public static final short ANY_TYPE = 0;68/**69* The result is a number as defined by . Document modification does not70* invalidate the number, but may mean that reevaluation would not yield71* the same number.72*/73public static final short NUMBER_TYPE = 1;74/**75* The result is a string as defined by . Document modification does not76* invalidate the string, but may mean that the string no longer77* corresponds to the current document.78*/79public static final short STRING_TYPE = 2;80/**81* The result is a boolean as defined by . Document modification does not82* invalidate the boolean, but may mean that reevaluation would not83* yield the same boolean.84*/85public static final short BOOLEAN_TYPE = 3;86/**87* The result is a node set as defined by that will be accessed88* iteratively, which may not produce nodes in a particular order.89* Document modification invalidates the iteration.90* <br>This is the default type returned if the result is a node set and91* <code>ANY_TYPE</code> is requested.92*/93public static final short UNORDERED_NODE_ITERATOR_TYPE = 4;94/**95* The result is a node set as defined by that will be accessed96* iteratively, which will produce document-ordered nodes. Document97* modification invalidates the iteration.98*/99public static final short ORDERED_NODE_ITERATOR_TYPE = 5;100/**101* The result is a node set as defined by that will be accessed as a102* snapshot list of nodes that may not be in a particular order.103* Document modification does not invalidate the snapshot but may mean104* that reevaluation would not yield the same snapshot and nodes in the105* snapshot may have been altered, moved, or removed from the document.106*/107public static final short UNORDERED_NODE_SNAPSHOT_TYPE = 6;108/**109* The result is a node set as defined by that will be accessed as a110* snapshot list of nodes that will be in original document order.111* Document modification does not invalidate the snapshot but may mean112* that reevaluation would not yield the same snapshot and nodes in the113* snapshot may have been altered, moved, or removed from the document.114*/115public static final short ORDERED_NODE_SNAPSHOT_TYPE = 7;116/**117* The result is a node set as defined by and will be accessed as a118* single node, which may be <code>null</code>if the node set is empty.119* Document modification does not invalidate the node, but may mean that120* the result node no longer corresponds to the current document. This121* is a convenience that permits optimization since the implementation122* can stop once any node in the in the resulting set has been found.123* <br>If there are more than one node in the actual result, the single124* node returned might not be the first in document order.125*/126public static final short ANY_UNORDERED_NODE_TYPE = 8;127/**128* The result is a node set as defined by and will be accessed as a129* single node, which may be <code>null</code> if the node set is empty.130* Document modification does not invalidate the node, but may mean that131* the result node no longer corresponds to the current document. This132* is a convenience that permits optimization since the implementation133* can stop once the first node in document order of the resulting set134* has been found.135* <br>If there are more than one node in the actual result, the single136* node returned will be the first in document order.137*/138public static final short FIRST_ORDERED_NODE_TYPE = 9;139140/**141* A code representing the type of this result, as defined by the type142* constants.143*/144public short getResultType();145146/**147* The value of this number result. If the native double type of the DOM148* binding does not directly support the exact IEEE 754 result of the149* XPath expression, then it is up to the definition of the binding150* binding to specify how the XPath number is converted to the native151* binding number.152* @exception XPathException153* TYPE_ERR: raised if <code>resultType</code> is not154* <code>NUMBER_TYPE</code>.155*/156public double getNumberValue()157throws XPathException;158159/**160* The value of this string result.161* @exception XPathException162* TYPE_ERR: raised if <code>resultType</code> is not163* <code>STRING_TYPE</code>.164*/165public String getStringValue()166throws XPathException;167168/**169* The value of this boolean result.170* @exception XPathException171* TYPE_ERR: raised if <code>resultType</code> is not172* <code>BOOLEAN_TYPE</code>.173*/174public boolean getBooleanValue()175throws XPathException;176177/**178* The value of this single node result, which may be <code>null</code>.179* @exception XPathException180* TYPE_ERR: raised if <code>resultType</code> is not181* <code>ANY_UNORDERED_NODE_TYPE</code> or182* <code>FIRST_ORDERED_NODE_TYPE</code>.183*/184public Node getSingleNodeValue()185throws XPathException;186187/**188* Signifies that the iterator has become invalid. True if189* <code>resultType</code> is <code>UNORDERED_NODE_ITERATOR_TYPE</code>190* or <code>ORDERED_NODE_ITERATOR_TYPE</code> and the document has been191* modified since this result was returned.192*/193public boolean getInvalidIteratorState();194195/**196* The number of nodes in the result snapshot. Valid values for197* snapshotItem indices are <code>0</code> to198* <code>snapshotLength-1</code> inclusive.199* @exception XPathException200* TYPE_ERR: raised if <code>resultType</code> is not201* <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or202* <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.203*/204public int getSnapshotLength()205throws XPathException;206207/**208* Iterates and returns the next node from the node set or209* <code>null</code>if there are no more nodes.210* @return Returns the next node.211* @exception XPathException212* TYPE_ERR: raised if <code>resultType</code> is not213* <code>UNORDERED_NODE_ITERATOR_TYPE</code> or214* <code>ORDERED_NODE_ITERATOR_TYPE</code>.215* @exception DOMException216* INVALID_STATE_ERR: The document has been mutated since the result was217* returned.218*/219public Node iterateNext()220throws XPathException, DOMException;221222/**223* Returns the <code>index</code>th item in the snapshot collection. If224* <code>index</code> is greater than or equal to the number of nodes in225* the list, this method returns <code>null</code>. Unlike the iterator226* result, the snapshot does not become invalid, but may not correspond227* to the current document if it is mutated.228* @param index Index into the snapshot collection.229* @return The node at the <code>index</code>th position in the230* <code>NodeList</code>, or <code>null</code> if that is not a valid231* index.232* @exception XPathException233* TYPE_ERR: raised if <code>resultType</code> is not234* <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or235* <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.236*/237public Node snapshotItem(int index)238throws XPathException;239240}241242243