229 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type, specifying
230 * XPathEvaluationResult as the type will result in IllegalArgumentException.
231 * Any implementation supporting the
232 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
233 * this method.
234 *
235 * @param <T> The class type that will be returned by the XPath expression.
236 * @param item The context the XPath expression will be evaluated in.
237 * @param type The class type expected to be returned by the XPath expression.
238 *
239 * @return The result of evaluating the expression.
240 *
241 * @throws XPathExpressionException If the expression cannot be evaluated.
242 * @throws IllegalArgumentException If {@code type} is not of the types
243 * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType
244 * XPathResultType}, or XPathEvaluationResult is specified as the type but an
245 * implementation supporting the
246 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type is not available.
247 * @throws NullPointerException If {@code type} is {@code null}.
248 *
249 * @since 1.9
250 */
251 default <T>T evaluateExpression(Object item, Class<T> type)
252 throws XPathExpressionException
253 {
254 return type.cast(evaluate(item, XPathEvaluationResult.XPathResultType.getQNameType(type)));
255 }
256
257 /**
258 * Evaluate the compiled XPath expression in the specified context. This is
259 * equivalent to calling {@link #evaluateExpression(Object item, Class type)}
260 * with type {@link XPathEvaluationResult}:
261 * <pre> {@code
262 * evaluateExpression(item, XPathEvaluationResult.class);
263 * }</pre>
264 * <p>
265 * The parameter {@code item} represents the context the XPath expression
266 * will be operated on. The type of the context is implementation-dependent.
267 * If the value is {@code null}, the operation must have no dependency on
268 * the context, otherwise an XPathExpressionException will be thrown.
269 *
275 * <pre> {@code
276 * evaluateExpression(item, XPathEvaluationResult.class);
277 * }</pre>
278 *
279 * Since the {@code evaluate} method does not support the
280 * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
281 * type, the default implementation of this method will always throw an
282 * IllegalArgumentException. Any implementation supporting the
283 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
284 * override this method.
285 *
286 * @param item The context the XPath expression will be evaluated in.
287 *
288 * @return The result of evaluating the expression.
289 *
290 * @throws XPathExpressionException If the expression cannot be evaluated.
291 * @throws IllegalArgumentException If the implementation of this method
292 * does not support the
293 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
294 *
295 * @since 1.9
296 */
297 default XPathEvaluationResult<?> evaluateExpression(Object item)
298 throws XPathExpressionException
299 {
300 return evaluateExpression(item, XPathEvaluationResult.class);
301 }
302
303 /**
304 * Evaluate the compiled XPath expression in the specified context,
305 * and return the result with the type specified through the {@code class type}
306 * <p>
307 * This method builds a data model for the {@link InputSource} and calls
308 * {@link #evaluateExpression(Object item, Class type)} on the resulting
309 * document object.
310 * <P>
311 * By default, the JDK's data model is {@link org.w3c.dom.Document}.
312 *
313 * @implSpec
314 * The default implementation in the XPath API is equivalent to:
315 * <pre> {@code
321 * XPathEvaluationResult as the type will result in IllegalArgumentException.
322 * Any implementation supporting the
323 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
324 * this method.
325 *
326 * @param <T> The class type that will be returned by the XPath expression.
327 * @param source The {@code InputSource} of the document to evaluate over.
328 * @param type The class type expected to be returned by the XPath expression.
329 *
330 * @return The result of evaluating the expression.
331 *
332 * @throws XPathExpressionException If the expression cannot be evaluated.
333 * @throws IllegalArgumentException If {@code type} is not of the types
334 * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType
335 * XPathResultType}, or XPathEvaluationResult is specified as the type but an
336 * implementation supporting the
337 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type
338 * is not available.
339 * @throws NullPointerException If {@code source or type} is {@code null}.
340 *
341 * @since 1.9
342 */
343 default <T>T evaluateExpression(InputSource source, Class<T> type)
344 throws XPathExpressionException
345 {
346 return type.cast(evaluate(source, XPathEvaluationResult.XPathResultType.getQNameType(type)));
347 }
348
349 /**
350 * Evaluate the compiled XPath expression in the specified context. This is
351 * equivalent to calling {@link #evaluateExpression(InputSource source, Class type)}
352 * with type {@link XPathEvaluationResult}:
353 * <pre> {@code
354 * evaluateExpression(source, XPathEvaluationResult.class);
355 * }</pre>
356 *
357 * @implSpec
358 * The default implementation in the XPath API is equivalent to:
359 * <pre> {@code
360 * (XPathEvaluationResult)evaluateExpression(source, XPathEvaluationResult.class);
361 * }</pre>
362 *
363 * Since the {@code evaluate} method does not support the
364 * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
365 * type, the default implementation of this method will always throw an
366 * IllegalArgumentException. Any implementation supporting the
367 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
368 * override this method.
369 *
370 * @param source The {@code InputSource} of the document to evaluate over.
371 *
372 * @return The result of evaluating the expression.
373 *
374 * @throws XPathExpressionException If the expression cannot be evaluated.
375 * @throws IllegalArgumentException If the implementation of this method
376 * does not support the
377 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
378 * @throws NullPointerException If {@code source} is {@code null}.
379 *
380 * @since 1.9
381 */
382 default XPathEvaluationResult<?> evaluateExpression(InputSource source)
383 throws XPathExpressionException
384 {
385 return evaluateExpression(source, XPathEvaluationResult.class);
386 }
387 }
|
229 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type, specifying
230 * XPathEvaluationResult as the type will result in IllegalArgumentException.
231 * Any implementation supporting the
232 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
233 * this method.
234 *
235 * @param <T> The class type that will be returned by the XPath expression.
236 * @param item The context the XPath expression will be evaluated in.
237 * @param type The class type expected to be returned by the XPath expression.
238 *
239 * @return The result of evaluating the expression.
240 *
241 * @throws XPathExpressionException If the expression cannot be evaluated.
242 * @throws IllegalArgumentException If {@code type} is not of the types
243 * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType
244 * XPathResultType}, or XPathEvaluationResult is specified as the type but an
245 * implementation supporting the
246 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type is not available.
247 * @throws NullPointerException If {@code type} is {@code null}.
248 *
249 * @since 9
250 */
251 default <T>T evaluateExpression(Object item, Class<T> type)
252 throws XPathExpressionException
253 {
254 return type.cast(evaluate(item, XPathEvaluationResult.XPathResultType.getQNameType(type)));
255 }
256
257 /**
258 * Evaluate the compiled XPath expression in the specified context. This is
259 * equivalent to calling {@link #evaluateExpression(Object item, Class type)}
260 * with type {@link XPathEvaluationResult}:
261 * <pre> {@code
262 * evaluateExpression(item, XPathEvaluationResult.class);
263 * }</pre>
264 * <p>
265 * The parameter {@code item} represents the context the XPath expression
266 * will be operated on. The type of the context is implementation-dependent.
267 * If the value is {@code null}, the operation must have no dependency on
268 * the context, otherwise an XPathExpressionException will be thrown.
269 *
275 * <pre> {@code
276 * evaluateExpression(item, XPathEvaluationResult.class);
277 * }</pre>
278 *
279 * Since the {@code evaluate} method does not support the
280 * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
281 * type, the default implementation of this method will always throw an
282 * IllegalArgumentException. Any implementation supporting the
283 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
284 * override this method.
285 *
286 * @param item The context the XPath expression will be evaluated in.
287 *
288 * @return The result of evaluating the expression.
289 *
290 * @throws XPathExpressionException If the expression cannot be evaluated.
291 * @throws IllegalArgumentException If the implementation of this method
292 * does not support the
293 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
294 *
295 * @since 9
296 */
297 default XPathEvaluationResult<?> evaluateExpression(Object item)
298 throws XPathExpressionException
299 {
300 return evaluateExpression(item, XPathEvaluationResult.class);
301 }
302
303 /**
304 * Evaluate the compiled XPath expression in the specified context,
305 * and return the result with the type specified through the {@code class type}
306 * <p>
307 * This method builds a data model for the {@link InputSource} and calls
308 * {@link #evaluateExpression(Object item, Class type)} on the resulting
309 * document object.
310 * <P>
311 * By default, the JDK's data model is {@link org.w3c.dom.Document}.
312 *
313 * @implSpec
314 * The default implementation in the XPath API is equivalent to:
315 * <pre> {@code
321 * XPathEvaluationResult as the type will result in IllegalArgumentException.
322 * Any implementation supporting the
323 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must override
324 * this method.
325 *
326 * @param <T> The class type that will be returned by the XPath expression.
327 * @param source The {@code InputSource} of the document to evaluate over.
328 * @param type The class type expected to be returned by the XPath expression.
329 *
330 * @return The result of evaluating the expression.
331 *
332 * @throws XPathExpressionException If the expression cannot be evaluated.
333 * @throws IllegalArgumentException If {@code type} is not of the types
334 * corresponding to the types defined in the {@link XPathEvaluationResult.XPathResultType
335 * XPathResultType}, or XPathEvaluationResult is specified as the type but an
336 * implementation supporting the
337 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type
338 * is not available.
339 * @throws NullPointerException If {@code source or type} is {@code null}.
340 *
341 * @since 9
342 */
343 default <T>T evaluateExpression(InputSource source, Class<T> type)
344 throws XPathExpressionException
345 {
346 return type.cast(evaluate(source, XPathEvaluationResult.XPathResultType.getQNameType(type)));
347 }
348
349 /**
350 * Evaluate the compiled XPath expression in the specified context. This is
351 * equivalent to calling {@link #evaluateExpression(InputSource source, Class type)}
352 * with type {@link XPathEvaluationResult}:
353 * <pre> {@code
354 * evaluateExpression(source, XPathEvaluationResult.class);
355 * }</pre>
356 *
357 * @implSpec
358 * The default implementation in the XPath API is equivalent to:
359 * <pre> {@code
360 * (XPathEvaluationResult)evaluateExpression(source, XPathEvaluationResult.class);
361 * }</pre>
362 *
363 * Since the {@code evaluate} method does not support the
364 * {@link XPathEvaluationResult.XPathResultType#ANY ANY}
365 * type, the default implementation of this method will always throw an
366 * IllegalArgumentException. Any implementation supporting the
367 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type must therefore
368 * override this method.
369 *
370 * @param source The {@code InputSource} of the document to evaluate over.
371 *
372 * @return The result of evaluating the expression.
373 *
374 * @throws XPathExpressionException If the expression cannot be evaluated.
375 * @throws IllegalArgumentException If the implementation of this method
376 * does not support the
377 * {@link XPathEvaluationResult.XPathResultType#ANY ANY} type.
378 * @throws NullPointerException If {@code source} is {@code null}.
379 *
380 * @since 9
381 */
382 default XPathEvaluationResult<?> evaluateExpression(InputSource source)
383 throws XPathExpressionException
384 {
385 return evaluateExpression(source, XPathEvaluationResult.class);
386 }
387 }
|