Skip to content

Package: ExpressionEvaluator

ExpressionEvaluator

nameinstructionbranchcomplexitylinemethod
ExpressionEvaluator()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2020 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: * Copyright 2004 The Apache Software Foundation
5: *
6: * Licensed under the Apache License, Version 2.0 (the "License");
7: * you may not use this file except in compliance with the License.
8: * You may obtain a copy of the License at
9: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package jakarta.servlet.jsp.el;
20:
21: /**
22: * <p>
23: * The abstract base class for an expression-language evaluator. Classes that implement an expression language expose
24: * their functionality via this abstract class.
25: * </p>
26: *
27: * <p>
28: * An instance of the ExpressionEvaluator can be obtained via the JspContext / PageContext
29: * </p>
30: *
31: * <p>
32: * The parseExpression() and evaluate() methods must be thread-safe. That is, multiple threads may call these methods on
33: * the same ExpressionEvaluator object simultaneously. Implementations should synchronize access if they depend on
34: * transient state. Implementations should not, however, assume that only one object of each ExpressionEvaluator type
35: * will be instantiated; global caching should therefore be static.
36: * </p>
37: *
38: * <p>
39: * Only a single EL expression, starting with '${' and ending with '}', can be parsed or evaluated at a time. EL
40: * expressions cannot be mixed with static text. For example, attempting to parse or evaluate
41: * "<code>abc${1+1}def${1+1}ghi</code>" or even "<code>${1+1}${1+1}</code>" will cause an <code>ELException</code> to be
42: * thrown.
43: * </p>
44: *
45: * <p>
46: * The following are examples of syntactically legal EL expressions:
47: * </p>
48: *
49: * <ul>
50: * <li><code>${person.lastName}</code></li>
51: * <li><code>${8 * 8}</code></li>
52: * <li><code>${my:reverse('hello')}</code></li>
53: * </ul>
54: *
55: * @deprecated As of JSP 2.1, replaced by {@link jakarta.el.ExpressionFactory}
56: * @since JSP 2.0
57: */
58: @Deprecated
59: public abstract class ExpressionEvaluator {
60:
61: /**
62: * Prepare an expression for later evaluation. This method should perform syntactic validation of the expression; if
63: * in doing so it detects errors, it should raise an ELParseException.
64: *
65: * @param expression The expression to be evaluated.
66: * @param expectedType The expected type of the result of the evaluation
67: * @param fMapper A FunctionMapper to resolve functions found in the expression. It can be null, in which case
68: * no functions are supported for this invocation. The ExpressionEvaluator must not hold on to
69: * the FunctionMapper reference after returning from <code>parseExpression()</code>. The
70: * <code>Expression</code> object returned must invoke the same functions regardless of whether
71: * the mappings in the provided <code>FunctionMapper</code> instance change between calling
72: * <code>ExpressionEvaluator.parseExpression()</code> and <code>Expression.evaluate()</code>.
73: * @return The Expression object encapsulating the arguments.
74: *
75: * @exception ELException Thrown if parsing errors were found.
76: */
77: public abstract Expression parseExpression(String expression, Class<?> expectedType, FunctionMapper fMapper)
78: throws ELException;
79:
80: /**
81: * Evaluates an expression. This method may perform some syntactic validation and, if so, it should raise an
82: * ELParseException error if it encounters syntactic errors. EL evaluation errors should cause an ELException to be
83: * raised.
84: *
85: * @param expression The expression to be evaluated.
86: * @param expectedType The expected type of the result of the evaluation
87: * @param vResolver A VariableResolver instance that can be used at runtime to resolve the name of implicit
88: * objects into Objects.
89: * @param fMapper A FunctionMapper to resolve functions found in the expression. It can be null, in which case
90: * no functions are supported for this invocation.
91: * @return The result of the expression evaluation.
92: *
93: * @exception ELException Thrown if the expression evaluation failed.
94: */
95: public abstract Object evaluate(String expression, Class<?> expectedType, VariableResolver vResolver,
96: FunctionMapper fMapper) throws ELException;
97: }