Class ExpressionFactory

java.lang.Object
org.flowable.common.engine.impl.javax.el.ExpressionFactory
Direct Known Subclasses:
ExpressionFactoryImpl

public abstract class ExpressionFactory extends Object
Provides an implementation for creating and evaluating Jakarta Expression Language expressions.

Classes that implement the Jakarta Expression Language expression language expose their functionality via this abstract class. An implementation supports the following functionalities.

  • Parses a String into a ValueExpression or MethodExpression instance for later evaluation.
  • Implements an ELResolver for 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 Details

    • ExpressionFactory

      public ExpressionFactory()
  • Method Details

    • newInstance

      public static ExpressionFactory newInstance()
      Create a new ExpressionFactory. The class to use is determined by the following search order:
      1. services API (META-INF/services/ExpressionFactory)
      2. $JRE_HOME/lib/el.properties - key ExpressionFactory
      3. ExpressionFactory
      4. Platform default implementation - org.flowable.common.engine.impl.de.odysseus.el.ExpressionFactoryImpl
      Returns:
      the new ExpressionFactory
    • newInstance

      public static ExpressionFactory newInstance(Properties properties)
      Create a new ExpressionFactory passing in the provided Properties. Search order is the same as newInstance().
      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 evaluation
      expression - The String representation of the value expression
      expectedType - 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 is null
      ELException - If there are syntax errors in the provided expression
    • createValueExpression

      public abstract ValueExpression createValueExpression(Object instance, Class<?> expectedType)
    • 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 evaluation
      expression - The String representation of the method expression
      expectedReturnType - The expected type of the result of invoking the method
      expectedParamTypes - The expected types of the input parameters
      Returns:
      A new method expression formed from the input parameters.
      Throws:
      NullPointerException - If the expected parameters types are null
      ELException - If there are syntax errors in the provided expression
    • coerceToType

      public abstract <T> T coerceToType(Object obj, Class<T> expectedType)
      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 coerced
      expectedType - The type to which the object should be coerced
      Returns:
      An instance of the requested type.
      Throws:
      ELException - If the conversion fails
    • getStreamELResolver

      public ELResolver getStreamELResolver()
      Retrieves an ELResolver that implements the operations in collections.

      This ELResolver resolves the method invocation on the pair (base, property) when base is a Collection or a Map, and property is the name of the operation.

      See the specification document for detailed descriptions of these operators, their arguments, and return values.

      Returns:
      The ELResolver that implements the Query Operators.
      Since:
      Jakarta Expression Language 3.0
    • getInitFunctionMap

      public Map<String,Method> getInitFunctionMap()
      Retrieve a function map containing a pre-configured function mapping.
      Returns:
      A initial map for functions, null if there is none.
      Since:
      Jakarta Expression Language 3.0