Module jakarta.el
Package jakarta.el

Class ExpressionFactory

java.lang.Object
jakarta.el.ExpressionFactory

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(jakarta.el.ELContext, java.lang.String, java.lang.Class<?>) method is used to parse expressions that evaluate to values (both l-values and r-values are supported). The createMethodExpression(jakarta.el.ELContext, java.lang.String, java.lang.Class<?>, java.lang.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:
Jakarta Server Pages 2.1