ExpressionFactorypublic abstract class ExpressionFactory extends Object Parses a String into a {@link ValueExpression} or
{@link MethodExpression} instance for later evaluation.
Classes that implement the EL expression language expose their
functionality via this abstract class.
The {@link #newInstance} method can be used to obtain an
instance of the implementation.
Technologies such as
JavaServer Pages and JavaServer Faces provide access to an
implementation via factory methods.
The {@link #createValueExpression} method is used to parse expressions
that evaluate to values (both l-values and r-values are supported).
The {@link #createMethodExpression} method is used to parse expressions
that evaluate to a reference to a method on an object.
Unlike previous incarnations of this API, there is no way to parse
and evaluate an expression in one single step. The expression needs to first
be parsed, and then evaluated.
Resolution of model objects is performed at evaluation time, via the
{@link ELResolver} associated with the {@link ELContext} passed to
the ValueExpression or MethodExpression .
The ELContext object also provides access to the {@link FunctionMapper}
and {@link VariableMapper} to be used when parsing the expression.
EL function and variable mapping is performed at parse-time, and
the results are
bound to the expression. Therefore, the {@link ELContext},
{@link FunctionMapper},
and {@link VariableMapper}
are not stored for future use and do not have to be
Serializable .
The createValueExpression and
createMethodExpression methods must be thread-safe. That is,
multiple threads may call these methods on the same
ExpressionFactory object simultaneously. Implementations
should synchronize access if they depend on transient state.
Implementations should not, however, assume that only one object of
each ExpressionFactory type will be instantiated; global
caching should therefore be static.
The ExpressionFactory must be able to handle the following
types of input for the expression parameter:
- Single expressions using the
${} delimiter
(e.g. "${employee.lastName}" ).
- Single expressions using the
#{} delimiter
(e.g. "#{employee.lastName}" ).
- Literal text containing no
${} or #{}
delimiters (e.g. "John Doe" ).
- Multiple expressions using the same delimiter (e.g.
"${employee.firstName}${employee.lastName}" or
"#{employee.firstName}#{employee.lastName}" ).
- Mixed literal text and expressions using the same delimiter (e.g.
"Name: ${employee.firstName} ${employee.lastName}" ).
The following types of input are illegal and must cause an
{@link ELException} to be thrown:
- Multiple expressions using different delimiters (e.g.
"${employee.firstName}#{employee.lastName}" ).
- Mixed literal text and expressions using different delimiters(e.g.
"Name: ${employee.firstName} #{employee.lastName}" ).
|
Methods Summary |
---|
public abstract java.lang.Object | coerceToType(java.lang.Object obj, java.lang.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.
| public abstract javax.el.MethodExpression | createMethodExpression(javax.el.ELContext context, java.lang.String expression, java.lang.Class expectedReturnType, java.lang.Class[] expectedParamTypes)Parses an expression into a {@link 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 .
| public abstract javax.el.ValueExpression | createValueExpression(javax.el.ELContext context, java.lang.String expression, java.lang.Class expectedType)Parses an expression into a {@link 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 .
| public abstract javax.el.ValueExpression | createValueExpression(java.lang.Object instance, java.lang.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.
| public static javax.el.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.
return ExpressionFactory.newInstance(null);
| public static javax.el.ExpressionFactory | newInstance(java.util.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.
return (ExpressionFactory) FactoryFinder.find(
"javax.el.ExpressionFactory",
"com.sun.el.ExpressionFactoryImpl",
properties);
|
|