类 SimpleEvaluationContext
- 所有已实现的接口:
EvaluationContext
EvaluationContext that focuses on a subset
of essential SpEL features and customization options, targeting simple
condition evaluation and in particular data binding scenarios.
In many cases, the full extent of the SpEL language is not required and
should be meaningfully restricted. Examples include but are not limited to
data binding expressions, property-based filters, and others. To that effect,
SimpleEvaluationContext is tailored to support only a subset of the
SpEL language syntax, e.g. excluding references to Java types, constructors,
and bean references.
When creating a SimpleEvaluationContext you need to choose the
level of support that you need for property access in SpEL expressions:
- A custom
PropertyAccessor(typically not reflection-based), potentially combined with aDataBindingPropertyAccessor - Data binding properties for read-only access
- Data binding properties for read and write
Conveniently, forReadOnlyDataBinding()
enables read access to properties via DataBindingPropertyAccessor;
same for forReadWriteDataBinding() when
write access is needed as well. Alternatively, configure custom accessors
via forPropertyAccessors(cn.taketoday.expression.PropertyAccessor...), and potentially
activate method resolution and/or a type converter through the builder.
Note that SimpleEvaluationContext is typically not configured
with a default root object. Instead it is meant to be created once and
used repeatedly through getValue calls on a pre-compiled
Expression with both an
EvaluationContext and a root object as arguments:
Expression.getValue(EvaluationContext, Object).
In addition to support for setting and looking up variables as defined in
the EvaluationContext API, SimpleEvaluationContext also
provides support for registering and
looking up functions as variables. Since
functions share a common namespace with the variables in this evaluation
context, care must be taken to ensure that function names and variable names
do not overlap.
For more power and flexibility, in particular for internal configuration
scenarios, consider using StandardEvaluationContext instead.
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Juergen Hoeller, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类 -
字段概要
字段修饰符和类型字段说明private final List<MethodResolver>private final List<PropertyAccessor>private final TypedValueprivate final TypeConverterprivate static final TypeLocator -
构造器概要
构造器限定符构造器说明privateSimpleEvaluationContext(List<PropertyAccessor> accessors, List<MethodResolver> resolvers, TypeConverter converter, TypedValue rootObject) -
方法概要
修饰符和类型方法说明assignVariable(String name, Supplier<TypedValue> valueSupplier) SimpleEvaluationContextdoes not support variable assignment within expressions.forPropertyAccessors(PropertyAccessor... accessors) Create aSimpleEvaluationContextfor the specifiedPropertyAccessordelegates: typically a customPropertyAccessorspecific to a use case (e.g. attribute resolution in a custom data structure), potentially combined with aDataBindingPropertyAccessorif property dereferences are needed as well.Create aSimpleEvaluationContextfor read-only access to public properties viaDataBindingPropertyAccessor.Create aSimpleEvaluationContextfor read-write access to public properties viaDataBindingPropertyAccessor.SimpleEvaluationContextdoes not support the use of bean references.Return an empty list, always, since this context does not support the use of type references.Return the specifiedMethodResolverdelegates, if any.Return an instance ofStandardOperatorOverloader.Return the specifiedPropertyAccessordelegates, if any.Return the specified root object, if any.Return an instance ofStandardTypeComparator.The configuredTypeConverter.SimpleEvaluationContextdoes not support use of type references.lookupVariable(String name) Look up a named variable or function within this evaluation context.voidsetVariable(String name, Object value) Set a named variable or function in this evaluation context to the specified value.
-
字段详细资料
-
typeNotFoundTypeLocator
-
rootObject
-
propertyAccessors
-
methodResolvers
-
typeConverter
-
variables
-
-
构造器详细资料
-
SimpleEvaluationContext
private SimpleEvaluationContext(List<PropertyAccessor> accessors, List<MethodResolver> resolvers, @Nullable TypeConverter converter, @Nullable TypedValue rootObject)
-
-
方法详细资料
-
getRootObject
Return the specified root object, if any.- 指定者:
getRootObject在接口中EvaluationContext
-
getPropertyAccessors
Return the specifiedPropertyAccessordelegates, if any. -
getConstructorResolvers
Return an empty list, always, since this context does not support the use of type references.- 指定者:
getConstructorResolvers在接口中EvaluationContext
-
getMethodResolvers
Return the specifiedMethodResolverdelegates, if any. -
getBeanResolver
SimpleEvaluationContextdoes not support the use of bean references.- 指定者:
getBeanResolver在接口中EvaluationContext- 返回:
- always
null
-
getTypeLocator
SimpleEvaluationContextdoes not support use of type references.- 指定者:
getTypeLocator在接口中EvaluationContext- 返回:
TypeLocatorimplementation that raises aSpelEvaluationExceptionwithSpelMessage.TYPE_NOT_FOUND.
-
getTypeConverter
The configuredTypeConverter.By default this is
StandardTypeConverter. -
getTypeComparator
Return an instance ofStandardTypeComparator.- 指定者:
getTypeComparator在接口中EvaluationContext
-
getOperatorOverloader
Return an instance ofStandardOperatorOverloader.- 指定者:
getOperatorOverloader在接口中EvaluationContext
-
assignVariable
SimpleEvaluationContextdoes not support variable assignment within expressions.- 指定者:
assignVariable在接口中EvaluationContext- 参数:
name- the name of the variable to assignvalueSupplier- the supplier of the value to be assigned to the variable- 返回:
- a
TypedValuewrapping the assigned value - 抛出:
SpelEvaluationException- withSpelMessage.VARIABLE_ASSIGNMENT_NOT_SUPPORTED
-
setVariable
Set a named variable or function in this evaluation context to the specified value.A function can be registered as a
Methodor aMethodHandle.Note that variables and functions share a common namespace in this evaluation context. See the class-level documentation for details.
- 指定者:
setVariable在接口中EvaluationContext- 参数:
name- the name of the variable or function to setvalue- the value to be placed in the variable or function- 另请参阅:
-
lookupVariable
Look 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.
- 指定者:
lookupVariable在接口中EvaluationContext- 参数:
name- the name of the variable or function to look up- 返回:
- the value of the variable or function, or
nullif not found
-
forPropertyAccessors
Create aSimpleEvaluationContextfor the specifiedPropertyAccessordelegates: typically a customPropertyAccessorspecific to a use case (e.g. attribute resolution in a custom data structure), potentially combined with aDataBindingPropertyAccessorif property dereferences are needed as well.- 参数:
accessors- the accessor delegates to use- 另请参阅:
-
forReadOnlyDataBinding
Create aSimpleEvaluationContextfor read-only access to public properties viaDataBindingPropertyAccessor. -
forReadWriteDataBinding
Create aSimpleEvaluationContextfor read-write access to public properties viaDataBindingPropertyAccessor.
-