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.
 
In addition to support for setting and looking up variables as defined in
 the EvaluationContext API, StandardEvaluationContext also
 provides support for registering and looking up functions. The
 registerFunction(...) methods provide a convenient way to register a
 function as a Method or a MethodHandle; however, a function
 can also be registered via setVariable(String, Object) or
 setVariables(Map). Since functions share a namespace with the variables
 in this evaluation context, care must be taken to ensure that function names
 and variable names do not overlap.
 
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 SummaryConstructorsConstructorDescriptionCreate aStandardEvaluationContextwith a null root object.StandardEvaluationContext(Object rootObject) Create aStandardEvaluationContextwith the given root object.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddConstructorResolver(ConstructorResolver constructorResolver) Add the supplied constructor resolver to this evaluation context.voidaddIndexAccessor(IndexAccessor indexAccessor) Add the supplied index accessor to this evaluation context.voidaddMethodResolver(MethodResolver methodResolver) Add the supplied method resolver to this evaluation context.voidaddPropertyAccessor(PropertyAccessor propertyAccessor) Add the supplied property accessor to this evaluation context.voidapplyDelegatesTo(StandardEvaluationContext evaluationContext) Apply the internal delegates of this instance to the specifiedevaluationContext.Get the configuredBeanResolverfor looking up beans, if any.Get the list of constructor resolvers to use in this evaluation context.Get the list of index accessors configured in this evaluation context.Get the list of method resolvers to use in this evaluation context.Get the configuredOperatorOverloaderfor mathematical operations.Get the list of property accessors configured in this evaluation context.Return the configured default root context object against which unqualified properties, methods, etc.Get the configuredTypeComparatorfor comparing pairs of objects.Get the configuredTypeConverterfor value conversion.Get the configuredTypeLocatorthat will be used to find types, either by short or fully-qualified name.lookupVariable(String name) Look up a named variable or function within this evaluation context.voidregisterFunction(String name, MethodHandle methodHandle) Register the specifiedMethodHandleas a SpEL function.voidregisterFunction(String name, Method method) Register the specifiedMethodas a SpEL function.voidregisterMethodFilter(Class<?> type, MethodFilter filter) Register aMethodFilterwhich will be called during method resolution for the specified type.booleanremoveConstructorResolver(ConstructorResolver constructorResolver) Remove the supplied constructor resolver from this evaluation context.booleanremoveIndexAccessor(IndexAccessor indexAccessor) Remove the supplied index accessor from this evaluation context.booleanremoveMethodResolver(MethodResolver methodResolver) Remove the supplied method resolver from this evaluation context.booleanremovePropertyAccessor(PropertyAccessor propertyAccessor) Remove the supplied property accessor from this evaluation context.voidsetBeanResolver(BeanResolver beanResolver) Set theBeanResolverto use for looking up beans, if any.voidsetConstructorResolvers(List<ConstructorResolver> constructorResolvers) Set the list of constructor resolvers to use in this evaluation context.voidsetIndexAccessors(List<IndexAccessor> indexAccessors) Set the list of index accessors to use in this evaluation context.voidsetMethodResolvers(List<MethodResolver> methodResolvers) Set the list of method resolvers to use in this evaluation context.voidsetOperatorOverloader(OperatorOverloader operatorOverloader) Set theOperatorOverloaderfor mathematical operations.voidsetPropertyAccessors(List<PropertyAccessor> propertyAccessors) Set the list of property accessors to use in this evaluation context.voidsetRootObject(Object rootObject) Specify the default root context object against which unqualified properties, methods, etc.voidsetRootObject(Object rootObject, TypeDescriptor typeDescriptor) Specify the default root context object (including a type descriptor) against which unqualified properties, methods, etc.voidsetTypeComparator(TypeComparator typeComparator) Set theTypeComparatorfor comparing pairs of objects.voidsetTypeConverter(TypeConverter typeConverter) Set theTypeConverterfor value conversion.voidsetTypeLocator(TypeLocator typeLocator) Set theTypeLocatorto use to find types, either by short or fully-qualified name.voidsetVariable(String name, Object value) Set a named variable in this evaluation context to a specified value.voidsetVariables(Map<String, Object> variables) Set multiple named variables in this evaluation context to the specified values.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.expression.EvaluationContextassignVariable, isAssignmentEnabled
- 
Constructor Details- 
StandardEvaluationContextpublic StandardEvaluationContext()Create aStandardEvaluationContextwith a null root object.
- 
StandardEvaluationContextCreate aStandardEvaluationContextwith the given root object.- Parameters:
- rootObject- the root object to use
- See Also:
 
 
- 
- 
Method Details- 
setRootObjectSpecify the default root context object (including a type descriptor) against which unqualified properties, methods, etc. should be resolved.- Parameters:
- rootObject- the root object to use
- typeDescriptor- a corresponding type descriptor
 
