ExpressionEvaluator (Java EE 5)

Java EE API


javax.servlet.jsp.el Class ExpressionEvaluator

java.lang.Object
  extended by javax.servlet.jsp.el.ExpressionEvaluator

Deprecated. As of JSP 2.1, replaced by ExpressionFactory


表达式语言计算器的抽象基类。实现表达式语言的类通过此抽象类公开其功能。

ExpressionEvaluator 实例可通过 JspContext / PageContext 获得。

parseExpression() 和 evaluate() 方法必须是线程安全的。也就是说,多个线程可以对同一 ExpressionEvaluator 对象同时调用这些方法。如果实现依赖于 transient 状态,那么它们应该使访问同步。但是,实现不应假定每种 ExpressionEvaluator 类型中只有一个对象将被实例化;因此,全局缓存应该是静态的。

一次只能解析或求值一个以 '${' 开头并以 '}' 结尾的 EL 表达式。EL 表达式无法与静态文本混合。例如,试图解析或求值 "abc${1+1}def${1+1}ghi" 或者甚至 "${1+1}${1+1}" 将导致抛出 ELException

以下是具有合法语法的 EL 表达式的示例:

  • ${person.lastName}
  • ${8 * 8}
  • ${my:reverse('hello')}

英文文档:

public abstract class ExpressionEvaluator
extends Object

The abstract base class for an expression-language evaluator. Classes that implement an expression language expose their functionality via this abstract class.

An instance of the ExpressionEvaluator can be obtained via the JspContext / PageContext

The parseExpression() and evaluate() methods must be thread-safe. That is, multiple threads may call these methods on the same ExpressionEvaluator object simultaneously. Implementations should synchronize access if they depend on transient state. Implementations should not, however, assume that only one object of each ExpressionEvaluator type will be instantiated; global caching should therefore be static.

Only a single EL expression, starting with '${' and ending with '}', can be parsed or evaluated at a time. EL expressions cannot be mixed with static text. For example, attempting to parse or evaluate "abc${1+1}def${1+1}ghi" or even "${1+1}${1+1}" will cause an ELException to be thrown.

The following are examples of syntactically legal EL expressions:

  • ${person.lastName}
  • ${8 * 8}
  • ${my:reverse('hello')}

Since:
JSP 2.0

Constructor Summary
 
Method Summary
abstract  Object
abstract  Expression
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public ExpressionEvaluator()
英文文档:

ExpressionEvaluator

public ExpressionEvaluator()
Deprecated. 
Method Detail

abstract public Expression parseExpression(String expression, Class<T> expectedType, FunctionMapper fMapper) throws ELException
为以后的求值准备表达式。此方法应对表达式执行语法验证;如果执行验证时检测到错误,则将引发 ELParseException。
expression 要求值的表达式。
expectedType 求值结果的期望类型
fMapper 用来解析表达式中发现的函数的 FunctionMapper。它可以为 null,这种情况下此调用不支持任何函数。在从 parseExpression() 返回之后,ExpressionEvaluator 不得占用 FunctionMapper 引用。返回的 Expression 对象必须调用相同的函数,不管提供的 FunctionMapper 实例中的映射在调用 ExpressionEvaluator.parseExpression()Expression.evaluate() 之间是否发生更改。
return 封装参数的 Expression 对象。
ThrowsELException: 如果发现解析错误,则抛出此异常。
英文文档:

parseExpression

public abstract Expression parseExpression(String expression,
                                           Class expectedType,
                                           FunctionMapper fMapper)
                                    throws ELException
Deprecated. 
Prepare an expression for later evaluation. This method should perform syntactic validation of the expression; if in doing so it detects errors, it should raise an ELParseException.

Parameters:
expression - The expression to be evaluated.
expectedType - The expected type of the result of the evaluation
fMapper - A FunctionMapper to resolve functions found in the expression. It can be null, in which case no functions are supported for this invocation. The ExpressionEvaluator must not hold on to the FunctionMapper reference after returning from parseExpression(). The Expression object returned must invoke the same functions regardless of whether the mappings in the provided FunctionMapper instance change between calling ExpressionEvaluator.parseExpression() and Expression.evaluate().
Returns:
The Expression object encapsulating the arguments.
Throws:
ELException - Thrown if parsing errors were found.

abstract public Object evaluate(String expression, Class<T> expectedType, VariableResolver vResolver, FunctionMapper fMapper) throws ELException
对表达式求值。此方法可能执行一些语法验证,如果执行语法验证,那么它在遇到语法错误时将引发 ELParseException 错误。EL 求值错误将导致引发 ELException。
expression 要求值的表达式。
expectedType 求值结果的期望类型
vResolver 一个 VariableResolver 实例,可在运行时使用它将隐式对象的名称解析为 Objects。
fMapper 用来解析表达式中发现的函数的 FunctionMapper。它可以为 null,这种情况下此调用不支持任何函数。
return 表达式求值的结果。
ThrowsELException: 如果表达式求值失败,则抛出此异常。
英文文档:

evaluate

public abstract Object evaluate(String expression,
                                Class expectedType,
                                VariableResolver vResolver,
                                FunctionMapper fMapper)
                         throws ELException
Deprecated. 
Evaluates an expression. This method may perform some syntactic validation and, if so, it should raise an ELParseException error if it encounters syntactic errors. EL evaluation errors should cause an ELException to be raised.

Parameters:
expression - The expression to be evaluated.
expectedType - The expected type of the result of the evaluation
vResolver - A VariableResolver instance that can be used at runtime to resolve the name of implicit objects into Objects.
fMapper - A FunctionMapper to resolve functions found in the expression. It can be null, in which case no functions are supported for this invocation.
Returns:
The result of the expression evaluation.
Throws:
ELException - Thrown if the expression evaluation failed.


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!