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:
PropertyAccessor (typically not reflection-based),
potentially combined with a DataBindingPropertyAccessorConveniently, SimpleEvaluationContext#forReadOnlyDataBinding()
enables read access to properties via DataBindingPropertyAccessor;
same for SimpleEvaluationContext#forReadWriteDataBinding() when
write access is needed as well. Alternatively, configure custom accessors
via SimpleEvaluationContext#forPropertyAccessors, 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
org. with both an
EvaluationContext and a root object as arguments:
org..
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.
forPropertyAccessors, forReadOnlyDataBinding(), forReadWriteDataBinding(), StandardEvaluationContext, StandardTypeConverter, DataBindingPropertyAccessor, DataBindingMethodResolver
| Modifier and Type | Class and Description |
|---|---|
| public static class | SimpleEvaluationContext.Builder
Builder for |
| Modifier and Type | Field and Description |
|---|---|
| private final List | |
| private final OperatorOverloader | |
| private final List | |
| private final TypedValue | |
| private final TypeComparator | |
| private final TypeConverter | |
| private static final TypeLocator | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| private | SimpleEvaluationContext(List<PropertyAccessor> accessors, List<MethodResolver> resolvers, TypeConverter converter, TypedValue rootObject)
|
| Modifier and Type | Method and Description |
|---|---|
| public TypedValue | assignVariable(String
the name of the variable to assign name, Supplier<TypedValue> the supplier of the value to be assigned to the variable valueSupplier)Overrides default org. SimpleEvaluationContext does not support variable assignment within
expressions.
|
| public static SimpleEvaluationContext. | forPropertyAccessors(PropertyAccessor...
the accessor delegates to use accessors)Create a |
| public static SimpleEvaluationContext. | forReadOnlyDataBinding()
Create a |
| public static SimpleEvaluationContext. | forReadWriteDataBinding()
Create a |
| public BeanResolver | Returns: alwaysnullImplements org. SimpleEvaluationContext does not support the use of bean references.
|
| public List | getConstructorResolvers()
Implements org. |
| public List | getMethodResolvers()
Implements org. MethodResolver delegates, if any.
|
| public OperatorOverloader | getOperatorOverloader()
Implements org. StandardOperatorOverloader.
|
| public List | getPropertyAccessors()
Implements org. PropertyAccessor delegates, if any.
|
| public TypedValue | getRootObject()
Implements org. |
| public TypeComparator | getTypeComparator()
Implements org. StandardTypeComparator.
|
| public TypeConverter | getTypeConverter()
Implements org. TypeConverter.
|
| public TypeLocator | Returns: TypeLocator implementation that raises a
SpelEvaluationException with SpelMessage#TYPE_NOT_FOUNDImplements org. SimpleEvaluationContext does not support use of type references.
|
| public Object | Returns: the value of the variable or function, ornull if not foundthe name of the variable or function to look up name)Implements org. |
| public void | setVariable(String
the name of the variable or function to set name, Object the value to be placed in the variable or function value)Implements org. |
| methodResolvers | back to summary |
|---|---|
| private final List<MethodResolver> methodResolvers | |
| operatorOverloader | back to summary |
|---|---|
| private final OperatorOverloader operatorOverloader | |
| propertyAccessors | back to summary |
|---|---|
| private final List<PropertyAccessor> propertyAccessors | |
| rootObject | back to summary |
|---|---|
| private final TypedValue rootObject | |
| typeComparator | back to summary |
|---|---|
| private final TypeComparator typeComparator | |
| typeConverter | back to summary |
|---|---|
| private final TypeConverter typeConverter | |
| typeNotFoundTypeLocator | back to summary |
|---|---|
| private static final TypeLocator typeNotFoundTypeLocator | |
| variables | back to summary |
|---|---|
| private final Map<String, Object> variables | |
| SimpleEvaluationContext | back to summary |
|---|---|
| private SimpleEvaluationContext(List<PropertyAccessor> accessors, List<MethodResolver> resolvers, TypeConverter converter, TypedValue rootObject) | |
| assignVariable | back to summary |
|---|---|
| public TypedValue assignVariable(String name, Supplier<TypedValue> valueSupplier) Overrides default org.
| |
| forPropertyAccessors | back to summary |
|---|---|
| public static SimpleEvaluationContext. Create a
| |
| forReadOnlyDataBinding | back to summary |
|---|---|
| public static SimpleEvaluationContext. Create a | |
| forReadWriteDataBinding | back to summary |
|---|---|
| public static SimpleEvaluationContext. Create a | |
| getBeanResolver | back to summary |
|---|---|
| public BeanResolver getBeanResolver() Implements org.
| |
| getConstructorResolvers | back to summary |
|---|---|
| public List Implements org. Return an empty list, always, since this context does not support the use of type references.
| |
| getMethodResolvers | back to summary |
|---|---|
| public List Implements org. Return the specified
| |
| getOperatorOverloader | back to summary |
|---|---|
| public OperatorOverloader getOperatorOverloader() Implements org. Return an instance of
| |
| getPropertyAccessors | back to summary |
|---|---|
| public List Implements org. Return the specified
| |
| getRootObject | back to summary |
|---|---|
| public TypedValue getRootObject() Implements org. Return the specified root object, if any.
| |
| getTypeComparator | back to summary |
|---|---|
| public TypeComparator getTypeComparator() Implements org. Return an instance of
| |
| getTypeConverter | back to summary |
|---|---|
| public TypeConverter getTypeConverter() Implements org. The configured By default this is
| |
| getTypeLocator | back to summary |
|---|---|
| public TypeLocator getTypeLocator() Implements org.
| |
| lookupVariable | back to summary |
|---|---|
| public Object lookupVariable(String name) Implements org. 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. | |
| setVariable | back to summary |
|---|---|
| public void setVariable(String name, Object value) Implements org. Set a named variable or function in this evaluation context to the specified value. A function can be registered as a Note that variables and functions share a common namespace in this evaluation context. See the class-level documentation for details.
| |
SimpleEvaluationContext.
| Modifier and Type | Field and Description |
|---|---|
| private final List | |
| private List | |
| private TypedValue | |
| private TypeConverter |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public SimpleEvaluationContext | |
| public SimpleEvaluationContext. | |
| public SimpleEvaluationContext. | withInstanceMethods()
Register a |
| public SimpleEvaluationContext. | withMethodResolvers(MethodResolver...
the resolver delegates to use resolvers)Register the specified |
| public SimpleEvaluationContext. | |
| public SimpleEvaluationContext. | |
| public SimpleEvaluationContext. | withTypedRootObject(Object rootObject, TypeDescriptor typeDescriptor)
Specify a typed root object to resolve against. |
| accessors | back to summary |
|---|---|
| private final List<PropertyAccessor> accessors | |
| resolvers | back to summary |
|---|---|
| private List<MethodResolver> resolvers | |
| rootObject | back to summary |
|---|---|
| private TypedValue rootObject
| |
| typeConverter | back to summary |
|---|---|
| private TypeConverter typeConverter
| |
| Builder | back to summary |
|---|---|
| private Builder(PropertyAccessor... accessors) | |
| build | back to summary |
|---|---|
| public SimpleEvaluationContext build() | |
| withConversionService | back to summary |
|---|---|
| public SimpleEvaluationContext. Register a custom By default a | |
| withInstanceMethods | back to summary |
|---|---|
| public SimpleEvaluationContext. Register a | |
| withMethodResolvers | back to summary |
|---|---|
| public SimpleEvaluationContext. Register the specified
| |
| withRootObject | back to summary |
|---|---|
| public SimpleEvaluationContext. Specify a default root object to resolve against. Default is none, expecting an object argument at evaluation time. | |
| withTypeConverter | back to summary |
|---|---|
| public SimpleEvaluationContext. Register a custom By default a | |
| withTypedRootObject | back to summary |
|---|---|
| public SimpleEvaluationContext. Specify a typed root object to resolve against. Default is none, expecting an object argument at evaluation time. | |