- 
setRootObjectSpecify the default root context object against which unqualified properties, methods, etc. should be resolved.- Parameters:
- rootObject- the root object to use
 
- 
getRootObjectReturn the configured default root context object against which unqualified properties, methods, etc. should be resolved (can beTypedValue.NULL).- Specified by:
- getRootObjectin interface- EvaluationContext
 
- 
setPropertyAccessorsSet the list of property accessors to use in this evaluation context.Replaces any previously configured property accessors. 
- 
getPropertyAccessorsGet the list of property accessors configured in this evaluation context.- Specified by:
- getPropertyAccessorsin interface- EvaluationContext
 
- 
addPropertyAccessorAdd the supplied property accessor to this evaluation context.- Parameters:
- propertyAccessor- the property accessor to add
- See Also:
 
- 
removePropertyAccessorRemove the supplied property accessor from this evaluation context.- Parameters:
- propertyAccessor- the property accessor to remove
- Returns:
- trueif the property accessor was removed,- falseif the property accessor was not configured in this evaluation context
- See Also:
 
- 
setIndexAccessorsSet the list of index accessors to use in this evaluation context.Replaces any previously configured index accessors. - Since:
- 6.2
- See Also:
 
- 
getIndexAccessorsGet the list of index accessors configured in this evaluation context.- Specified by:
- getIndexAccessorsin interface- EvaluationContext
- Since:
- 6.2
- See Also:
 
- 
addIndexAccessorAdd the supplied index accessor to this evaluation context.- Parameters:
- indexAccessor- the index accessor to add
- Since:
- 6.2
- See Also:
 
- 
removeIndexAccessorRemove the supplied index accessor from this evaluation context.- Parameters:
- indexAccessor- the index accessor to remove
- Returns:
- trueif the index accessor was removed,- falseif the index accessor was not configured in this evaluation context
- Since:
- 6.2
- See Also:
 
- 
setConstructorResolversSet the list of constructor resolvers to use in this evaluation context.Replaces any previously configured constructor resolvers. 
- 
getConstructorResolversGet the list of constructor resolvers to use in this evaluation context.- Specified by:
- getConstructorResolversin interface- EvaluationContext
 
- 
addConstructorResolverAdd the supplied constructor resolver to this evaluation context.- Parameters:
- constructorResolver- the constructor resolver to add
- See Also:
 
- 
removeConstructorResolverRemove the supplied constructor resolver from this evaluation context.- Parameters:
- constructorResolver- the constructor resolver to remove
- Returns:
- trueif the constructor resolver was removed,- falseif the constructor resolver was not configured in this evaluation context
- See Also:
 
- 
setMethodResolversSet the list of method resolvers to use in this evaluation context.Replaces any previously configured method resolvers. 
- 
getMethodResolversGet the list of method resolvers to use in this evaluation context.- Specified by:
- getMethodResolversin interface- EvaluationContext
 
- 
addMethodResolverAdd the supplied method resolver to this evaluation context.- Parameters:
- methodResolver- the method resolver to add
- See Also:
 
- 
removeMethodResolverRemove the supplied method resolver from this evaluation context.- Parameters:
- methodResolver- the method resolver to remove
- Returns:
- trueif the method resolver was removed,- falseif the method resolver was not configured in this evaluation context
- See Also:
 
