src/java.xml/share/classes/javax/xml/xpath/XPath.java
author egahlin
Fri, 27 Sep 2019 13:01:55 +0200
branchJEP-349-branch
changeset 58370 9b4841a568cb
parent 48412 d4412e380f6b
permissions -rw-r--r--
Add missing TestUtils class for testing onError
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     1
/*
45261
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
     2
 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     4
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    10
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    15
 * accompanied this code).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    16
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    20
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    23
 * questions.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    24
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    25
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    26
package javax.xml.xpath;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    27
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    28
import javax.xml.namespace.NamespaceContext;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    29
import javax.xml.namespace.QName;
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    30
import org.xml.sax.InputSource;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    31
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    32
/**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    33
 * {@code XPath} provides access to the XPath evaluation environment and expressions.
45261
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
    34
 * The XPath evaluation is affected by the factors described in the following table.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    35
 *
45261
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
    36
 * <a id="XPath-evaluation"></a>
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
    37
 * <table class="striped">
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
    38
 *    <caption>Evaluation of XPath Expressions</caption>
40483
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    39
 *    <thead>
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    40
 *      <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    41
 *        <th scope="col">Factor</th>
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    42
 *        <th scope="col">Behavior</th>
40483
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    43
 *      </tr>
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    44
 *    </thead>
45261
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
    45
 *    <tbody>
40483
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    46
 *    <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    47
 *      <th scope="row">context</th>
40483
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    48
 *      <td>
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    49
 *        The type of the context is implementation-dependent. If the value is
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    50
 *        null, the operation must have no dependency on the context, otherwise
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    51
 *        an XPathExpressionException will be thrown.
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    52
 *
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    53
 *        For the purposes of evaluating XPath expressions, a DocumentFragment
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    54
 *        is treated like a Document node.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    55
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    56
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    57
 *    <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    58
 *      <th scope="row">variables</th>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    59
 *      <td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    60
 *        If the expression contains a variable reference, its value will be found through the {@link XPathVariableResolver}
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    61
 *        set with {@link #setXPathVariableResolver(XPathVariableResolver resolver)}.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    62
 *        An {@link XPathExpressionException} is raised if the variable resolver is undefined or
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    63
 *        the resolver returns {@code null} for the variable.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    64
 *        The value of a variable must be immutable through the course of any single evaluation.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    65
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    66
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    67
 *    <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    68
 *      <th scope="row">functions</th>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    69
 *      <td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    70
 *        If the expression contains a function reference, the function will be found through the {@link XPathFunctionResolver}
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    71
 *        set with {@link #setXPathFunctionResolver(XPathFunctionResolver resolver)}.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    72
 *        An {@link XPathExpressionException} is raised if the function resolver is undefined or
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    73
 *        the function resolver returns {@code null} for the function.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    74
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    75
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    76
 *    <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    77
 *      <th scope="row">QNames</th>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    78
 *      <td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    79
 *        QNames in the expression are resolved against the XPath namespace context
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    80
 *        set with {@link #setNamespaceContext(NamespaceContext nsContext)}.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    81
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    82
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
 *    <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    84
 *      <th scope="row">result</th>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    85
 *      <td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    86
 *        This result of evaluating an expression is converted to an instance of the desired return type.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    87
 *        Valid return types are defined in {@link XPathConstants}.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    88
 *        Conversion to the return type follows XPath conversion rules.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    89
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    90
 *    </tr>
45261
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
    91
 *    </tbody>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    92
 * </table>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    93
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    94
 * <p>An XPath object is not thread-safe and not reentrant.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    95
 * In other words, it is the application's responsibility to make
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    96
 * sure that one {@link XPath} object is not used from
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    97
 * more than one thread at any given time, and while the {@code evaluate}
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    98
 * method is invoked, applications may not recursively call
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    99
 * the {@code evaluate} method.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   100
 *
48412
d4412e380f6b 8184431: References to @sun.com
joehw
parents: 47216
diff changeset
   101
 * @author  Norman Walsh
d4412e380f6b 8184431: References to @sun.com
joehw
parents: 47216
diff changeset
   102
 * @author  Jeff Suttor
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   103
 * @see <a href="http://www.w3.org/TR/xpath">XML Path Language (XPath) Version 1.0</a>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   104
 * @since 1.5
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   105
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   106
public interface XPath {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   107
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   108
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   109
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   110
     * Reset this {@code XPath} to its original configuration.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   111
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   112
     * <p>{@code XPath} is reset to the same state as when it was created with
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   113
     * {@link XPathFactory#newXPath()}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   114
     * {@code reset()} is designed to allow the reuse of existing {@code XPath}s
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   115
     * thus saving resources associated with the creation of new {@code XPath}s.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   116
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   117
     * <p>The reset {@code XPath} is not guaranteed to have the same
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   118
     * {@link XPathFunctionResolver}, {@link XPathVariableResolver}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   119
     * or {@link NamespaceContext} {@code Object}s, e.g. {@link Object#equals(Object obj)}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   120
     * It is guaranteed to have a functionally equal {@code XPathFunctionResolver},
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   121
     * {@code XPathVariableResolver} and {@code NamespaceContext}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   122
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   123
    public void reset();
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   124
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   125
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   126
     * Establish a variable resolver.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   127
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   128
     * <p>A {@code NullPointerException} is thrown if {@code resolver} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   129
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   130
     * @param resolver Variable resolver.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   131
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   132
     * @throws NullPointerException If {@code resolver} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   133
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   134
    public void setXPathVariableResolver(XPathVariableResolver resolver);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   135
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   136
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   137
       * Return the current variable resolver.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   138
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   139
       * <p>{@code null} is returned in no variable resolver is in effect.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   140
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   141
       * @return Current variable resolver.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   142
       */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   143
    public XPathVariableResolver getXPathVariableResolver();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   144
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   145
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   146
       * Establish a function resolver.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   147
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   148
       * <p>A {@code NullPointerException} is thrown if {@code resolver} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   149
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   150
       * @param resolver XPath function resolver.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   151
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   152
       * @throws NullPointerException If {@code resolver} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   153
       */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   154
    public void setXPathFunctionResolver(XPathFunctionResolver resolver);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   155
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   156
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   157
       * Return the current function resolver.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   158
       * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   159
       * {@code null} is returned in no function resolver is in effect.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   160
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   161
       * @return Current function resolver.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   162
       */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   163
    public XPathFunctionResolver getXPathFunctionResolver();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   164
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   165
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   166
       * Establish a namespace context.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   167
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   168
       * <p>A {@code NullPointerException} is thrown if {@code nsContext} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   169
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   170
       * @param nsContext Namespace context to use.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   171
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   172
       * @throws NullPointerException If {@code nsContext} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   173
       */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   174
    public void setNamespaceContext(NamespaceContext nsContext);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   175
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   176
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   177
       * Return the current namespace context.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   178
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   179
       * <p>{@code null} is returned in no namespace context is in effect.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   180
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   181
       * @return Current Namespace context.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   182
       */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   183
    public NamespaceContext getNamespaceContext();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   184
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   185
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   186
       * Compile an XPath expression for later evaluation.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   187
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   188
       * <p>If {@code expression} contains any {@link XPathFunction}s,
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   189
       * they must be available via the {@link XPathFunctionResolver}.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   190
       * An {@link XPathExpressionException} will be thrown if the
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   191
       * {@code XPathFunction}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   192
       * cannot be resovled with the {@code XPathFunctionResolver}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   193
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   194
       * <p>If {@code expression} contains any variables, the
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   195
       * {@link XPathVariableResolver} in effect
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   196
       * <strong>at compile time</strong> will be used to resolve them.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   197
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   198
       * @param expression The XPath expression.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   199
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   200
       * @return Compiled XPath expression.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   201
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   202
       * @throws XPathExpressionException If {@code expression} cannot be compiled.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   203
       * @throws NullPointerException If {@code expression} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   204
       */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   205
    public XPathExpression compile(String expression)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   206
        throws XPathExpressionException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   207
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   208
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   209
     * Evaluate an {@code XPath} expression in the specified context and
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   210
     * return the result as the specified type.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   211
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   212
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   213
     * See <a href="#XPath-evaluation">Evaluation of XPath Expressions</a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   214
     * for context item evaluation, variable, function and {@code QName} resolution
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   215
     * and return type conversion.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   216
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   217
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   218
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   219
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   220
     * the context, otherwise an XPathExpressionException will be thrown.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   221
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   222
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   223
     * The type of the context is usually {@link org.w3c.dom.Node}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   224
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   225
     * @param expression The XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   226
     * @param item The context the XPath expression will be evaluated in.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   227
     * @param returnType The result type expected to be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   228
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   229
     * @return The result of evaluating an XPath expression as an {@code Object} of {@code returnType}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   230
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   231
     * @throws XPathExpressionException If {@code expression} cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   232
     * @throws IllegalArgumentException If {@code returnType} is not one of the types defined in {@link XPathConstants} (
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   233
     * {@link XPathConstants#NUMBER NUMBER},
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   234
     * {@link XPathConstants#STRING STRING},
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   235
     * {@link XPathConstants#BOOLEAN BOOLEAN},
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   236
     * {@link XPathConstants#NODE NODE} or
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   237
     * {@link XPathConstants#NODESET NODESET}).
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   238
     * @throws NullPointerException If {@code expression or returnType} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   239
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   240
    public Object evaluate(String expression, Object item, QName returnType)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   241
        throws XPathExpressionException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   242
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   243
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   244
     * Evaluate an XPath expression in the specified context and return the result as a {@code String}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   245
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   246
     * <p>This method calls {@link #evaluate(String expression, Object item, QName returnType)} with a {@code returnType} of
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   247
     * {@link XPathConstants#STRING}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   248
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   249
     * <p>See <a href="#XPath-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   250
     * variable, function and QName resolution and return type conversion.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   251
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   252
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   253
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   254
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   255
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   256
     * the context, otherwise an XPathExpressionException will be thrown.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   257
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   258
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   259
     * The type of the context is usually {@link org.w3c.dom.Node}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   260
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   261
     * @param expression The XPath expression.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   262
     * @param item The context the XPath expression will be evaluated in.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   263
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   264
     * @return The result of evaluating an XPath expression as a {@code String}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   265
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   266
     * @throws XPathExpressionException If {@code expression} cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   267
     * @throws NullPointerException If {@code expression} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   268
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   269
    public String evaluate(String expression, Object item)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   270
        throws XPathExpressionException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   271
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   272
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   273
     * Evaluate an XPath expression in the context of the specified {@code InputSource}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   274
     * and return the result as the specified type.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   275
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   276
     * <p>This method builds a data model for the {@link InputSource} and calls
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   277
     * {@link #evaluate(String expression, Object item, QName returnType)} on the resulting document object.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   278
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   279
     * <p>See <a href="#XPath-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   280
     * variable, function and QName resolution and return type conversion.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   281
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   282
     * @param expression The XPath expression.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   283
     * @param source The input source of the document to evaluate over.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   284
     * @param returnType The desired return type.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   285
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   286
     * @return The {@code Object} that encapsulates the result of evaluating the expression.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   287
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   288
     * @throws XPathExpressionException If expression cannot be evaluated.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   289
     * @throws IllegalArgumentException If {@code returnType} is not one of the types defined in {@link XPathConstants}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   290
     * @throws NullPointerException If {@code expression, source or returnType} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   291
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   292
    public Object evaluate(
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   293
        String expression,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   294
        InputSource source,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   295
        QName returnType)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   296
        throws XPathExpressionException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   297
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   298
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   299
     * Evaluate an XPath expression in the context of the specified {@code InputSource}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   300
     * and return the result as a {@code String}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   301
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   302
     * <p>This method calls {@link #evaluate(String expression, InputSource source, QName returnType)} with a
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   303
     * {@code returnType} of {@link XPathConstants#STRING}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   304
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   305
     * <p>See <a href="#XPath-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   306
     * variable, function and QName resolution and return type conversion.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   307
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   308
     * @param expression The XPath expression.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   309
     * @param source The {@code InputSource} of the document to evaluate over.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   310
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   311
     * @return The {@code String} that is the result of evaluating the expression and
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   312
     *   converting the result to a {@code String}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   313
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   314
     * @throws XPathExpressionException If expression cannot be evaluated.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   315
     * @throws NullPointerException If {@code expression or source} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   316
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   317
    public String evaluate(String expression, InputSource source)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   318
        throws XPathExpressionException;
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   319
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   320
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   321
     * Evaluate an XPath expression in the specified context and return
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   322
     * the result with the type specified through the {@code class type}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   323
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   324
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   325
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   326
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   327
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   328
     * the context, otherwise an XPathExpressionException will be thrown.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   329
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   330
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   331
     * The type of the context is usually {@link org.w3c.dom.Node}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   332
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   333
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   334
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   335
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   336
     *     (T)evaluate(expression, item,
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   337
     *           XPathEvaluationResult.XPathResultType.getQNameType(type));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   338
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   339
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   340
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   341
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type, specifying
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   342
     * XPathEvaluationResult as the type will result in IllegalArgumentException.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   343
     * Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   344
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   345
     * this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   346
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   347
     * @param <T> The class type that will be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   348
     * @param expression The XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   349
     * @param item The context the XPath expression will be evaluated in.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   350
     * @param type The class type expected to be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   351
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   352
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   353
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   354
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   355
     * @throws IllegalArgumentException If {@code type} is not of the types
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   356
     * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType},
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   357
     * or XPathEvaluationResult is specified as the type but an implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   358
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type is not available.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   359
     * @throws NullPointerException If {@code expression or type} is {@code null}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   360
     *
35337
2ba279bcff39 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 29999
diff changeset
   361
     * @since 9
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   362
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   363
    default <T>T evaluateExpression(String expression, Object item, Class<T> type)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   364
        throws XPathExpressionException {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   365
        return type.cast(evaluate(expression, item,
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   366
                XPathEvaluationResult.XPathResultType.getQNameType(type)));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   367
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   368
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   369
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   370
     * Evaluate an XPath expression in the specified context. This is equivalent to
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   371
     * calling {@link #evaluateExpression(String expression, Object item, Class type)}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   372
     * with type {@link XPathEvaluationResult}:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   373
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   374
     *     evaluateExpression(expression, item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   375
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   376
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   377
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   378
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   379
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   380
     * the context, otherwise an XPathExpressionException will be thrown.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   381
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   382
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   383
     * The type of the context is usually {@link org.w3c.dom.Node}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   384
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   385
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   386
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   387
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   388
     *     evaluateExpression(expression, item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   389
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   390
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   391
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   392
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   393
     * type, the default implementation of this method will always throw an
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   394
     * IllegalArgumentException. Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   395
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   396
     * override this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   397
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   398
     * @param expression The XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   399
     * @param item The context the XPath expression will be evaluated in.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   400
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   401
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   402
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   403
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   404
     * @throws IllegalArgumentException If the implementation of this method
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   405
     * does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   406
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   407
     * @throws NullPointerException If {@code expression} is {@code null}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   408
     *
35337
2ba279bcff39 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 29999
diff changeset
   409
     * @since 9
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   410
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   411
    default XPathEvaluationResult<?> evaluateExpression(String expression, Object item)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   412
        throws XPathExpressionException
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   413
    {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   414
        return evaluateExpression(expression, item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   415
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   416
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   417
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   418
     * Evaluate an XPath expression in the context of the specified {@code source}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   419
     * and return the result as specified.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   420
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   421
     * This method builds a data model for the {@link InputSource} and calls
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   422
     * {@link #evaluateExpression(String expression, Object item, Class type)}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   423
     * on the resulting document object. The data model is usually
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   424
     * {@link org.w3c.dom.Document}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   425
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   426
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   427
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   428
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   429
           (T)evaluate(expression, source,
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   430
                XPathEvaluationResult.XPathResultType.getQNameType(type));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   431
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   432
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   433
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   434
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type, specifying
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   435
     * XPathEvaluationResult as the type will result in IllegalArgumentException.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   436
     * Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   437
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   438
     * this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   439
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   440
     * @param <T> The class type that will be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   441
     * @param expression The XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   442
     * @param source The input source of the document to evaluate over.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   443
     * @param type The class type expected to be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   444
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   445
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   446
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   447
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   448
     * @throws IllegalArgumentException If {@code type} is not of the types
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   449
     * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   450
     * XPathResultType}, or XPathEvaluationResult is specified as the type but an
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   451
     * implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   452
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type is not available.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   453
     * @throws NullPointerException If {@code expression, source or type}is {@code null}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   454
     *
35337
2ba279bcff39 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 29999
diff changeset
   455
     * @since 9
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   456
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   457
    default <T>T evaluateExpression(String expression, InputSource source, Class<T> type)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   458
        throws XPathExpressionException
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   459
    {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   460
        return type.cast(evaluate(expression, source,
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   461
                XPathEvaluationResult.XPathResultType.getQNameType(type)));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   462
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   463
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   464
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   465
     * Evaluate an XPath expression in the specified context. This is equivalent to
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   466
     * calling {@link #evaluateExpression(String expression, Object item, Class type)}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   467
     * with type {@link XPathEvaluationResult}:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   468
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   469
     *     evaluateExpression(expression, item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   470
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   471
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   472
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   473
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   474
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   475
     *     evaluateExpression(expression, source, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   476
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   477
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   478
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   479
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   480
     * type, the default implementation of this method will always throw an
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   481
     * IllegalArgumentException. Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   482
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   483
     * override this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   484
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   485
     * @param expression The XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   486
     * @param source The input source of the document to evaluate over.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   487
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   488
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   489
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   490
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   491
     * @throws IllegalArgumentException If the implementation of this method
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   492
     * does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   493
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   494
     * @throws NullPointerException If {@code expression or source} is {@code null}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   495
     *
35337
2ba279bcff39 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 29999
diff changeset
   496
     * @since 9
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   497
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   498
    default XPathEvaluationResult<?> evaluateExpression(String expression, InputSource source)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   499
        throws XPathExpressionException
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   500
    {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   501
        return evaluateExpression(expression, source, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   502
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   503
}