ExpressionFactory (Java EE 5)

Java EE API


javax.el Class ExpressionFactory

java.lang.Object
  extended by javax.el.ExpressionFactory

public abstract class ExpressionFactory
extends Object


英文文档:


Constructor Summary
 
Method Summary
abstract  Object
abstract  MethodExpression
abstract  ValueExpression
abstract  ValueExpression
static ExpressionFactory
static ExpressionFactory
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public ExpressionFactory()
英文文档:

ExpressionFactory

public ExpressionFactory()
Method Detail

public static ExpressionFactory newInstance()
创建 ExpressionFactory 的新实例。此方法使用以下查找过程顺序来确定要加载的 ExpressionFactory 实现类:
  • 使用 Services API(在 JAR 规范中进行了详细描述)。如果存在名为 META-INF/services/javax.el.ExpressionFactory 的资源,则它的第一行(如果存在)被用作实现类的 UTF-8 编码名称。
  • 使用 JRE 目录中的属性文件 "lib/el.properties"。如果存在此文件,且可以通过 java.util.Properties.load(InputStream) 方法读取它,并且该文件包含键为 "javax.el.ExpressionFactory" 的条目,则该条目的值被用作实现类的名称。
  • 使用 javax.el.ExpressionFactory 系统属性。如果定义了此名称的系统属性,则它的值被用作实现类的名称。
  • 使用平台的默认实现。
英文文档:

newInstance

public static ExpressionFactory newInstance()
Creates a new instance of a ExpressionFactory. This method uses the following ordered lookup procedure to determine the ExpressionFactory implementation class to load:
  • Use the Services API (as detailed in the JAR specification). If a resource with the name of META-INF/services/javax.el.ExpressionFactory exists, then its first line, if present, is used as the UTF-8 encoded name of the implementation class.
  • Use the properties file "lib/el.properties" in the JRE directory. If this file exists and it is readable by the java.util.Properties.load(InputStream) method, and it contains an entry whose key is "javax.el.ExpressionFactory", then the value of that entry is used as the name of the implementation class.
  • Use the javax.el.ExpressionFactory system property. If a system property with this name is defined, then its value is used as the name of the implementation class.
  • Use a platform default implementation.


public static ExpressionFactory newInstance(java.util.Properties properties)

创建具有可选属性的新 ExpressionFactory 实例。此方法使用与 newInstance() 相同的查找过程。

如果参数 properties 不为 null,并且实现包含具有单一参数类型 java.util.Properties 的构造方法,则使用该构造方法创建实例。

属性是可选的,并且可以被实现忽略。

属性名称应该以 "javax.el" 开头。

下面是属性的一些建议名称。

  • javax.el.cacheSize

properties 传递给实现的属性。如果为 null,则没有属性。
英文文档:

newInstance

public static ExpressionFactory newInstance(Properties properties)

Create a new instance of a ExpressionFactory, with optional properties. This method uses the same lookup procedure as the one used in newInstance().

If the argument properties is not null, and if the implementation contains a constructor with a single parameter of type java.util.Properties, then the constructor is used to create the instance.

Properties are optional and can be ignored by an implementation.

The name of a property should start with "javax.el."

The following are some suggested names for properties.

  • javax.el.cacheSize

Parameters:
properties - Properties passed to the implementation. If null, then no properties.

英文文档:

createValueExpression

public abstract ValueExpression createValueExpression(ELContext context,
                                                      String expression,
                                                      Class<?> expectedType)
Parses an expression into a ValueExpression for later evaluation. Use this method for expressions that refer to values.

This method should perform syntactic validation of the expression. If in doing so it detects errors, it should raise an ELException.

Parameters:
context - The EL context used to parse the expression. The FunctionMapper and VariableMapper stored in the ELContext are used to resolve functions and variables found in the expression. They can be null, in which case functions or variables are not supported for this expression. The object returned must invoke the same functions and access the same variable mappings regardless of whether the mappings in the provided FunctionMapper and VariableMapper instances change between calling ExpressionFactory.createValueExpression() and any method on ValueExpression.

Note that within the EL, the ${} and #{} syntaxes are treated identically. This includes the use of VariableMapper and FunctionMapper at expression creation time. Each is invoked if not null, independent of whether the #{} or ${} syntax is used for the expression.

expression - The expression to parse
expectedType - The type the result of the expression will be coerced to after evaluation.
Returns:
The parsed expression
Throws:
NullPointerException - Thrown if expectedType is null.
ELException - Thrown if there are syntactical errors in the provided expression.

英文文档:

createValueExpression

public abstract ValueExpression createValueExpression(Object instance,
                                                      Class<?> expectedType)
Creates a ValueExpression that wraps an object instance. This method can be used to pass any object as a ValueExpression. The wrapper ValueExpression is read only, and returns the wrapped object via its getValue() method, optionally coerced.

Parameters:
instance - The object instance to be wrapped.
expectedType - The type the result of the expression will be coerced to after evaluation. There will be no coercion if it is Object.class,
Throws:
NullPointerException - Thrown if expectedType is null.

英文文档:

createMethodExpression

public abstract MethodExpression createMethodExpression(ELContext context,
                                                        String expression,
                                                        Class<?> expectedReturnType,
                                                        Class<?>[] expectedParamTypes)
Parses an expression into a MethodExpression for later evaluation. Use this method for expressions that refer to methods.

If the expression is a String literal, a MethodExpression is created, which when invoked, returns the String literal, coerced to expectedReturnType. An ELException is thrown if expectedReturnType is void or if the coercion of the String literal to the expectedReturnType yields an error (see Section "1.16 Type Conversion").

This method should perform syntactic validation of the expression. If in doing so it detects errors, it should raise an ELException.

Parameters:
context - The EL context used to parse the expression. The FunctionMapper and VariableMapper stored in the ELContext are used to resolve functions and variables found in the expression. They can be null, in which case functions or variables are not supported for this expression. The object returned must invoke the same functions and access the same variable mappings regardless of whether the mappings in the provided FunctionMapper and VariableMapper instances change between calling ExpressionFactory.createMethodExpression() and any method on MethodExpression.

Note that within the EL, the ${} and #{} syntaxes are treated identically. This includes the use of VariableMapper and FunctionMapper at expression creation time. Each is invoked if not null, independent of whether the #{} or ${} syntax is used for the expression.

expression - The expression to parse
expectedReturnType - The expected return type for the method to be found. After evaluating the expression, the MethodExpression must check that the return type of the actual method matches this type. Passing in a value of null indicates the caller does not care what the return type is, and the check is disabled.
expectedParamTypes - The expected parameter types for the method to be found. Must be an array with no elements if there are no parameters expected. It is illegal to pass null.
Returns:
The parsed expression
Throws:
ELException - Thrown if there are syntactical errors in the provided expression.
NullPointerException - if paramTypes is null.

英文文档:

coerceToType

public abstract Object coerceToType(Object obj,
                                    Class<?> targetType)
Coerces an object to a specific type according to the EL type conversion rules.

An ELException is thrown if an error results from applying the conversion rules.

Parameters:
obj - The object to coerce.
targetType - The target type for the coercion.
Throws:
ELException - thrown if an error results from applying the conversion rules.


Submit a bug or feature

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

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

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