jaxp/src/java.xml/share/classes/javax/xml/xpath/XPath.java
author joehw
Tue, 27 Jan 2015 22:01:46 -0800
changeset 28695 427254b89b9e
parent 25868 686eef1e7a79
child 29999 8493f5fc1052
permissions -rw-r--r--
8054196: XPath: support any type Reviewed-by: alanb, lancea, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     1
/*
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
     2
 * Copyright (c) 2003, 2015, 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.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    34
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    35
 * <a name="XPath-evaluation"/>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    36
 * <table border="1" cellpadding="2">
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    37
 *   <thead>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    38
 *     <tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    39
 *       <th colspan="2">Evaluation of XPath Expressions.</th>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    40
 *     </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    41
 *   </thead>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    42
 *     <tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    43
 *       <td>context</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    44
 *       <td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    45
 *         If a request is made to evaluate the expression in the absence
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    46
 * of a context item, an empty document node will be used for the context.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    47
 * For the purposes of evaluating XPath expressions, a DocumentFragment
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    48
 * is treated like a Document node.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    49
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    50
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    51
 *    <tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    52
 *      <td>variables</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    53
 *      <td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    54
 *        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
    55
 *        set with {@link #setXPathVariableResolver(XPathVariableResolver resolver)}.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    56
 *        An {@link XPathExpressionException} is raised if the variable resolver is undefined or
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    57
 *        the resolver returns {@code null} for the variable.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    58
 *        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
    59
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    60
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    61
 *    <tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    62
 *      <td>functions</td>
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
 *        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
    65
 *        set with {@link #setXPathFunctionResolver(XPathFunctionResolver resolver)}.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    66
 *        An {@link XPathExpressionException} is raised if the function resolver is undefined or
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    67
 *        the function resolver returns {@code null} for the function.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    68
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    69
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    70
 *    <tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    71
 *      <td>QNames</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    72
 *      <td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    73
 *        QNames in the expression are resolved against the XPath namespace context
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    74
 *        set with {@link #setNamespaceContext(NamespaceContext nsContext)}.
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
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    77
 *    <tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    78
 *      <td>result</td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    79
 *      <td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    80
 *        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
    81
 *        Valid return types are defined in {@link XPathConstants}.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    82
 *        Conversion to the return type follows XPath conversion rules.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
 *      </td>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    84
 *    </tr>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    85
 * </table>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    86
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    87
 * <p>An XPath object is not thread-safe and not reentrant.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    88
 * In other words, it is the application's responsibility to make
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    89
 * sure that one {@link XPath} object is not used from
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    90
 * 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
    91
 * method is invoked, applications may not recursively call
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    92
 * the {@code evaluate} method.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    93
 * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    94
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    95
 * @author  <a href="Norman.Walsh@Sun.com">Norman Walsh</a>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    96
 * @author  <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    97
 * @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
    98
 * @since 1.5
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    99
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   100
public interface XPath {
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
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
     * Reset this {@code XPath} to its original configuration.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   105
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   106
     * <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
   107
     * {@link XPathFactory#newXPath()}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   108
     * {@code reset()} is designed to allow the reuse of existing {@code XPath}s
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   109
     * 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
   110
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   111
     * <p>The reset {@code XPath} is not guaranteed to have the same
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   112
     * {@link XPathFunctionResolver}, {@link XPathVariableResolver}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   113
     * or {@link NamespaceContext} {@code Object}s, e.g. {@link Object#equals(Object obj)}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   114
     * It is guaranteed to have a functionally equal {@code XPathFunctionResolver},
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   115
     * {@code XPathVariableResolver} and {@code NamespaceContext}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   116
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   117
    public void reset();
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   118
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   119
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   120
     * Establish a variable resolver.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   121
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   122
     * <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
   123
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   124
     * @param resolver Variable resolver.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   125
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   126
     * @throws NullPointerException If {@code resolver} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   127
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   128
    public void setXPathVariableResolver(XPathVariableResolver resolver);
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
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   131
       * Return the current variable resolver.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   132
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   133
       * <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
   134
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   135
       * @return Current variable resolver.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   136
       */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   137
    public XPathVariableResolver getXPathVariableResolver();
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
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   140
       * Establish a function resolver.
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>A {@code NullPointerException} is thrown if {@code resolver} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   143
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   144
       * @param resolver XPath function resolver.
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
       * @throws NullPointerException If {@code resolver} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   147
       */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   148
    public void setXPathFunctionResolver(XPathFunctionResolver resolver);
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
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   151
       * Return the current function resolver.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   152
       * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   153
       * {@code null} is returned in no function resolver is in effect.
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
       * @return Current function resolver.
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 XPathFunctionResolver getXPathFunctionResolver();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   158
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   159
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   160
       * Establish a namespace context.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   161
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   162
       * <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
   163
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   164
       * @param nsContext Namespace context to use.
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
       * @throws NullPointerException If {@code nsContext} is {@code null}.
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
    public void setNamespaceContext(NamespaceContext nsContext);
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
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   171
       * Return the current namespace context.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   172
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   173
       * <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
   174
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   175
       * @return Current Namespace context.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   176
       */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   177
    public NamespaceContext getNamespaceContext();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   178
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
       * Compile an XPath expression for later evaluation.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   181
       *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   182
       * <p>If {@code expression} contains any {@link XPathFunction}s,
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   183
       * they must be available via the {@link XPathFunctionResolver}.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   184
       * An {@link XPathExpressionException} will be thrown if the
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   185
       * {@code XPathFunction}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   186
       * cannot be resovled with the {@code XPathFunctionResolver}.
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 variables, the
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   189
       * {@link XPathVariableResolver} in effect
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   190
       * <strong>at compile time</strong> will be used to resolve them.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   191
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   192
       * @param expression The XPath expression.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   193
       *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   194
       * @return Compiled XPath expression.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   195
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   196
       * @throws XPathExpressionException If {@code expression} cannot be compiled.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   197
       * @throws NullPointerException If {@code expression} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   198
       */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   199
    public XPathExpression compile(String expression)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   200
        throws XPathExpressionException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   201
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
     * Evaluate an {@code XPath} expression in the specified context and
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   204
     * return the result as the specified type.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   205
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   206
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   207
     * See <a href="#XPath-evaluation">Evaluation of XPath Expressions</a>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   208
     * for context item evaluation, variable, function and {@code QName} resolution
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   209
     * and return type conversion.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   210
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   211
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   212
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   213
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   214
     * the context, otherwise an XPathExpressionException will be thrown.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   215
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   216
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   217
     * The type of the context is usually {@link org.w3c.dom.Node}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   218
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   219
     * @param expression The XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   220
     * @param item The context the XPath expression will be evaluated in.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   221
     * @param returnType The result type expected to be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   222
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   223
     * @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
   224
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   225
     * @throws XPathExpressionException If {@code expression} cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   226
     * @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
   227
     * {@link XPathConstants#NUMBER NUMBER},
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   228
     * {@link XPathConstants#STRING STRING},
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   229
     * {@link XPathConstants#BOOLEAN BOOLEAN},
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   230
     * {@link XPathConstants#NODE NODE} or
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   231
     * {@link XPathConstants#NODESET NODESET}).
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   232
     * @throws NullPointerException If {@code expression or returnType} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   233
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   234
    public Object evaluate(String expression, Object item, QName returnType)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   235
        throws XPathExpressionException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   236
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   237
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   238
     * 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
   239
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   240
     * <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
   241
     * {@link XPathConstants#STRING}.
12005
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
     * <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
   244
     * variable, function and QName resolution and return type conversion.
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>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   247
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   248
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   249
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   250
     * the context, otherwise an XPathExpressionException will be thrown.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   251
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   252
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   253
     * 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
   254
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   255
     * @param expression The XPath expression.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   256
     * @param item The context the XPath expression will be evaluated in.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   257
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   258
     * @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
   259
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   260
     * @throws XPathExpressionException If {@code expression} cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   261
     * @throws NullPointerException If {@code expression} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   262
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   263
    public String evaluate(String expression, Object item)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   264
        throws XPathExpressionException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   265
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   266
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   267
     * Evaluate an XPath expression in the context of the specified {@code InputSource}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   268
     * and return the result as the specified type.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   269
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   270
     * <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
   271
     * {@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
   272
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   273
     * <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
   274
     * variable, function and QName resolution and return type conversion.
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
     * @param expression The XPath expression.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   277
     * @param source The input source of the document to evaluate over.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   278
     * @param returnType The desired return type.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   279
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   280
     * @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
   281
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   282
     * @throws XPathExpressionException If expression cannot be evaluated.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   283
     * @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
   284
     * @throws NullPointerException If {@code expression, source or returnType} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   285
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   286
    public Object evaluate(
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   287
        String expression,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   288
        InputSource source,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   289
        QName returnType)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   290
        throws XPathExpressionException;
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
    /**
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   293
     * Evaluate an XPath expression in the context of the specified {@code InputSource}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   294
     * and return the result as a {@code String}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   295
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   296
     * <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
   297
     * {@code returnType} of {@link XPathConstants#STRING}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   298
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   299
     * <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
   300
     * variable, function and QName resolution and return type conversion.
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
     * @param expression The XPath expression.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   303
     * @param source The {@code InputSource} of the document to evaluate over.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   304
     *
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   305
     * @return The {@code String} that is the result of evaluating the expression and
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   306
     *   converting the result to a {@code String}.
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
     * @throws XPathExpressionException If expression cannot be evaluated.
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   309
     * @throws NullPointerException If {@code expression or source} is {@code null}.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   310
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   311
    public String evaluate(String expression, InputSource source)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   312
        throws XPathExpressionException;
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   313
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   314
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   315
     * Evaluate an XPath expression in the specified context and return
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   316
     * the result with the type specified through the {@code class type}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   317
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   318
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   319
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   320
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   321
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   322
     * the context, otherwise an XPathExpressionException will be thrown.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   323
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   324
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   325
     * The type of the context is usually {@link org.w3c.dom.Node}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   326
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   327
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   328
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   329
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   330
     *     (T)evaluate(expression, item,
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   331
     *           XPathEvaluationResult.XPathResultType.getQNameType(type));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   332
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   333
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   334
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   335
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type, specifying
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   336
     * XPathEvaluationResult as the type will result in IllegalArgumentException.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   337
     * Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   338
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   339
     * this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   340
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   341
     * @param <T> The class type that will be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   342
     * @param expression The XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   343
     * @param item The context the XPath expression will be evaluated in.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   344
     * @param type The class type expected to be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   345
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   346
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   347
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   348
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   349
     * @throws IllegalArgumentException If {@code type} is not of the types
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   350
     * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType},
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   351
     * or XPathEvaluationResult is specified as the type but an implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   352
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type is not available.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   353
     * @throws NullPointerException If {@code expression or type} is {@code null}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   354
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   355
     * @since 1.9
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   356
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   357
    default <T>T evaluateExpression(String expression, Object item, Class<T> type)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   358
        throws XPathExpressionException {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   359
        return type.cast(evaluate(expression, item,
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   360
                XPathEvaluationResult.XPathResultType.getQNameType(type)));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   361
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   362
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   363
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   364
     * Evaluate an XPath expression in the specified context. This is equivalent to
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   365
     * calling {@link #evaluateExpression(String expression, Object item, Class type)}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   366
     * with type {@link XPathEvaluationResult}:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   367
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   368
     *     evaluateExpression(expression, item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   369
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   370
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   371
     * The parameter {@code item} represents the context the XPath expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   372
     * will be operated on. The type of the context is implementation-dependent.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   373
     * If the value is {@code null}, the operation must have no dependency on
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   374
     * the context, otherwise an XPathExpressionException will be thrown.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   375
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   376
     * @implNote
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   377
     * The type of the context is usually {@link org.w3c.dom.Node}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   378
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   379
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   380
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   381
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   382
     *     evaluateExpression(expression, item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   383
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   384
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   385
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   386
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   387
     * type, the default implementation of this method will always throw an
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   388
     * IllegalArgumentException. Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   389
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   390
     * override this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   391
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   392
     * @param expression The XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   393
     * @param item The context the XPath expression will be evaluated in.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   394
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   395
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   396
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   397
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   398
     * @throws IllegalArgumentException If the implementation of this method
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   399
     * does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   400
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   401
     * @throws NullPointerException If {@code expression} is {@code null}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   402
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   403
     * @since 1.9
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   404
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   405
    default XPathEvaluationResult<?> evaluateExpression(String expression, Object item)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   406
        throws XPathExpressionException
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   407
    {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   408
        return evaluateExpression(expression, item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   409
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   410
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   411
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   412
     * Evaluate an XPath expression in the context of the specified {@code source}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   413
     * and return the result as specified.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   414
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   415
     * This method builds a data model for the {@link InputSource} and calls
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   416
     * {@link #evaluateExpression(String expression, Object item, Class type)}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   417
     * on the resulting document object. The data model is usually
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   418
     * {@link org.w3c.dom.Document}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   419
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   420
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   421
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   422
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   423
           (T)evaluate(expression, source,
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   424
                XPathEvaluationResult.XPathResultType.getQNameType(type));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   425
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   426
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   427
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   428
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type, specifying
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   429
     * XPathEvaluationResult as the type will result in IllegalArgumentException.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   430
     * Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   431
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   432
     * this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   433
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   434
     * @param <T> The class type that will be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   435
     * @param expression The XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   436
     * @param source The input source of the document to evaluate over.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   437
     * @param type The class type expected to be returned by the XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   438
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   439
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   440
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   441
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   442
     * @throws IllegalArgumentException If {@code type} is not of the types
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   443
     * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   444
     * XPathResultType}, or XPathEvaluationResult is specified as the type but an
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   445
     * implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   446
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type is not available.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   447
     * @throws NullPointerException If {@code expression, source or type}is {@code null}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   448
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   449
     * @since 1.9
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   450
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   451
    default <T>T evaluateExpression(String expression, InputSource source, Class<T> type)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   452
        throws XPathExpressionException
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   453
    {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   454
        return type.cast(evaluate(expression, source,
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   455
                XPathEvaluationResult.XPathResultType.getQNameType(type)));
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   456
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   457
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   458
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   459
     * Evaluate an XPath expression in the specified context. This is equivalent to
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   460
     * calling {@link #evaluateExpression(String expression, Object item, Class type)}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   461
     * with type {@link XPathEvaluationResult}:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   462
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   463
     *     evaluateExpression(expression, item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   464
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   465
     * <p>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   466
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   467
     * @implSpec
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   468
     * The default implementation in the XPath API is equivalent to:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   469
     * <pre> {@code
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   470
     *     evaluateExpression(expression, source, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   471
     * }</pre>
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   472
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   473
     * Since the {@code evaluate} method does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   474
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   475
     * type, the default implementation of this method will always throw an
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   476
     * IllegalArgumentException. Any implementation supporting the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   477
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   478
     * override this method.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   479
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   480
     * @param expression The XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   481
     * @param source The input source of the document to evaluate over.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   482
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   483
     * @return The result of evaluating the expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   484
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   485
     * @throws XPathExpressionException If the expression cannot be evaluated.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   486
     * @throws IllegalArgumentException If the implementation of this method
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   487
     * does not support the
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   488
     * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   489
     * @throws NullPointerException If {@code expression or source} is {@code null}.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   490
     *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   491
     * @since 1.9
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   492
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   493
    default XPathEvaluationResult<?> evaluateExpression(String expression, InputSource source)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   494
        throws XPathExpressionException
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   495
    {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   496
        return evaluateExpression(expression, source, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   497
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   498
}