- 
setBeanResolverSet theBeanResolverto use for looking up beans, if any.
- 
getBeanResolverGet the configuredBeanResolverfor looking up beans, if any.- Specified by:
- getBeanResolverin interface- EvaluationContext
 
- 
setTypeLocatorSet theTypeLocatorto use to find types, either by short or fully-qualified name.By default, a StandardTypeLocatorwill be used.NOTE: Even if a StandardTypeLocatoris sufficient, you may need to manually configure aStandardTypeLocatorwith a specificClassLoaderto ensure that the SpEL expression parser is able to reliably locate user types.- Parameters:
- typeLocator- the- TypeLocatorto use
- See Also:
 
- 
getTypeLocatorGet the configuredTypeLocatorthat will be used to find types, either by short or fully-qualified name.See setTypeLocator(TypeLocator)for further details.- Specified by:
- getTypeLocatorin interface- EvaluationContext
- See Also:
 
- 
setTypeConverterSet theTypeConverterfor value conversion.
- 
getTypeConverterGet the configuredTypeConverterfor value conversion.- Specified by:
- getTypeConverterin interface- EvaluationContext
 
- 
setTypeComparatorSet theTypeComparatorfor comparing pairs of objects.
- 
getTypeComparatorGet the configuredTypeComparatorfor comparing pairs of objects.- Specified by:
- getTypeComparatorin interface- EvaluationContext
 
- 
setOperatorOverloaderSet theOperatorOverloaderfor mathematical operations.
- 
getOperatorOverloaderGet the configuredOperatorOverloaderfor mathematical operations.- Specified by:
- getOperatorOverloaderin interface- EvaluationContext
 
- 
setVariableSet a named variable in this evaluation context to a specified value.If the specified nameisnull, it will be ignored. If the specifiedvalueisnull, the named variable will be removed from this evaluation context.In contrast to EvaluationContext.assignVariable(String,java.util.function.Supplier), this method should only be invoked programmatically when interacting directly with theEvaluationContext— for example, to provide initial configuration for the context.Note that variables and functions share a common namespace in this evaluation context. See the class-level documentation for details. - Specified by:
- setVariablein interface- EvaluationContext
- Parameters:
- name- the name of the variable to set
- value- the value to be placed in the variable
- See Also:
 
- 
setVariablesSet multiple named variables in this evaluation context to the specified values.This is a convenience variant of setVariable(String, Object).Note that variables and functions share a common namespace in this evaluation context. See the class-level documentation for details. - Parameters:
- variables- the names and values of the variables to set
- See Also:
 
- 
registerFunctionRegister the specifiedMethodas a SpEL function.Note that variables and functions share a common namespace in this evaluation context. See the class-level documentation for details. - Parameters:
- name- the name of the function
- method- the- Methodto register
- See Also:
 
- 
registerFunctionRegister the specifiedMethodHandleas a SpEL function.Note that variables and functions share a common namespace in this evaluation context. See the class-level documentation for details. - Parameters:
- name- the name of the function
- methodHandle- the- MethodHandleto register
- Since:
- 6.1
- See Also:
 
- 
lookupVariableLook up a named variable or function within this evaluation context.Note that variables and functions share a common namespace in this evaluation context. See the class-level documentation for details. - Specified by:
- lookupVariablein interface- EvaluationContext
- Parameters:
- name- the name of the variable or function to look up
- Returns:
- the value of the variable or function, or nullif not found
 
- 
registerMethodFilterRegister aMethodFilterwhich will be called during method resolution for the specified type.The MethodFiltermay 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 called
- filter- a- MethodFilter, or- nullto unregister a filter for the type
- Throws:
- IllegalStateException- if the- ReflectiveMethodResolveris not in use
 
- 
applyDelegatesToApply the internal delegates of this instance to the specifiedevaluationContext. Typically invoked right after the new context instance has been created to reuse the delegates. Does not modify the root object or any registered variables or functions.- Parameters:
- evaluationContext- the evaluation context to update
- Since:
- 6.1.1
 
 
-