Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/w3c/dom/xpath/XPathEvaluator.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 evaluation of XPath expressions is provided by49* <code>XPathEvaluator</code>. In a DOM implementation which supports the50* XPath 3.0 feature, as described above, the <code>XPathEvaluator</code>51* interface will be implemented on the same object which implements the52* <code>Document</code> interface permitting it to be obtained by the usual53* binding-specific method such as casting or by using the DOM Level 354* getInterface method. In this case the implementation obtained from the55* Document supports the XPath DOM module and is compatible with the XPath56* 1.0 specification.57* <p>Evaluation of expressions with specialized extension functions or58* variables may not work in all implementations and is, therefore, not59* portable. <code>XPathEvaluator</code> implementations may be available60* from other sources that could provide specific support for specialized61* extension functions or variables as would be defined by other62* specifications.63* <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>.64*/65public interface XPathEvaluator {66/**67* Creates a parsed XPath expression with resolved namespaces. This is68* useful when an expression will be reused in an application since it69* makes it possible to compile the expression string into a more70* efficient internal form and preresolve all namespace prefixes which71* occur within the expression.72* @param expression The XPath expression string to be parsed.73* @param resolver The <code>resolver</code> permits translation of74* prefixes within the XPath expression into appropriate namespace URIs75* . If this is specified as <code>null</code>, any namespace prefix76* within the expression will result in <code>DOMException</code>77* being thrown with the code <code>NAMESPACE_ERR</code>.78* @return The compiled form of the XPath expression.79* @exception XPathException80* INVALID_EXPRESSION_ERR: Raised if the expression is not legal81* according to the rules of the <code>XPathEvaluator</code>i82* @exception DOMException83* NAMESPACE_ERR: Raised if the expression contains namespace prefixes84* which cannot be resolved by the specified85* <code>XPathNSResolver</code>.86*/87public XPathExpression createExpression(String expression,88XPathNSResolver resolver)89throws XPathException, DOMException;9091/**92* Adapts any DOM node to resolve namespaces so that an XPath expression93* can be easily evaluated relative to the context of the node where it94* appeared within the document. This adapter works like the DOM Level 395* method <code>lookupNamespaceURI</code> on nodes in resolving the96* namespaceURI from a given prefix using the current information97* available in the node's hierarchy at the time lookupNamespaceURI is98* called. also correctly resolving the implicit xml prefix.99* @param nodeResolver The node to be used as a context for namespace100* resolution.101* @return <code>XPathNSResolver</code> which resolves namespaces with102* respect to the definitions in scope for a specified node.103*/104public XPathNSResolver createNSResolver(Node nodeResolver);105106/**107* Evaluates an XPath expression string and returns a result of the108* specified type if possible.109* @param expression The XPath expression string to be parsed and110* evaluated.111* @param contextNode The <code>context</code> is context node for the112* evaluation of this XPath expression. If the XPathEvaluator was113* obtained by casting the <code>Document</code> then this must be114* owned by the same document and must be a <code>Document</code>,115* <code>Element</code>, <code>Attribute</code>, <code>Text</code>,116* <code>CDATASection</code>, <code>Comment</code>,117* <code>ProcessingInstruction</code>, or <code>XPathNamespace</code>118* node. If the context node is a <code>Text</code> or a119* <code>CDATASection</code>, then the context is interpreted as the120* whole logical text node as seen by XPath, unless the node is empty121* in which case it may not serve as the XPath context.122* @param resolver The <code>resolver</code> permits translation of123* prefixes within the XPath expression into appropriate namespace URIs124* . If this is specified as <code>null</code>, any namespace prefix125* within the expression will result in <code>DOMException</code>126* being thrown with the code <code>NAMESPACE_ERR</code>.127* @param type If a specific <code>type</code> is specified, then the128* result will be returned as the corresponding type.For XPath 1.0129* results, this must be one of the codes of the130* <code>XPathResult</code> interface.131* @param result The <code>result</code> specifies a specific result132* object which may be reused and returned by this method. If this is133* specified as <code>null</code>or the implementation does not reuse134* the specified result, a new result object will be constructed and135* returned.For XPath 1.0 results, this object will be of type136* <code>XPathResult</code>.137* @return The result of the evaluation of the XPath expression.For XPath138* 1.0 results, this object will be of type <code>XPathResult</code>.139* @exception XPathException140* INVALID_EXPRESSION_ERR: Raised if the expression is not legal141* according to the rules of the <code>XPathEvaluator</code>i142* <br>TYPE_ERR: Raised if the result cannot be converted to return the143* specified type.144* @exception DOMException145* NAMESPACE_ERR: Raised if the expression contains namespace prefixes146* which cannot be resolved by the specified147* <code>XPathNSResolver</code>.148* <br>WRONG_DOCUMENT_ERR: The Node is from a document that is not149* supported by this <code>XPathEvaluator</code>.150* <br>NOT_SUPPORTED_ERR: The Node is not a type permitted as an XPath151* context node or the request type is not permitted by this152* <code>XPathEvaluator</code>.153*/154public Object evaluate(String expression,155Node contextNode,156XPathNSResolver resolver,157short type,158Object result)159throws XPathException, DOMException;160161}162163164