src/java.xml/share/classes/javax/xml/xpath/XPathExpression.java
author joehw
Thu, 21 Dec 2017 17:08:05 -0800
changeset 48412 d4412e380f6b
parent 47216 71c04702a3d5
permissions -rw-r--r--
8184431: References to @sun.com Reviewed-by: lancea
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.QName;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    29
import org.xml.sax.InputSource;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    30
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    31
/**
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
    32
 * {@code XPathExpression} provides access to compiled XPath expressions.
45261
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
    33
 * 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
    34
 *
45261
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
    35
 * <a id="XPathExpression-evaluation"></a>
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
    36
 * <table class="striped">
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
    37
 *    <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
    38
 *    <thead>
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    39
 *      <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    40
 *        <th scope="col">Factor</th>
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    41
 *        <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
    42
 *      </tr>
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    43
 *    </thead>
45261
8a151bf73222 8180385: Fix HTML5 issues in the java.xml module
jjg
parents: 40483
diff changeset
    44
 *    <tbody>
40483
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    45
 *    <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    46
 *      <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
    47
 *      <td>
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    48
 *        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
    49
 *        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
    50
 *        an XPathExpressionException will be thrown.
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    51
 *
cb7f243e782d 6211561: XPath.evaluate(String,Object,QName) throws exception if context node is null
joehw
parents: 35337
diff changeset
    52
 *        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
    53
 *        is treated like a Document node.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    54
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    55
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    56
 *    <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    57
 *      <th scope="row">variables</th>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    58
 *      <td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    59
 *        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
    60
 *        An {@link XPathExpressionException} is raised if the variable resolver is undefined or
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    61
 *        the resolver returns {@code null} for the variable.
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
    62
 *        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
    63
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    64
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    65
 *    <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    66
 *      <th scope="row">functions</th>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    67
 *      <td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    68
 *        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
    69
 *        An {@link XPathExpressionException} is raised if the function resolver is undefined or
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
    70
 *        the function resolver returns {@code null} for the function.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    71
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    72
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    73
 *    <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    74
 *      <th scope="row">QNames</th>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    75
 *      <td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    76
 *        QNames in the expression are resolved against the XPath namespace context.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    77
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    78
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    79
 *    <tr>
45855
46c3f654e80f 8184021: Fix tables in doc comments to be accessible
jjg
parents: 45261
diff changeset
    80
 *      <th scope="row">result</th>
12005
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
 *        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
    83
 *        Valid return types are defined in {@link XPathConstants}.
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
    84
 *        Conversion to the return type follows XPath conversion rules.
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
 *    </tr>
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
    87
 *   </tbody>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    88
 * </table>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    89
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    90
 * <p>An XPath expression is not thread-safe and not reentrant.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    91
 * In other words, it is the application's responsibility to make
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    92
 * sure that one {@link XPathExpression} object is not used from
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    93
 * 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
    94
 * method is invoked, applications may not recursively call
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    95
 * the {@code evaluate} method.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    96
 *
48412
d4412e380f6b 8184431: References to @sun.com
joehw
parents: 47216
diff changeset
    97
 * @author  Norman Walsh
d4412e380f6b 8184431: References to @sun.com
joehw
parents: 47216
diff changeset
    98
 * @author  Jeff Suttor
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    99
 * @see <a href="http://www.w3.org/TR/xpath#section-Expressions">XML Path Language (XPath) Version 1.0, Expressions</a>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   100
 * @since 1.5
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   101
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   102
public interface XPathExpression {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   103
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   104
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   105
    /**
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   106
     * Evaluate the compiled XPath expression in the specified context and return the result as the specified type.
12005
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
     * <p>See <a href="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   109
     * variable, function and QName resolution and return type conversion.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   110
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   111
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   112
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   113
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   114
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   115
     * the context, otherwise an XPathExpressionException will be thrown.
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
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   118
     * 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
   119
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   120
     * @param item The context the XPath expression will be evaluated in.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   121
     * @param returnType The result type expected to be returned by the XPath expression.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   122
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   123
     * @return The {@code Object} that is the result of evaluating the expression and converting the result to
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   124
     *   {@code returnType}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   125
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   126
     * @throws XPathExpressionException If the expression cannot be evaluated.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   127
     * @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
   128
     * @throws NullPointerException If {@code returnType} 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
    public Object evaluate(Object item, QName returnType)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   131
        throws XPathExpressionException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   132
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   133
    /**
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   134
     * Evaluate the compiled 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
   135
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   136
     * <p>This method calls {@link #evaluate(Object item, QName returnType)} with a {@code returnType} of
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   137
     * {@link XPathConstants#STRING}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   138
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   139
     * <p>See <a href="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   140
     * variable, function and QName resolution and return type conversion.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   141
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   142
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   143
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   144
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   145
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   146
     * the context, otherwise an XPathExpressionException will be thrown.
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
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   149
     * 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
   150
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   151
     * @param item The context the XPath expression will be evaluated in.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   152
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   153
     * @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
   154
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   155
     * @throws XPathExpressionException If the expression cannot be evaluated.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   156
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   157
    public String evaluate(Object item)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   158
        throws XPathExpressionException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   159
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   160
    /**
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   161
     * Evaluate the compiled XPath expression in the context
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   162
     * of the specified {@code InputSource} and return the result as the
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   163
     * specified type.
12005
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
     * <p>This method builds a data model for the {@link InputSource} and calls
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   166
     * {@link #evaluate(Object item, QName returnType)} on the resulting document object.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   167
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   168
     * <p>See <a href="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   169
     * variable, function and QName resolution and return type conversion.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   170
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   171
     * <p>If {@code returnType} is not one of the types defined in {@link XPathConstants},
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   172
     * then an {@code IllegalArgumentException} is thrown.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   173
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   174
     * <p>If {@code source} or {@code returnType} is {@code null},
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   175
     * then a {@code NullPointerException} is thrown.
12005
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
     * @param source The {@code InputSource} of the document to evaluate over.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   178
     * @param returnType The desired return type.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   179
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   180
     * @return The {@code Object} that is the result of evaluating the expression and converting the result to
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   181
     *   {@code returnType}.
12005
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
     * @throws XPathExpressionException If the expression cannot be evaluated.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   184
     * @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
   185
     * @throws NullPointerException If {@code source or returnType} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   186
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   187
    public Object evaluate(InputSource source, QName returnType)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   188
        throws XPathExpressionException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   189
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   190
    /**
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   191
     * Evaluate the compiled XPath expression in the context
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   192
     * of the specified {@code InputSource} and return the result as a
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   193
     * {@code String}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   194
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   195
     * <p>This method calls {@link #evaluate(InputSource source, QName returnType)} with a {@code returnType} of
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   196
     * {@link XPathConstants#STRING}.
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
     * <p>See <a href="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   199
     * variable, function and QName resolution and return type conversion.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   200
     *
29999
8493f5fc1052 8077332: tidy warnings from javax/xml
avstepan
parents: 28695
diff changeset
   201
     * <p>If {@code source} is {@code null}, then a {@code NullPointerException} is thrown.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   202
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   203
     * @param source The {@code InputSource} of the document to evaluate over.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   204
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   205
     * @return The {@code String} that is the result of evaluating the expression and converting the result to a
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   206
     *   {@code String}.
12005
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
     * @throws XPathExpressionException If the expression cannot be evaluated.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   209
     * @throws NullPointerException If {@code source} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   210
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   211
    public String evaluate(InputSource source)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   212
        throws XPathExpressionException;
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   213
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   214
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   215
     * Evaluate the compiled XPath expression in the specified context, and return
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   216
     * the result with the type specified through the {@code class type}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   217
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   218
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   219
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   220
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   221
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   222
     * the context, otherwise an XPathExpressionException will be thrown.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   223
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   224
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   225
     * The type of the context is usually {@link org.w3c.dom.Node}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   226
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   227
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   228
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   229
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   230
     *     (T)evaluate(item, XPathEvaluationResult.XPathResultType.getQNameType(type));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   231
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   232
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   233
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   234
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type, specifying
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   235
     * XPathEvaluationResult as the type will result in IllegalArgumentException.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   236
     * Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   237
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   238
     * this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   239
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   240
     * @param <T> The class type that will be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   241
     * @param item The context the XPath expression will be evaluated in.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   242
     * @param type The class type expected to be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   243
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   244
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   245
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   246
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   247
     * @throws IllegalArgumentException If {@code type} is not of the types
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   248
     * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   249
     * XPathResultType}, or XPathEvaluationResult is specified as the type but an
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   250
     * implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   251
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type is not available.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   252
     * @throws NullPointerException If {@code type} is {@code null}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   253
     *
35337
2ba279bcff39 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 29999
diff changeset
   254
     * @since 9
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   255
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   256
    default <T>T evaluateExpression(Object item, Class<T> type)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   257
        throws XPathExpressionException
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   258
    {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   259
        return type.cast(evaluate(item, XPathEvaluationResult.XPathResultType.getQNameType(type)));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   260
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   261
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   262
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   263
     * Evaluate the compiled XPath expression in the specified context. This is
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   264
     * equivalent to calling {@link #evaluateExpression(Object item, Class type)}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   265
     * with type {@link XPathEvaluationResult}:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   266
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   267
     *     evaluateExpression(item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   268
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   269
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   270
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   271
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   272
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   273
     * the context, otherwise an XPathExpressionException will be thrown.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   274
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   275
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   276
     * The type of the context is usually {@link org.w3c.dom.Node}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   277
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   278
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   279
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   280
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   281
     *     evaluateExpression(item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   282
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   283
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   284
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   285
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   286
     * type, the default implementation of this method will always throw an
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   287
     * IllegalArgumentException. Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   288
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   289
     * override this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   290
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   291
     * @param item The context the XPath expression will be evaluated in.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   292
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   293
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   294
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   295
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   296
     * @throws IllegalArgumentException If the implementation of this method
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   297
     * does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   298
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   299
     *
35337
2ba279bcff39 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 29999
diff changeset
   300
     * @since 9
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   301
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   302
    default XPathEvaluationResult<?> evaluateExpression(Object item)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   303
        throws XPathExpressionException
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   304
    {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   305
        return evaluateExpression(item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   306
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   307
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   308
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   309
     * Evaluate the compiled XPath expression in the specified context,
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   310
     * and return the result with the type specified through the {@code class type}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   311
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   312
     * This method builds a data model for the {@link InputSource} and calls
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   313
     * {@link #evaluateExpression(Object item, Class type)} on the resulting
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   314
     * document object.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   315
     * <P>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   316
     * By default, the JDK's data model is {@link org.w3c.dom.Document}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   317
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   318
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   319
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   320
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   321
           (T)evaluate(source, XPathEvaluationResult.XPathResultType.getQNameType(type));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   322
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   323
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   324
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   325
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type, specifying
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   326
     * XPathEvaluationResult as the type will result in IllegalArgumentException.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   327
     * Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   328
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   329
     * this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   330
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   331
     * @param <T> The class type that will be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   332
     * @param source The {@code InputSource} of the document to evaluate over.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   333
     * @param type The class type expected to be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   334
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   335
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   336
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   337
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   338
     * @throws IllegalArgumentException If {@code type} is not of the types
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   339
     * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   340
     * XPathResultType}, or XPathEvaluationResult is specified as the type but an
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   341
     * implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   342
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   343
     * is not available.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   344
     * @throws NullPointerException If {@code source or type} is {@code null}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   345
     *
35337
2ba279bcff39 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 29999
diff changeset
   346
     * @since 9
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   347
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   348
    default <T>T evaluateExpression(InputSource source, Class<T> type)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   349
        throws XPathExpressionException
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   350
    {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   351
        return type.cast(evaluate(source, XPathEvaluationResult.XPathResultType.getQNameType(type)));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   352
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   353
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   354
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   355
     * Evaluate the compiled XPath expression in the specified context. This is
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   356
     * equivalent to calling {@link #evaluateExpression(InputSource source, Class type)}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   357
     * with type {@link XPathEvaluationResult}:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   358
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   359
     *     evaluateExpression(source, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   360
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   361
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   362
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   363
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   364
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   365
     *     (XPathEvaluationResult)evaluateExpression(source, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   366
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   367
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   368
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   369
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   370
     * type, the default implementation of this method will always throw an
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   371
     * IllegalArgumentException. Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   372
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   373
     * override this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   374
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   375
     * @param source The {@code InputSource} of the document to evaluate over.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   376
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   377
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   378
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   379
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   380
     * @throws IllegalArgumentException If the implementation of this method
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   381
     * does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   382
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   383
     * @throws NullPointerException If {@code source} is {@code null}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   384
     *
35337
2ba279bcff39 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 29999
diff changeset
   385
     * @since 9
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   386
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   387
    default XPathEvaluationResult<?> evaluateExpression(InputSource source)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   388
        throws XPathExpressionException
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   389
    {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   390
        return evaluateExpression(source, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   391
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   392
}