public interface EvaluationContext
There are two default implementations of this interface.
SimpleEvaluationContext
: a simpler builder-style EvaluationContext
variant for data-binding purposes, which allows for opting into several SpEL
features as needed.StandardEvaluationContext
: a powerful and highly configurable EvaluationContext
implementation, which can be extended, rather than having to implement everything
manually.Modifier and Type | Method and Description |
---|---|
default TypedValue |
assignVariable(String name,
Supplier<TypedValue> valueSupplier)
Assign the value created by the specified
Supplier to a named variable
within this evaluation context. |
BeanResolver |
getBeanResolver()
Return a bean resolver that can look up beans by name.
|
List<ConstructorResolver> |
getConstructorResolvers()
Return a list of resolvers that will be asked in turn to locate a constructor.
|
List<MethodResolver> |
getMethodResolvers()
Return a list of resolvers that will be asked in turn to locate a method.
|
OperatorOverloader |
getOperatorOverloader()
Return an operator overloader that may support mathematical operations
between more than the standard set of types.
|
List<PropertyAccessor> |
getPropertyAccessors()
Return a list of accessors that will be asked in turn to read/write a property.
|
TypedValue |
getRootObject()
Return the default root context object against which unqualified
properties/methods/etc should be resolved.
|
TypeComparator |
getTypeComparator()
Return a type comparator for comparing pairs of objects for equality.
|
TypeConverter |
getTypeConverter()
Return a type converter that can convert (or coerce) a value from one type to another.
|
TypeLocator |
getTypeLocator()
Return a type locator that can be used to find types, either by short or
fully qualified name.
|
default boolean |
isAssignmentEnabled()
Determine if assignment is enabled within expressions evaluated by this evaluation
context.
|
Object |
lookupVariable(String name)
Look up a named variable within this evaluation context.
|
void |
setVariable(String name,
Object value)
Set a named variable in this evaluation context to a specified value.
|
TypedValue getRootObject()
List<PropertyAccessor> getPropertyAccessors()
List<ConstructorResolver> getConstructorResolvers()
List<MethodResolver> getMethodResolvers()
@Nullable BeanResolver getBeanResolver()
TypeLocator getTypeLocator()
TypeConverter getTypeConverter()
TypeComparator getTypeComparator()
OperatorOverloader getOperatorOverloader()
default TypedValue assignVariable(String name, Supplier<TypedValue> valueSupplier)
Supplier
to 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 the valueSupplier
. Concrete implementations
may override this default method to provide different semantics.
name
- the name of the variable to assignvalueSupplier
- the supplier of the value to be assigned to the variableTypedValue
wrapping the assigned valuevoid setVariable(String name, @Nullable Object value)
In contrast to assignVariable(String, Supplier)
, this method
should only be invoked programmatically when interacting directly with the
EvaluationContext
— for example, to provide initial
configuration for the context.
name
- the name of the variable to setvalue
- the value to be placed in the variable@Nullable Object lookupVariable(String name)
name
- the name of the variable to look upnull
if not founddefault boolean isAssignmentEnabled()
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.
true
if assignment is enabled; false
otherwise