Class StandardEvaluationContext
- java.lang.Object
- org.springframework.expression.spel.support.StandardEvaluationContext
- All Implemented Interfaces:
EvaluationContext
- Direct Known Subclasses:
MethodBasedEvaluationContext
public class StandardEvaluationContext extends Object implements EvaluationContext
A powerful and highly configurableEvaluationContextimplementation. This context uses standard implementations of all applicable strategies, based on reflection to resolve properties, methods and fields.For a simpler builder-style context variant for data-binding purposes, consider using
SimpleEvaluationContextinstead which allows for opting into several SpEL features as needed by specific evaluation cases.- Since:
- 3.0
- Author:
- Andy Clement, Juergen Hoeller, Sam Brannen
Constructor Summary
Constructors Constructor Description StandardEvaluationContext()Create aStandardEvaluationContextwith a null root object.StandardEvaluationContext(Object rootObject)Create aStandardEvaluationContextwith the given root object.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConstructorResolver(ConstructorResolver resolver)voidaddMethodResolver(MethodResolver resolver)voidaddPropertyAccessor(PropertyAccessor accessor)BeanResolvergetBeanResolver()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.OperatorOverloadergetOperatorOverloader()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.TypedValuegetRootObject()Return the default root context object against which unqualified properties/methods/etc should be resolved.TypeComparatorgetTypeComparator()Return a type comparator for comparing pairs of objects for equality.TypeConvertergetTypeConverter()Return a type converter that can convert (or coerce) a value from one type to another.TypeLocatorgetTypeLocator()Return a type locator that can be used to find types, either by short or fully qualified name.ObjectlookupVariable(String name)Look up a named variable within this evaluation context.voidregisterFunction(String name, Method method)voidregisterMethodFilter(Class<?> type, MethodFilter filter)Register aMethodFilterwhich will be called during method resolution for the specified type.booleanremoveConstructorResolver(ConstructorResolver resolver)booleanremoveMethodResolver(MethodResolver methodResolver)booleanremovePropertyAccessor(PropertyAccessor accessor)voidsetBeanResolver(BeanResolver beanResolver)voidsetConstructorResolvers(List<ConstructorResolver> constructorResolvers)voidsetMethodResolvers(List<MethodResolver> methodResolvers)voidsetOperatorOverloader(OperatorOverloader operatorOverloader)voidsetPropertyAccessors(List<PropertyAccessor> propertyAccessors)voidsetRootObject(Object rootObject)voidsetRootObject(Object rootObject, TypeDescriptor typeDescriptor)voidsetTypeComparator(TypeComparator typeComparator)voidsetTypeConverter(TypeConverter typeConverter)voidsetTypeLocator(TypeLocator typeLocator)voidsetVariable(String name, Object value)Set a named variable within this evaluation context to a specified value.voidsetVariables(Map<String,Object> variables)
Constructor Detail
StandardEvaluationContext
public StandardEvaluationContext()
Create aStandardEvaluationContextwith a null root object.
StandardEvaluationContext
public StandardEvaluationContext(Object rootObject)
Create aStandardEvaluationContextwith the given root object.- Parameters:
rootObject- the root object to use- See Also:
setRootObject(java.lang.Object, org.springframework.core.convert.TypeDescriptor)
Method Detail
setRootObject
public void setRootObject(Object rootObject, TypeDescriptor typeDescriptor)
setRootObject
public void setRootObject(Object rootObject)
getRootObject
public TypedValue getRootObject()
Description copied from interface:EvaluationContextReturn the default root context object against which unqualified properties/methods/etc should be resolved. This can be overridden when evaluating an expression.- Specified by:
getRootObjectin interfaceEvaluationContext
setPropertyAccessors
public void setPropertyAccessors(List<PropertyAccessor> propertyAccessors)
getPropertyAccessors
public List<PropertyAccessor> getPropertyAccessors()
Description copied from interface:EvaluationContextReturn a list of accessors that will be asked in turn to read/write a property.- Specified by:
getPropertyAccessorsin interfaceEvaluationContext
addPropertyAccessor
public void addPropertyAccessor(PropertyAccessor accessor)
removePropertyAccessor
public boolean removePropertyAccessor(PropertyAccessor accessor)
setConstructorResolvers
public void setConstructorResolvers(List<ConstructorResolver> constructorResolvers)
getConstructorResolvers
public List<ConstructorResolver> getConstructorResolvers()
Description copied from interface:EvaluationContextReturn a list of resolvers that will be asked in turn to locate a constructor.- Specified by:
getConstructorResolversin interfaceEvaluationContext
addConstructorResolver
public void addConstructorResolver(ConstructorResolver resolver)
removeConstructorResolver
public boolean removeConstructorResolver(ConstructorResolver resolver)
setMethodResolvers
public void setMethodResolvers(List<MethodResolver> methodResolvers)
getMethodResolvers
public List<MethodResolver> getMethodResolvers()
Description copied from interface:EvaluationContextReturn a list of resolvers that will be asked in turn to locate a method.- Specified by:
getMethodResolversin interfaceEvaluationContext
addMethodResolver
public void addMethodResolver(MethodResolver resolver)
removeMethodResolver
public boolean removeMethodResolver(MethodResolver methodResolver)
setBeanResolver
public void setBeanResolver(BeanResolver beanResolver)
getBeanResolver
public BeanResolver getBeanResolver()
Description copied from interface:EvaluationContextReturn a bean resolver that can look up beans by name.- Specified by:
getBeanResolverin interfaceEvaluationContext
setTypeLocator
public void setTypeLocator(TypeLocator typeLocator)
getTypeLocator
public TypeLocator getTypeLocator()
Description copied from interface:EvaluationContextReturn a type locator that can be used to find types, either by short or fully qualified name.- Specified by:
getTypeLocatorin interfaceEvaluationContext
setTypeConverter
public void setTypeConverter(TypeConverter typeConverter)
getTypeConverter
public TypeConverter getTypeConverter()
Description copied from interface:EvaluationContextReturn a type converter that can convert (or coerce) a value from one type to another.- Specified by:
getTypeConverterin interfaceEvaluationContext
setTypeComparator
public void setTypeComparator(TypeComparator typeComparator)
getTypeComparator
public TypeComparator getTypeComparator()
Description copied from interface:EvaluationContextReturn a type comparator for comparing pairs of objects for equality.- Specified by:
getTypeComparatorin interfaceEvaluationContext
setOperatorOverloader
public void setOperatorOverloader(OperatorOverloader operatorOverloader)
getOperatorOverloader
public OperatorOverloader getOperatorOverloader()
Description copied from interface:EvaluationContextReturn an operator overloader that may support mathematical operations between more than the standard set of types.- Specified by:
getOperatorOverloaderin interfaceEvaluationContext
setVariable
public void setVariable(String name, Object value)
Description copied from interface:EvaluationContextSet a named variable within this evaluation context to a specified value.- Specified by:
setVariablein interfaceEvaluationContext- Parameters:
name- variable to setvalue- value to be placed in the variable
setVariables
public void setVariables(Map<String,Object> variables)
registerFunction
public void registerFunction(String name, Method method)
lookupVariable
public Object lookupVariable(String name)
Description copied from interface:EvaluationContextLook up a named variable within this evaluation context.- Specified by:
lookupVariablein interfaceEvaluationContext- Parameters:
name- variable to lookup- Returns:
- the value of the variable, or
nullif not found
registerMethodFilter
public void registerMethodFilter(Class<?> type, MethodFilter filter) throws IllegalStateException
Register 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 calledfilter- aMethodFilter, ornullto unregister a filter for the type- Throws:
IllegalStateException- if theReflectiveMethodResolveris not in use