Class ELContext
java.lang.Object
jakarta.el.ELContext
- Direct Known Subclasses:
StandardELContext
Provides the context in which an EL expression is evaluated. An ELContext holds references to the
ELResolver, FunctionMapper, VariableMapper, ImportHandler, locale, and other
objects required for expression evaluation. Implementations include StandardELContext.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEvaluationListener(EvaluationListener listener) Register an EvaluationListener with this ELContext.<T> TconvertToType(Object obj, Class<T> type) Coerce the supplied object to the requested type.voidenterLambdaScope(Map<String, Object> arguments) Called when starting to evaluate a lambda expression so that the arguments are available to the EL context during evaluation.voidCalled after evaluating a lambda expression to signal that the arguments are no longer required.getContext(Class<?> key) Obtain the context object for the given key.abstract ELResolverReturns the ELResolver used to resolve properties and method invocations during expression evaluation.Obtain the list of registered EvaluationListeners.abstract FunctionMapperReturns the FunctionMapper used to resolve EL function names to Java methods during expression evaluation.Obtain the ImportHandler for this ELContext, creating one if necessary.getLambdaArgument(String name) Obtain the value of the lambda argument with the given name.Returns the locale associated with this EL context.abstract VariableMapperReturns the VariableMapper used to resolve EL variable names toValueExpressioninstances during expression evaluation.booleanisLambdaArgument(String name) Determine if the specified name is recognised as the name of a lambda argument.booleanReturns whether a property has been resolved during the current evaluation step.voidnotifyAfterEvaluation(String expression) Notify interested listeners that an expression has been evaluated.voidnotifyBeforeEvaluation(String expression) Notify interested listeners that an expression will be evaluated.voidnotifyPropertyResolved(Object base, Object property) Notify interested listeners that a property has been resolved.voidputContext(Class<?> key, Object contextObject) Add an object to this EL context under the given key.voidSets the locale for this EL context.voidsetPropertyResolved(boolean resolved) Sets the internal flag indicating whether a property has been resolved during the current evaluation step.voidsetPropertyResolved(Object base, Object property) Mark the given property as resolved and notify any interested listeners.
-
Constructor Details
-
ELContext
public ELContext()Constructs an ELContext with the resolved flag set tofalse.
-
-
Method Details
-
setPropertyResolved
public void setPropertyResolved(boolean resolved) Sets the internal flag indicating whether a property has been resolved during the current evaluation step. This method is used byELResolverimplementations to signal that they have handled the current base/property combination.- Parameters:
resolved-trueif a property has been resolved,falseotherwise
-
setPropertyResolved
-
isPropertyResolved
public boolean isPropertyResolved()Returns whether a property has been resolved during the current evaluation step. ELResolver implementations callsetPropertyResolved(boolean)to indicate resolution, and the expression evaluator checks this flag to determine if resolution was successful.- Returns:
trueif a property has been resolved,falseotherwise
-
putContext
Add an object to this EL context under the given key.- Parameters:
key- The key under which to store the objectcontextObject- The object to add- Throws:
NullPointerException- If the supplied key or context isnull
-
getContext
Obtain the context object for the given key.- Parameters:
key- The key of the required context object- Returns:
- The value of the context object associated with the given key
- Throws:
NullPointerException- If the supplied key isnull
-
getELResolver
Returns the ELResolver used to resolve properties and method invocations during expression evaluation.- Returns:
- the ELResolver for this context
-
getImportHandler
Obtain the ImportHandler for this ELContext, creating one if necessary. This method is not thread-safe.- Returns:
- the ImportHandler for this ELContext.
- Since:
- EL 3.0
-
getFunctionMapper
Returns the FunctionMapper used to resolve EL function names to Java methods during expression evaluation.- Returns:
- the FunctionMapper for this context
-
getLocale
Returns the locale associated with this EL context. The locale is used for type conversion operations such as parsing numbers and dates during expression evaluation.- Returns:
- the locale for this context, or
nullif not set
-
setLocale
Sets the locale for this EL context. The locale is used for type conversion operations such as parsing numbers and dates during expression evaluation.- Parameters:
locale- the locale to use for this context
-
getVariableMapper
Returns the VariableMapper used to resolve EL variable names toValueExpressioninstances during expression evaluation.- Returns:
- the VariableMapper for this context
-
addEvaluationListener
Register an EvaluationListener with this ELContext.- Parameters:
listener- The EvaluationListener to register- Since:
- EL 3.0
-
getEvaluationListeners
Obtain the list of registered EvaluationListeners.- Returns:
- A list of the EvaluationListener registered with this ELContext
- Since:
- EL 3.0
-
notifyBeforeEvaluation
Notify interested listeners that an expression will be evaluated.- Parameters:
expression- The expression that will be evaluated- Since:
- EL 3.0
-
notifyAfterEvaluation
Notify interested listeners that an expression has been evaluated.- Parameters:
expression- The expression that was evaluated- Since:
- EL 3.0
-
notifyPropertyResolved
-
isLambdaArgument
Determine if the specified name is recognised as the name of a lambda argument.- Parameters:
name- The name of the lambda argument- Returns:
trueif the name is recognised as the name of a lambda argument, otherwisefalse- Since:
- EL 3.0
-
getLambdaArgument
-
enterLambdaScope
-
exitLambdaScope
public void exitLambdaScope()Called after evaluating a lambda expression to signal that the arguments are no longer required.- Since:
- EL 3.0
-
convertToType
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 coercedtype- The type to which the object should be coerced- Returns:
- An instance of the requested type.
- Throws:
ELException- If the conversion fails- Since:
- EL 3.0
-