< prev index next >

jaxp/src/java.xml/share/classes/javax/xml/xpath/XPath.java

Print this page




 334      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type, specifying
 335      * XPathEvaluationResult as the type will result in IllegalArgumentException.
 336      * Any implementation supporting the
 337      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
 338      * this method.
 339      *
 340      * @param <T> The class type that will be returned by the XPath expression.
 341      * @param expression The XPath expression.
 342      * @param item The context the XPath expression will be evaluated in.
 343      * @param type The class type expected to be returned by the XPath expression.
 344      *
 345      * @return The result of evaluating the expression.
 346      *
 347      * @throws XPathExpressionException If the expression cannot be evaluated.
 348      * @throws IllegalArgumentException If {@code type} is not of the types
 349      * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType},
 350      * or XPathEvaluationResult is specified as the type but an implementation supporting the
 351      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type is not available.
 352      * @throws NullPointerException If {@code expression or type} is {@code null}.
 353      *
 354      * @since 1.9
 355      */
 356     default <T>T evaluateExpression(String expression, Object item, Class<T> type)
 357         throws XPathExpressionException {
 358         return type.cast(evaluate(expression, item,
 359                 XPathEvaluationResult.XPathResultType.getQNameType(type)));
 360     }
 361 
 362     /**
 363      * Evaluate an XPath expression in the specified context. This is equivalent to
 364      * calling {@link #evaluateExpression(String expression, Object item, Class type)}
 365      * with type {@link XPathEvaluationResult}:
 366      * <pre> {@code
 367      *     evaluateExpression(expression, item, XPathEvaluationResult.class);
 368      * }</pre>
 369      * <p>
 370      * The parameter {@code item} represents the context the XPath expression
 371      * will be operated on. The type of the context is implementation-dependent.
 372      * If the value is {@code null}, the operation must have no dependency on
 373      * the context, otherwise an XPathExpressionException will be thrown.
 374      *


 382      * }</pre>
 383      *
 384      * Since the {@code evaluate} method does not support the
 385      * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
 386      * type, the default implementation of this method will always throw an
 387      * IllegalArgumentException. Any implementation supporting the
 388      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
 389      * override this method.
 390      *
 391      * @param expression The XPath expression.
 392      * @param item The context the XPath expression will be evaluated in.
 393      *
 394      * @return The result of evaluating the expression.
 395      *
 396      * @throws XPathExpressionException If the expression cannot be evaluated.
 397      * @throws IllegalArgumentException If the implementation of this method
 398      * does not support the
 399      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
 400      * @throws NullPointerException If {@code expression} is {@code null}.
 401      *
 402      * @since 1.9
 403      */
 404     default XPathEvaluationResult<?> evaluateExpression(String expression, Object item)
 405         throws XPathExpressionException
 406     {
 407         return evaluateExpression(expression, item, XPathEvaluationResult.class);
 408     }
 409 
 410     /**
 411      * Evaluate an XPath expression in the context of the specified {@code source}
 412      * and return the result as specified.
 413      * <p>
 414      * This method builds a data model for the {@link InputSource} and calls
 415      * {@link #evaluateExpression(String expression, Object item, Class type)}
 416      * on the resulting document object. The data model is usually
 417      * {@link org.w3c.dom.Document}
 418      *
 419      * @implSpec
 420      * The default implementation in the XPath API is equivalent to:
 421      * <pre> {@code
 422            (T)evaluate(expression, source,


 428      * XPathEvaluationResult as the type will result in IllegalArgumentException.
 429      * Any implementation supporting the
 430      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
 431      * this method.
 432      *
 433      * @param <T> The class type that will be returned by the XPath expression.
 434      * @param expression The XPath expression.
 435      * @param source The input source of the document to evaluate over.
 436      * @param type The class type expected to be returned by the XPath expression.
 437      *
 438      * @return The result of evaluating the expression.
 439      *
 440      * @throws XPathExpressionException If the expression cannot be evaluated.
 441      * @throws IllegalArgumentException If {@code type} is not of the types
 442      * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType
 443      * XPathResultType}, or XPathEvaluationResult is specified as the type but an
 444      * implementation supporting the
 445      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type is not available.
 446      * @throws NullPointerException If {@code expression, source or type}is {@code null}.
 447      *
 448      * @since 1.9
 449      */
 450     default <T>T evaluateExpression(String expression, InputSource source, Class<T> type)
 451         throws XPathExpressionException
 452     {
 453         return type.cast(evaluate(expression, source,
 454                 XPathEvaluationResult.XPathResultType.getQNameType(type)));
 455     }
 456 
 457     /**
 458      * Evaluate an XPath expression in the specified context. This is equivalent to
 459      * calling {@link #evaluateExpression(String expression, Object item, Class type)}
 460      * with type {@link XPathEvaluationResult}:
 461      * <pre> {@code
 462      *     evaluateExpression(expression, item, XPathEvaluationResult.class);
 463      * }</pre>
 464      *
 465      * @implSpec
 466      * The default implementation in the XPath API is equivalent to:
 467      * <pre> {@code
 468      *     evaluateExpression(expression, source, XPathEvaluationResult.class);
 469      * }</pre>
 470      *
 471      * Since the {@code evaluate} method does not support the
 472      * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
 473      * type, the default implementation of this method will always throw an
 474      * IllegalArgumentException. Any implementation supporting the
 475      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
 476      * override this method.
 477      *
 478      * @param expression The XPath expression.
 479      * @param source The input source of the document to evaluate over.
 480      *
 481      * @return The result of evaluating the expression.
 482      *
 483      * @throws XPathExpressionException If the expression cannot be evaluated.
 484      * @throws IllegalArgumentException If the implementation of this method
 485      * does not support the
 486      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
 487      * @throws NullPointerException If {@code expression or source} is {@code null}.
 488      *
 489      * @since 1.9
 490      */
 491     default XPathEvaluationResult<?> evaluateExpression(String expression, InputSource source)
 492         throws XPathExpressionException
 493     {
 494         return evaluateExpression(expression, source, XPathEvaluationResult.class);
 495     }
 496 }


 334      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type, specifying
 335      * XPathEvaluationResult as the type will result in IllegalArgumentException.
 336      * Any implementation supporting the
 337      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
 338      * this method.
 339      *
 340      * @param <T> The class type that will be returned by the XPath expression.
 341      * @param expression The XPath expression.
 342      * @param item The context the XPath expression will be evaluated in.
 343      * @param type The class type expected to be returned by the XPath expression.
 344      *
 345      * @return The result of evaluating the expression.
 346      *
 347      * @throws XPathExpressionException If the expression cannot be evaluated.
 348      * @throws IllegalArgumentException If {@code type} is not of the types
 349      * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType},
 350      * or XPathEvaluationResult is specified as the type but an implementation supporting the
 351      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type is not available.
 352      * @throws NullPointerException If {@code expression or type} is {@code null}.
 353      *
 354      * @since 9
 355      */
 356     default <T>T evaluateExpression(String expression, Object item, Class<T> type)
 357         throws XPathExpressionException {
 358         return type.cast(evaluate(expression, item,
 359                 XPathEvaluationResult.XPathResultType.getQNameType(type)));
 360     }
 361 
 362     /**
 363      * Evaluate an XPath expression in the specified context. This is equivalent to
 364      * calling {@link #evaluateExpression(String expression, Object item, Class type)}
 365      * with type {@link XPathEvaluationResult}:
 366      * <pre> {@code
 367      *     evaluateExpression(expression, item, XPathEvaluationResult.class);
 368      * }</pre>
 369      * <p>
 370      * The parameter {@code item} represents the context the XPath expression
 371      * will be operated on. The type of the context is implementation-dependent.
 372      * If the value is {@code null}, the operation must have no dependency on
 373      * the context, otherwise an XPathExpressionException will be thrown.
 374      *


 382      * }</pre>
 383      *
 384      * Since the {@code evaluate} method does not support the
 385      * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
 386      * type, the default implementation of this method will always throw an
 387      * IllegalArgumentException. Any implementation supporting the
 388      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
 389      * override this method.
 390      *
 391      * @param expression The XPath expression.
 392      * @param item The context the XPath expression will be evaluated in.
 393      *
 394      * @return The result of evaluating the expression.
 395      *
 396      * @throws XPathExpressionException If the expression cannot be evaluated.
 397      * @throws IllegalArgumentException If the implementation of this method
 398      * does not support the
 399      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
 400      * @throws NullPointerException If {@code expression} is {@code null}.
 401      *
 402      * @since 9
 403      */
 404     default XPathEvaluationResult<?> evaluateExpression(String expression, Object item)
 405         throws XPathExpressionException
 406     {
 407         return evaluateExpression(expression, item, XPathEvaluationResult.class);
 408     }
 409 
 410     /**
 411      * Evaluate an XPath expression in the context of the specified {@code source}
 412      * and return the result as specified.
 413      * <p>
 414      * This method builds a data model for the {@link InputSource} and calls
 415      * {@link #evaluateExpression(String expression, Object item, Class type)}
 416      * on the resulting document object. The data model is usually
 417      * {@link org.w3c.dom.Document}
 418      *
 419      * @implSpec
 420      * The default implementation in the XPath API is equivalent to:
 421      * <pre> {@code
 422            (T)evaluate(expression, source,


 428      * XPathEvaluationResult as the type will result in IllegalArgumentException.
 429      * Any implementation supporting the
 430      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
 431      * this method.
 432      *
 433      * @param <T> The class type that will be returned by the XPath expression.
 434      * @param expression The XPath expression.
 435      * @param source The input source of the document to evaluate over.
 436      * @param type The class type expected to be returned by the XPath expression.
 437      *
 438      * @return The result of evaluating the expression.
 439      *
 440      * @throws XPathExpressionException If the expression cannot be evaluated.
 441      * @throws IllegalArgumentException If {@code type} is not of the types
 442      * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType
 443      * XPathResultType}, or XPathEvaluationResult is specified as the type but an
 444      * implementation supporting the
 445      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type is not available.
 446      * @throws NullPointerException If {@code expression, source or type}is {@code null}.
 447      *
 448      * @since 9
 449      */
 450     default <T>T evaluateExpression(String expression, InputSource source, Class<T> type)
 451         throws XPathExpressionException
 452     {
 453         return type.cast(evaluate(expression, source,
 454                 XPathEvaluationResult.XPathResultType.getQNameType(type)));
 455     }
 456 
 457     /**
 458      * Evaluate an XPath expression in the specified context. This is equivalent to
 459      * calling {@link #evaluateExpression(String expression, Object item, Class type)}
 460      * with type {@link XPathEvaluationResult}:
 461      * <pre> {@code
 462      *     evaluateExpression(expression, item, XPathEvaluationResult.class);
 463      * }</pre>
 464      *
 465      * @implSpec
 466      * The default implementation in the XPath API is equivalent to:
 467      * <pre> {@code
 468      *     evaluateExpression(expression, source, XPathEvaluationResult.class);
 469      * }</pre>
 470      *
 471      * Since the {@code evaluate} method does not support the
 472      * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
 473      * type, the default implementation of this method will always throw an
 474      * IllegalArgumentException. Any implementation supporting the
 475      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
 476      * override this method.
 477      *
 478      * @param expression The XPath expression.
 479      * @param source The input source of the document to evaluate over.
 480      *
 481      * @return The result of evaluating the expression.
 482      *
 483      * @throws XPathExpressionException If the expression cannot be evaluated.
 484      * @throws IllegalArgumentException If the implementation of this method
 485      * does not support the
 486      * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
 487      * @throws NullPointerException If {@code expression or source} is {@code null}.
 488      *
 489      * @since 9
 490      */
 491     default XPathEvaluationResult<?> evaluateExpression(String expression, InputSource source)
 492         throws XPathExpressionException
 493     {
 494         return evaluateExpression(expression, source, XPathEvaluationResult.class);
 495     }
 496 }
< prev index next >