Interface EvaluationContext
- All Known Implementing Classes:
MethodBasedEvaluationContext, SimpleEvaluationContext, StandardEvaluationContext
There are two default implementations of this interface.
SimpleEvaluationContext: a simpler builder-styleEvaluationContextvariant for data-binding purposes, which allows for opting into several SpEL features as needed.StandardEvaluationContext: a powerful and highly configurableEvaluationContextimplementation, which can be extended, rather than having to implement everything manually.
WARNING: Special security considerations apply to the
evaluation of SpEL expressions, particularly those obtained from an untrusted
source. See the
Security Considerations section of the Spring Framework reference
documentation for details, as well as the class-level documentation for
StandardEvaluationContext and SimpleEvaluationContext.
An EvaluationContext is designed to be built once and reused across
many evaluations, potentially of many different Expression instances. A
single Expression, in turn, may cache accessor and executor state resolved
against a particular EvaluationContext configuration. Reusing an
Expression across EvaluationContext instances of the same type and
with equivalent configuration is supported; reusing an Expression across
contexts with different security implications — for example, first against a
StandardEvaluationContext and later against a
SimpleEvaluationContext — is not, since cached state from the more
permissive evaluation may be reused during the more restrictive one. See
Expression for details.
- Since:
- 3.0
- Author:
- Andy Clement, Juergen Hoeller, Sam Brannen
-
Method Summary
Modifier and TypeMethodDescriptiondefault TypedValueassignVariable(String name, Supplier<TypedValue> valueSupplier) Assign the value created by the specifiedSupplierto a named variable within this evaluation context.Return a bean resolver that can look up beans by name.default List<ConstructorResolver> Return a list of resolvers that will be asked in turn to locate a constructor.default List<IndexAccessor> Return a list of index accessors that will be asked in turn to access or set an indexed value.default List<MethodResolver> Return a list of resolvers that will be asked in turn to locate a method.Return an operator overloader that may support mathematical operations between more than the standard set of types.default List<PropertyAccessor> Return a list of accessors that will be asked in turn to read/write a property.Return the default root context object against which unqualified properties, methods, etc.Return a type comparator for comparing pairs of objects for equality.Return a type converter that can convert (or coerce) a value from one type to another.Return a type locator that can be used to find types, either by short or fully qualified name.default booleanDetermine if assignment is enabled within expressions evaluated by this evaluation context.lookupVariable(String name) Look up a named variable within this evaluation context.voidsetVariable(String name, @Nullable Object value) Set a named variable in this evaluation context to a specified value.
-
Method Details
-
getRootObject
TypedValue getRootObject()Return the default root context object against which unqualified properties, methods, etc. should be resolved.This can be overridden when evaluating an expression.
-
getPropertyAccessors
Return a list of accessors that will be asked in turn to read/write a property.The default implementation returns an empty list.
-
getIndexAccessors
Return a list of index accessors that will be asked in turn to access or set an indexed value.The default implementation returns an empty list.
- Since:
- 6.2
-
getConstructorResolvers
Return a list of resolvers that will be asked in turn to locate a constructor.The default implementation returns an empty list.
-
getMethodResolvers
Return a list of resolvers that will be asked in turn to locate a method.The default implementation returns an empty list.
-
getBeanResolver
@Nullable BeanResolver getBeanResolver()Return a bean resolver that can look up beans by name. -
getTypeLocator
TypeLocator getTypeLocator()Return a type locator that can be used to find types, either by short or fully qualified name. -
getTypeConverter
TypeConverter getTypeConverter()Return a type converter that can convert (or coerce) a value from one type to another. -
getTypeComparator
TypeComparator getTypeComparator()Return a type comparator for comparing pairs of objects for equality. -
getOperatorOverloader
OperatorOverloader getOperatorOverloader()Return an operator overloader that may support mathematical operations between more than the standard set of types. -
assignVariable
Assign the value created by the specifiedSupplierto a named variable within this evaluation context.In contrast to
setVariable(String, Object), this method should only be invoked to support the assignment operator (=) within an expression.By default, this method delegates to
setVariable(String, Object), providing the value created by thevalueSupplier. Concrete implementations may override this default method to provide different semantics.- Parameters:
name- the name of the variable to assignvalueSupplier- the supplier of the value to be assigned to the variable- Returns:
- a
TypedValuewrapping the assigned value - Since:
- 5.2.24
-
setVariable
Set a named variable in this evaluation context to a specified value.In contrast to
assignVariable(String, Supplier), this method should only be invoked programmatically when interacting directly with theEvaluationContext— for example, to provide initial configuration for the context.- Parameters:
name- the name of the variable to setvalue- the value to be placed in the variable- See Also:
-
lookupVariable
-
isAssignmentEnabled
default boolean isAssignmentEnabled()Determine if assignment is enabled within expressions evaluated by this evaluation context.If this method returns
false, the assignment (=), increment (++), and decrement (--) operators are disabled.By default, this method returns
true. Concrete implementations may override this default method to disable assignment.- Returns:
trueif assignment is enabled;falseotherwise- Since:
- 5.3.38
-