KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > servlet > jsp > el > ExpressionEvaluator


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */

17
18 package javax.servlet.jsp.el;
19
20
21 /**
22  * <p>The abstract base class for an expression-language evaluator.
23  * Classes that implement an expression language expose their functionality
24  * via this abstract class.</p>
25  *
26  * <p>An instance of the ExpressionEvaluator can be obtained via the
27  * JspContext / PageContext</p>
28  *
29  * <p>The parseExpression() and evaluate() methods must be thread-safe.
30  * That is, multiple threads may call these methods on the same
31  * ExpressionEvaluator object simultaneously. Implementations should
32  * synchronize access if they depend on transient state. Implementations
33  * should not, however, assume that only one object of each
34  * ExpressionEvaluator type will be instantiated; global caching should
35  * therefore be static.</p>
36  *
37  * <p>Only a single EL expression, starting with '${' and ending with
38  * '}', can be parsed or evaluated at a time. EL expressions
39  * cannot be mixed with static text. For example, attempting to
40  * parse or evaluate "<code>abc${1+1}def${1+1}ghi</code>" or even
41  * "<code>${1+1}${1+1}</code>" will cause an <code>ELException</code> to
42  * be thrown.</p>
43  *
44  * <p>The following are examples of syntactically legal EL expressions:
45  *
46  * <ul>
47  * <li><code>${person.lastName}</code></li>
48  * <li><code>${8 * 8}</code></li>
49  * <li><code>${my:reverse('hello')}</code></li>
50  * </ul>
51  * </p>
52  *
53  * @since 2.0
54  * @deprecated
55  */

56 public abstract class ExpressionEvaluator {
57
58     /**
59      * Prepare an expression for later evaluation. This method should perform
60      * syntactic validation of the expression; if in doing so it detects
61      * errors, it should raise an ELParseException.
62      *
63      * @param expression The expression to be evaluated.
64      * @param expectedType The expected type of the result of the evaluation
65      * @param fMapper A FunctionMapper to resolve functions found in
66      * the expression. It can be null, in which case no functions
67      * are supported for this invocation. The ExpressionEvaluator
68      * must not hold on to the FunctionMapper reference after
69      * returning from <code>parseExpression()</code>. The
70      * <code>Expression</code> object returned must invoke the same
71      * functions regardless of whether the mappings in the
72      * provided <code>FunctionMapper</code> instance change between
73      * calling <code>ExpressionEvaluator.parseExpression()</code>
74      * and <code>Expression.evaluate()</code>.
75      * @return The Expression object encapsulating the arguments.
76      *
77      * @exception ELException Thrown if parsing errors were found.
78      */

79     public abstract Expression JavaDoc parseExpression( String JavaDoc expression,
80                        Class JavaDoc expectedType,
81                        FunctionMapper JavaDoc fMapper )
82       throws ELException JavaDoc;
83
84
85     /**
86      * Evaluates an expression. This method may perform some syntactic
87      * validation and, if so, it should raise an ELParseException error if
88      * it encounters syntactic errors. EL evaluation errors should cause
89      * an ELException to be raised.
90      *
91      * @param expression The expression to be evaluated.
92      * @param expectedType The expected type of the result of the evaluation
93      * @param vResolver A VariableResolver instance that can be used at
94      * runtime to resolve the name of implicit objects into Objects.
95      * @param fMapper A FunctionMapper to resolve functions found in
96      * the expression. It can be null, in which case no functions
97      * are supported for this invocation.
98      * @return The result of the expression evaluation.
99      *
100      * @exception ELException Thrown if the expression evaluation failed.
101      */

102     public abstract Object JavaDoc evaluate( String JavaDoc expression,
103                 Class JavaDoc expectedType,
104                 VariableResolver JavaDoc vResolver,
105                 FunctionMapper JavaDoc fMapper )
106       throws ELException JavaDoc;
107 }
108
109
Popular Tags