Class ExpressionFactory
- Direct Known Subclasses:
ExpressionFactoryImpl
Classes that implement the Jakarta Expression Language expression language expose their functionality via this abstract class. An implementation supports the following functionalities.
- Parses a
Stringinto aValueExpressionorMethodExpressioninstance for later evaluation. - Implements an
ELResolverfor query operators - Provides a default type coercion
The newInstance() method can be used to obtain an instance of the implementation. Technologies such as
Jakarta Server Pages and Jakarta Faces provide access to an implementation via factory methods.
The createValueExpression(ELContext, String, Class) method is used to parse expressions that evaluate to values (both l-values and
r-values are supported). The createMethodExpression(ELContext, String, Class, Class[]) method is used to parse expressions that evaluate to a
reference to a method on an object.
Resolution of model objects is performed at evaluation time, via the ELResolver associated with the
ELContext passed to the ValueExpression or MethodExpression.
The ELContext object also provides access to the FunctionMapper and VariableMapper to be used when
parsing the expression. Jakarta Expression Language function and variable mapping is performed at parse-time, and the
results are bound to the expression. Therefore, the ELContext, FunctionMapper, and
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 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}").
- Since:
- 2.1
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract <T> TcoerceToType(Object obj, Class<T> expectedType) Coerce the supplied object to the requested type.abstract MethodExpressioncreateMethodExpression(ELContext context, String expression, Class<?> expectedReturnType, Class<?>[] expectedParamTypes) Create a new method expression instance.abstract ValueExpressioncreateValueExpression(Object instance, Class<?> expectedType) abstract ValueExpressioncreateValueExpression(ELContext context, String expression, Class<?> expectedType) Create a new value expression.Retrieve a function map containing a pre-configured function mapping.Retrieves an ELResolver that implements the operations in collections.static ExpressionFactoryCreate a newExpressionFactory.static ExpressionFactorynewInstance(Properties properties) Create a newExpressionFactorypassing in the providedProperties.
-
Constructor Details
-
ExpressionFactory
public ExpressionFactory()
-
-
Method Details
-
newInstance
Create a newExpressionFactory. The class to use is determined by the following search order:- services API (META-INF/services/ExpressionFactory)
- $JRE_HOME/lib/el.properties - key ExpressionFactory
- ExpressionFactory
- Platform default implementation - org.flowable.common.engine.impl.de.odysseus.el.ExpressionFactoryImpl
- Returns:
- the new ExpressionFactory
-
newInstance
Create a newExpressionFactorypassing in the providedProperties. Search order is the same asnewInstance().- Parameters:
properties- the properties to be passed to the new instance (might be null)- Returns:
- the new ExpressionFactory
-
createValueExpression
public abstract ValueExpression createValueExpression(ELContext context, String expression, Class<?> expectedType) Create a new value expression.- Parameters:
context- The EL context for this evaluationexpression- The String representation of the value expressionexpectedType- The expected type of the result of evaluating the expression- Returns:
- A new value expression formed from the input parameters
- Throws:
NullPointerException- If the expected type isnullELException- If there are syntax errors in the provided expression
-
createValueExpression
-
createMethodExpression
public abstract MethodExpression createMethodExpression(ELContext context, String expression, Class<?> expectedReturnType, Class<?>[] expectedParamTypes) Create a new method expression instance.- Parameters:
context- The EL context for this evaluationexpression- The String representation of the method expressionexpectedReturnType- The expected type of the result of invoking the methodexpectedParamTypes- The expected types of the input parameters- Returns:
- A new method expression formed from the input parameters.
- Throws:
NullPointerException- If the expected parameters types arenullELException- If there are syntax errors in the provided expression
-
coerceToType
Coerce the supplied object to the requested type.- Type Parameters:
T- The type to which the object should be coerced- Parameters:
obj- The object to be coercedexpectedType- The type to which the object should be coerced- Returns:
- An instance of the requested type.
- Throws:
ELException- If the conversion fails
-
getStreamELResolver
Retrieves an ELResolver that implements the operations in collections.This ELResolver resolves the method invocation on the pair (
base,property) whenbaseis aCollectionor aMap, andpropertyis the name of the operation.See the specification document for detailed descriptions of these operators, their arguments, and return values.
- Returns:
- The
ELResolverthat implements the Query Operators. - Since:
- Jakarta Expression Language 3.0
-
getInitFunctionMap
-