KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > xpath > XPathExpression


1 // $Id: XPathExpression.java,v 1.10.16.1 2004/07/01 17:49:23 ndw Exp $
2

3 /*
4  * @(#)XPathExpression.java 1.6 04/07/26
5  *
6  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
7  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
8  */

9
10 package javax.xml.xpath;
11
12 import org.xml.sax.InputSource JavaDoc;
13 import javax.xml.namespace.QName JavaDoc;
14
15 /**
16  * <p><code>XPathExpression</code> provides access to compiled XPath expressions.</p>
17  *
18  * <table id="XPathExpression-evaluation" border="1" cellpadding="2">
19  * <thead>
20  * <tr>
21  * <th colspan="2">Evaluation of XPath Expressions.</th>
22  * </tr>
23  * </thead>
24  * <tbody>
25  * <tr>
26  * <td>context</td>
27  * <td>
28  * If a request is made to evaluate the expression in the absence
29  * of a context item, an empty document node will be used for the context.
30  * For the purposes of evaluating XPath expressions, a DocumentFragment
31  * is treated like a Document node.
32  * </td>
33  * </tr>
34  * <tr>
35  * <td>variables</td>
36  * <td>
37  * If the expression contains a variable reference, its value will be found through the {@link XPathVariableResolver}.
38  * An {@link XPathExpressionException} is raised if the variable resolver is undefined or
39  * the resolver returns <code>null</code> for the variable.
40  * The value of a variable must be immutable through the course of any single evaluation.</p>
41  * </td>
42  * </tr>
43  * <tr>
44  * <td>functions</td>
45  * <td>
46  * If the expression contains a function reference, the function will be found through the {@link XPathFunctionResolver}.
47  * An {@link XPathExpressionException} is raised if the function resolver is undefined or
48  * the function resolver returns <code>null</code> for the function.</p>
49  * </td>
50  * </tr>
51  * <tr>
52  * <td>QNames</td>
53  * <td>
54  * QNames in the expression are resolved against the XPath namespace context.
55  * </td>
56  * </tr>
57  * <tr>
58  * <td>result</td>
59  * <td>
60  * This result of evaluating an expression is converted to an instance of the desired return type.
61  * Valid return types are defined in {@link XPathConstants}.
62  * Conversion to the return type follows XPath conversion rules.</p>
63  * </td>
64  * </tr>
65  * </table>
66  *
67  * @author <a HREF="mailto:Norman.Walsh@Sun.com">Norman Walsh</a>
68  * @author <a HREF="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
69  * @version $Revision: 1.10.16.1 $, $Date: 2004/07/01 17:49:23 $
70  * @see <a HREF="http://www.w3.org/TR/xpath#section-Expressions">XML Path Language (XPath) Version 1.0, Expressions</a>
71  * @since 1.5
72  */

73 public interface XPathExpression {
74     
75     /**
76      * <p>Evaluate the compiled XPath expression in the specified context and return the result as the specified type.</p>
77      *
78      * <p>See <a HREF="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
79      * variable, function and QName resolution and return type conversion.</p>
80      *
81      * <p>If <code>returnType</code> is not one of the types defined in {@link XPathConstants},
82      * then an <code>IllegalArgumentException</code> is thrown.</p>
83      *
84      * <p>If a <code>null</code> value is provided for
85      * <code>item</code>, an empty document will be used for the
86      * context.
87      * If <code>returnType</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p>
88      *
89      * @param item The starting context (node or node list, for example).
90      * @param returnType The desired return type.
91      *
92      * @return The <code>Object</code> that is the result of evaluating the expression and converting the result to
93      * <code>returnType</code>.
94      *
95      * @throws XPathExpressionException If the expression cannot be evaluated.
96      * @throws IllegalArgumentException If <code>returnType</code> is not one of the types defined in {@link XPathConstants}.
97      * @throws NullPointerException If <code>returnType</code> is <code>null</code>.
98      */

99     public Object JavaDoc evaluate(Object JavaDoc item, QName JavaDoc returnType)
100         throws XPathExpressionException JavaDoc;
101
102     /**
103      * <p>Evaluate the compiled XPath expression in the specified context and return the result as a <code>String</code>.</p>
104      *
105      * <p>This method calls {@link #evaluate(Object item, QName returnType)} with a <code>returnType</code> of
106      * {@link XPathConstants#STRING}.</p>
107      *
108      * <p>See <a HREF="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
109      * variable, function and QName resolution and return type conversion.</p>
110      *
111      * <p>If a <code>null</code> value is provided for
112      * <code>item</code>, an empty document will be used for the
113      * context.
114      *
115      * @param item The starting context (node or node list, for example).
116      *
117      * @return The <code>String</code> that is the result of evaluating the expression and converting the result to a
118      * <code>String</code>.
119      *
120      * @throws XPathExpressionException If the expression cannot be evaluated.
121      */

122     public String JavaDoc evaluate(Object JavaDoc item)
123         throws XPathExpressionException JavaDoc;
124
125     /**
126      * <p>Evaluate the compiled XPath expression in the context of the specified <code>InputSource</code> and return the result as the
127      * specified type.</p>
128      *
129      * <p>This method builds a data model for the {@link InputSource} and calls
130      * {@link #evaluate(Object item, QName returnType)} on the resulting document object.</p>
131      *
132      * <p>See <a HREF="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
133      * variable, function and QName resolution and return type conversion.</p>
134      *
135      * <p>If <code>returnType</code> is not one of the types defined in {@link XPathConstants},
136      * then an <code>IllegalArgumentException</code> is thrown.</p>
137      *
138      * <p>If <code>source</code> or <code>returnType</code> is <code>null</code>,
139      * then a <code>NullPointerException</code> is thrown.</p>
140      *
141      * @param source The <code>InputSource</code> of the document to evaluate over.
142      * @param returnType The desired return type.
143      *
144      * @return The <code>Object</code> that is the result of evaluating the expression and converting the result to
145      * <code>returnType</code>.
146      *
147      * @throws XPathExpressionException If the expression cannot be evaluated.
148      * @throws IllegalArgumentException If <code>returnType</code> is not one of the types defined in {@link XPathConstants}.
149      * @throws NullPointerException If <code>source</code> or <code>returnType</code> is <code>null</code>.
150      */

151     public Object JavaDoc evaluate(InputSource JavaDoc source, QName JavaDoc returnType)
152         throws XPathExpressionException JavaDoc;
153     
154     /**
155      * <p>Evaluate the compiled XPath expression in the context of the specified <code>InputSource</code> and return the result as a
156      * <code>String</code>.</p>
157      *
158      * <p>This method calls {@link #evaluate(InputSource source, QName returnType)} with a <code>returnType</code> of
159      * {@link XPathConstants#STRING}.</p>
160      *
161      * <p>See <a HREF="#XPathExpression-evaluation">Evaluation of XPath Expressions</a> for context item evaluation,
162      * variable, function and QName resolution and return type conversion.</p>
163      *
164      * <p>If <code>source</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p>
165      *
166      * @param source The <code>InputSource</code> of the document to evaluate over.
167      *
168      * @return The <code>String</code> that is the result of evaluating the expression and converting the result to a
169      * <code>String</code>.
170      *
171      * @throws XPathExpressionException If the expression cannot be evaluated.
172      * @throws NullPointerException If <code>source</code> is <code>null</code>.
173      */

174     public String JavaDoc evaluate(InputSource JavaDoc source)
175         throws XPathExpressionException JavaDoc;
176 }
177
Popular Tags