Class StandardEvaluationContext
- All Implemented Interfaces:
EvaluationContext
- Direct Known Subclasses:
MethodBasedEvaluationContext
EvaluationContext
implementation.
This context uses standard implementations of all applicable strategies,
based on reflection to resolve properties, methods, and fields. Note, however,
that you may need to manually configure a StandardTypeLocator
with a
specific ClassLoader
to ensure that the SpEL expression parser is able
to reliably locate user types. See setTypeLocator(TypeLocator)
for
details.
For a simpler, builder-style context variant for data-binding purposes,
consider using SimpleEvaluationContext
instead which allows for
opting into several SpEL features as needed by specific use cases.
- Since:
- 3.0
- Author:
- Andy Clement, Juergen Hoeller, Sam Brannen, Stephane Nicoll
- See Also:
-
Constructor Summary
ConstructorDescriptionCreate aStandardEvaluationContext
with a null root object.StandardEvaluationContext
(Object rootObject) Create aStandardEvaluationContext
with the given root object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConstructorResolver
(ConstructorResolver resolver) void
addMethodResolver
(MethodResolver resolver) void
addPropertyAccessor
(PropertyAccessor accessor) void
applyDelegatesTo
(StandardEvaluationContext evaluationContext) Apply the internal delegates of this instance to the specifiedevaluationContext
.Return a bean resolver that can look up beans by name.Return a list of resolvers that will be asked in turn to locate a constructor.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.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 should be resolved.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.Get the configuredTypeLocator
that will be used to find types, either by short or fully-qualified name.lookupVariable
(String name) Look up a named variable within this evaluation context.void
registerFunction
(String name, MethodHandle methodHandle) Register the specified MethodHandle as a SpEL function.void
registerFunction
(String name, Method method) Register the specified Method as a SpEL function.void
registerMethodFilter
(Class<?> type, MethodFilter filter) Register aMethodFilter
which will be called during method resolution for the specified type.boolean
removeConstructorResolver
(ConstructorResolver resolver) boolean
removeMethodResolver
(MethodResolver methodResolver) boolean
removePropertyAccessor
(PropertyAccessor accessor) void
setBeanResolver
(BeanResolver beanResolver) void
setConstructorResolvers
(List<ConstructorResolver> constructorResolvers) void
setMethodResolvers
(List<MethodResolver> methodResolvers) void
setOperatorOverloader
(OperatorOverloader operatorOverloader) void
setPropertyAccessors
(List<PropertyAccessor> propertyAccessors) void
setRootObject
(Object rootObject) void
setRootObject
(Object rootObject, TypeDescriptor typeDescriptor) void
setTypeComparator
(TypeComparator typeComparator) void
setTypeConverter
(TypeConverter typeConverter) void
setTypeLocator
(TypeLocator typeLocator) Set theTypeLocator
to use to find types, either by short or fully-qualified name.void
setVariable
(String name, Object value) Set a named variable in this evaluation context to a specified value.void
setVariables
(Map<String, Object> variables) Set multiple named variables in this evaluation context to given values.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.expression.EvaluationContext
assignVariable
-
Constructor Details
-
StandardEvaluationContext
public StandardEvaluationContext()Create aStandardEvaluationContext
with a null root object. -
StandardEvaluationContext
Create aStandardEvaluationContext
with the given root object.- Parameters:
rootObject
- the root object to use- See Also:
-
-
Method Details
-
setRootObject
-
setRootObject
-
getRootObject
Description copied from interface:EvaluationContext
Return the default root context object against which unqualified properties/methods/etc should be resolved. This can be overridden when evaluating an expression.- Specified by:
getRootObject
in interfaceEvaluationContext
-
setPropertyAccessors
-
getPropertyAccessors
Description copied from interface:EvaluationContext
Return a list of accessors that will be asked in turn to read/write a property.- Specified by:
getPropertyAccessors
in interfaceEvaluationContext
-
addPropertyAccessor
-
removePropertyAccessor
-
setConstructorResolvers
-
getConstructorResolvers
Description copied from interface:EvaluationContext
Return a list of resolvers that will be asked in turn to locate a constructor.- Specified by:
getConstructorResolvers
in interfaceEvaluationContext
-
addConstructorResolver
-
removeConstructorResolver
-
setMethodResolvers
-
getMethodResolvers
Description copied from interface:EvaluationContext
Return a list of resolvers that will be asked in turn to locate a method.- Specified by:
getMethodResolvers
in interfaceEvaluationContext
-
addMethodResolver
-
removeMethodResolver
-
setBeanResolver
-
getBeanResolver
Description copied from interface:EvaluationContext
Return a bean resolver that can look up beans by name.- Specified by:
getBeanResolver
in interfaceEvaluationContext
-
setTypeLocator
Set theTypeLocator
to use to find types, either by short or fully-qualified name.By default, a
StandardTypeLocator
will be used.NOTE: Even if a
StandardTypeLocator
is sufficient, you may need to manually configure aStandardTypeLocator
with a specificClassLoader
to ensure that the SpEL expression parser is able to reliably locate user types.- Parameters:
typeLocator
- theTypeLocator
to use- See Also:
-
getTypeLocator
Get the configuredTypeLocator
that will be used to find types, either by short or fully-qualified name.See
setTypeLocator(TypeLocator)
for further details.- Specified by:
getTypeLocator
in interfaceEvaluationContext
- See Also:
-
setTypeConverter
-
getTypeConverter
Description copied from interface:EvaluationContext
Return a type converter that can convert (or coerce) a value from one type to another.- Specified by:
getTypeConverter
in interfaceEvaluationContext
-
setTypeComparator
-
getTypeComparator
Description copied from interface:EvaluationContext
Return a type comparator for comparing pairs of objects for equality.- Specified by:
getTypeComparator
in interfaceEvaluationContext
-
setOperatorOverloader
-
getOperatorOverloader
Description copied from interface:EvaluationContext
Return an operator overloader that may support mathematical operations between more than the standard set of types.- Specified by:
getOperatorOverloader
in interfaceEvaluationContext
-
setVariable
Description copied from interface:EvaluationContext
Set a named variable in this evaluation context to a specified value.In contrast to
EvaluationContext.assignVariable(String, Supplier)
, this method should only be invoked programmatically when interacting directly with theEvaluationContext
— for example, to provide initial configuration for the context.- Specified by:
setVariable
in interfaceEvaluationContext
- Parameters:
name
- the name of the variable to setvalue
- the value to be placed in the variable
-
setVariables
Set multiple named variables in this evaluation context to given values.This is a convenience variant of
setVariable(String, Object)
.- Parameters:
variables
- the names and values of the variables to set- See Also:
-
registerFunction
Register the specified Method as a SpEL function.Note: Function names share a namespace with the variables in this evaluation context, as populated by
setVariable(String, Object)
. Make sure that specified function names and variable names do not overlap.- Parameters:
name
- the name of the functionmethod
- the Method to register- See Also:
-
registerFunction
Register the specified MethodHandle as a SpEL function.Note: Function names share a namespace with the variables in this evaluation context, as populated by
setVariable(String, Object)
. Make sure that specified function names and variable names do not overlap.- Parameters:
name
- the name of the functionmethodHandle
- the MethodHandle to register- Since:
- 6.1
- See Also:
-
lookupVariable
Description copied from interface:EvaluationContext
Look up a named variable within this evaluation context.- Specified by:
lookupVariable
in interfaceEvaluationContext
- Parameters:
name
- the name of the variable to look up- Returns:
- the value of the variable, or
null
if not found
-
registerMethodFilter
Register aMethodFilter
which will be called during method resolution for the specified type.The
MethodFilter
may remove methods and/or sort the methods which will then be used by SpEL as the candidates to look through for a match.- Parameters:
type
- the type for which the filter should be calledfilter
- aMethodFilter
, ornull
to unregister a filter for the type- Throws:
IllegalStateException
- if theReflectiveMethodResolver
is not in use
-
applyDelegatesTo
Apply the internal delegates of this instance to the specifiedevaluationContext
. Typically invoked right after the new context instance has been created to reuse the delegates. Do not modify the root object or any registered variables.- Parameters:
evaluationContext
- the evaluation context to update- Since:
- 6.1.1
-