Top Description Fields Constructors Methods
org.springframework.expression.spel.standard

public Class SpelExpression

extends Object
implements Expression
Class Inheritance
All Implemented Interfaces
org.springframework.expression.Expression
Imports
java.util.concurrent.atomic.AtomicInteger, org.springframework.core.convert.TypeDescriptor, org.springframework.expression.EvaluationContext, .EvaluationException, .Expression, .TypedValue, org.springframework.expression.common.ExpressionUtils, org.springframework.expression.spel.CompiledExpression, .ExpressionState, .SpelCompilerMode, .SpelEvaluationException, .SpelMessage, .SpelNode, .SpelParserConfiguration, org.springframework.expression.spel.ast.SpelNodeImpl, org.springframework.expression.spel.support.StandardEvaluationContext, org.springframework.lang.Nullable, org.springframework.util.Assert

A SpelExpression represents a parsed (valid) expression that is ready to be evaluated in a specified context. An expression can be evaluated standalone or in a specified context. During expression evaluation the context may be asked to resolve references to types, beans, properties, and methods.
Authors
Andy Clement, Juergen Hoeller, Sam Brannen
Since
3.0

Field Summary

Modifier and TypeField and Description
private final SpelNodeImpl
private volatile CompiledExpression
private final SpelParserConfiguration
private EvaluationContext
private final String
private static final int
private final AtomicInteger
private static final int
private final AtomicInteger

Constructor Summary

AccessConstructor and Description
public
SpelExpression(String expression, SpelNodeImpl ast, SpelParserConfiguration configuration)

Construct an expression, only used by the parser.

Method Summary

Modifier and TypeMethod and Description
private void
checkCompile(ExpressionState
the expression state used to determine compilation mode
expressionState
)

Compile the expression if it has been evaluated more than the threshold number of times to trigger compilation.

public boolean

Returns:

whether this expression has been successfully compiled
compileExpression
()

Perform expression compilation.

public SpelNode
getAST()

Return the Abstract Syntax Tree for the expression.

public EvaluationContext

Returns:

the default evaluation context
getEvaluationContext
()

Return the default evaluation context that will be used if none is supplied on an evaluation call.

public String
getExpressionString()

Implements org.springframework.expression.Expression.getExpressionString.

Return the original string used to create this expression (unmodified).

public Object
getValue()

Implements org.springframework.expression.Expression.getValue.

Evaluate this expression in the default standard context.

public <T> T
getValue(Class<T>
the type the caller would like the result to be
expectedResultType
)

Implements org.springframework.expression.Expression.getValue.

Evaluate this expression in the default context.

public Object
getValue(Object
the root object against which to evaluate the expression
rootObject
)

Implements org.springframework.expression.Expression.getValue.

Evaluate this expression against the specified root object.

public <T> T
getValue(Object
the root object against which to evaluate the expression
rootObject
,
Class<T>
the type the caller would like the result to be
expectedResultType
)

Implements org.springframework.expression.Expression.getValue.

Evaluate this expression in the default context against the specified root object.

public Object
getValue(EvaluationContext
the context in which to evaluate the expression
context
)

Implements org.springframework.expression.Expression.getValue.

Evaluate this expression in the provided context and return the result of evaluation.

public <T> T
getValue(EvaluationContext
the context in which to evaluate the expression
context
,
Class<T>
the type the caller would like the result to be
expectedResultType
)

Implements org.springframework.expression.Expression.getValue.

Evaluate this expression in the provided context which can resolve references to properties, methods, types, etc. The type of the evaluation result is expected to be of a particular type, and an exception will be thrown if it is not and cannot be converted to that type.

public Object
getValue(EvaluationContext
the context in which to evaluate the expression
context
,
Object
the root object against which to evaluate the expression
rootObject
)

Implements org.springframework.expression.Expression.getValue.

Evaluate this expression in the provided context and return the result of evaluation, but use the supplied root context as an override for any default root object specified in the context.

public <T> T
getValue(EvaluationContext
the context in which to evaluate the expression
context
,
Object
the root object against which to evaluate the expression
rootObject
,
Class<T>
the type the caller would like the result to be
expectedResultType
)

Implements org.springframework.expression.Expression.getValue.

Evaluate this expression in the provided context which can resolve references to properties, methods, types, etc. The type of the evaluation result is expected to be of a particular type, and an exception will be thrown if it is not and cannot be converted to that type.j

The supplied root object overrides any specified in the supplied context.

public Class<?>
getValueType()

Implements org.springframework.expression.Expression.getValueType.

Return the most general type that can be passed to the setValue(EvaluationContext, Object) method using the default context.

public Class<?>
getValueType(Object
the root object against which to evaluate the expression
rootObject
)

Implements org.springframework.expression.Expression.getValueType.

Return the most general type that can be passed to the setValue(Object, Object) method using the default context.

public Class<?>
getValueType(EvaluationContext
the context in which to evaluate the expression
context
)

Implements org.springframework.expression.Expression.getValueType.

Return the most general type that can be passed to the setValue(EvaluationContext, Object) method for the given context.

public Class<?>
getValueType(EvaluationContext
the context in which to evaluate the expression
context
,
Object
the root object against which to evaluate the expression
rootObject
)

Implements org.springframework.expression.Expression.getValueType.

Return the most general type that can be passed to the setValue(EvaluationContext, Object, Object) method for the given context.

public TypeDescriptor
getValueTypeDescriptor()

Implements org.springframework.expression.Expression.getValueTypeDescriptor.

Return a descriptor for the most general type that can be passed to one of the setValue(...) methods using the default context.

public TypeDescriptor
getValueTypeDescriptor(Object
the root object against which to evaluate the expression
rootObject
)

Implements org.springframework.expression.Expression.getValueTypeDescriptor.

Return a descriptor for the most general type that can be passed to the setValue(Object, Object) method using the default context.

public TypeDescriptor
getValueTypeDescriptor(EvaluationContext
the context in which to evaluate the expression
context
)

Implements org.springframework.expression.Expression.getValueTypeDescriptor.

Return a descriptor for the most general type that can be passed to the setValue(EvaluationContext, Object) method for the given context.

public TypeDescriptor
getValueTypeDescriptor(EvaluationContext
the context in which to evaluate the expression
context
,
Object
the root object against which to evaluate the expression
rootObject
)

Implements org.springframework.expression.Expression.getValueTypeDescriptor.

Return a descriptor for the most general type that can be passed to the setValue(EvaluationContext, Object, Object) method for the given context.

public boolean
isWritable(Object
the root object against which to evaluate the expression
rootObject
)

Implements org.springframework.expression.Expression.isWritable.

Determine if this expression can be written to, i.e. setValue() can be called.

public boolean
isWritable(EvaluationContext
the context in which the expression should be checked
context
)

Implements org.springframework.expression.Expression.isWritable.

Determine if this expression can be written to, i.e. setValue() can be called.

public boolean
isWritable(EvaluationContext
the context in which the expression should be checked
context
,
Object
the root object against which to evaluate the expression
rootObject
)

Implements org.springframework.expression.Expression.isWritable.

Determine if this expression can be written to, i.e. setValue() can be called.

public void
revertToInterpreted()

Cause an expression to revert to being interpreted if it has been using a compiled form.

public void
setEvaluationContext(EvaluationContext
the evaluation context to use
evaluationContext
)

Set the evaluation context that will be used if none is specified on an evaluation call.

public void
setValue(Object
the root object against which to evaluate the expression
rootObject
,
Object
the new value
value
)

Implements org.springframework.expression.Expression.setValue.

Set this expression in the provided context to the value provided.

public void
setValue(EvaluationContext
the context in which to set the value of the expression
context
,
Object
the new value
value
)

Implements org.springframework.expression.Expression.setValue.

Set this expression in the provided context to the value provided.

public void
setValue(EvaluationContext
the context in which to set the value of the expression
context
,
Object
the root object against which to evaluate the expression
rootObject
,
Object
the new value
value
)

Implements org.springframework.expression.Expression.setValue.

Set this expression in the provided context to the value provided.

public String

Returns:

the string representation of the AST
toStringAST
()

Produce a string representation of the Abstract Syntax Tree for the expression.

private TypedValue
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

astback to summary
private final SpelNodeImpl ast
compiledAstback to summary
private volatile CompiledExpression compiledAst
Annotations
@Nullable
configurationback to summary
private final SpelParserConfiguration configuration
evaluationContextback to summary
private EvaluationContext evaluationContext
Annotations
@Nullable
expressionback to summary
private final String expression
FAILED_ATTEMPTS_THRESHOLDback to summary
private static final int FAILED_ATTEMPTS_THRESHOLD
failedAttemptsback to summary
private final AtomicInteger failedAttempts
INTERPRETED_COUNT_THRESHOLDback to summary
private static final int INTERPRETED_COUNT_THRESHOLD
interpretedCountback to summary
private final AtomicInteger interpretedCount

Constructor Detail

SpelExpressionback to summary
public SpelExpression(String expression, SpelNodeImpl ast, SpelParserConfiguration configuration)

Construct an expression, only used by the parser.

Method Detail

checkCompileback to summary
private void checkCompile(ExpressionState expressionState)

Compile the expression if it has been evaluated more than the threshold number of times to trigger compilation.

Parameters
expressionState:ExpressionState

the expression state used to determine compilation mode

compileExpressionback to summary
public boolean compileExpression()

Perform expression compilation. This will only succeed once exit descriptors for all nodes have been determined. If the compilation fails and has failed more than 100 times the expression is no longer considered suitable for compilation.

Returns:boolean

whether this expression has been successfully compiled

getASTback to summary
public SpelNode getAST()

Return the Abstract Syntax Tree for the expression.

getEvaluationContextback to summary
public EvaluationContext getEvaluationContext()

Return the default evaluation context that will be used if none is supplied on an evaluation call.

Returns:EvaluationContext

the default evaluation context

getExpressionStringback to summary
public String getExpressionString()

Implements org.springframework.expression.Expression.getExpressionString.

Doc from org.springframework.expression.Expression.getExpressionString.

Return the original string used to create this expression (unmodified).

Returns:String

the original expression string

Annotations
@Override
getValueback to summary
public Object getValue() throws EvaluationException

Implements org.springframework.expression.Expression.getValue.

Doc from org.springframework.expression.Expression.getValue.

Evaluate this expression in the default standard context.

Returns:Object

the evaluation result

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem during evaluation
getValueback to summary
public <T> T getValue(Class<T> expectedResultType) throws EvaluationException

Implements org.springframework.expression.Expression.getValue.

Doc from org.springframework.expression.Expression.getValue.

Evaluate this expression in the default context. If the result of the evaluation does not match (and cannot be converted to) the expected result type then an exception will be thrown.

Parameters
expectedResultType:Class<T>

the type the caller would like the result to be

Returns:T

the evaluation result

Annotations
@SuppressWarnings:unchecked
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem during evaluation
getValueback to summary
public Object getValue(Object rootObject) throws EvaluationException

Implements org.springframework.expression.Expression.getValue.

Doc from org.springframework.expression.Expression.getValue.

Evaluate this expression against the specified root object.

Parameters
rootObject:Object

the root object against which to evaluate the expression

Returns:Object

the evaluation result

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem during evaluation
getValueback to summary
public <T> T getValue(Object rootObject, Class<T> expectedResultType) throws EvaluationException

Implements org.springframework.expression.Expression.getValue.

Doc from org.springframework.expression.Expression.getValue.

Evaluate this expression in the default context against the specified root object. If the result of the evaluation does not match (and cannot be converted to) the expected result type then an exception will be thrown.

Parameters
rootObject:Object

the root object against which to evaluate the expression

expectedResultType:Class<T>

the type the caller would like the result to be

Returns:T

the evaluation result

Annotations
@SuppressWarnings:unchecked
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem during evaluation
getValueback to summary
public Object getValue(EvaluationContext context) throws EvaluationException

Implements org.springframework.expression.Expression.getValue.

Doc from org.springframework.expression.Expression.getValue.

Evaluate this expression in the provided context and return the result of evaluation.

Parameters
context:EvaluationContext

the context in which to evaluate the expression

Returns:Object

the evaluation result

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem during evaluation
getValueback to summary
public <T> T getValue(EvaluationContext context, Class<T> expectedResultType) throws EvaluationException

Implements org.springframework.expression.Expression.getValue.

Doc from org.springframework.expression.Expression.getValue.

Evaluate this expression in the provided context which can resolve references to properties, methods, types, etc. The type of the evaluation result is expected to be of a particular type, and an exception will be thrown if it is not and cannot be converted to that type.

Parameters
context:EvaluationContext

the context in which to evaluate the expression

expectedResultType:Class<T>

the type the caller would like the result to be

Returns:T

the evaluation result

Annotations
@SuppressWarnings:unchecked
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem during evaluation
getValueback to summary
public Object getValue(EvaluationContext context, Object rootObject) throws EvaluationException

Implements org.springframework.expression.Expression.getValue.

Doc from org.springframework.expression.Expression.getValue.

Evaluate this expression in the provided context and return the result of evaluation, but use the supplied root context as an override for any default root object specified in the context.

Parameters
context:EvaluationContext

the context in which to evaluate the expression

rootObject:Object

the root object against which to evaluate the expression

Returns:Object

the evaluation result

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem during evaluation
getValueback to summary
public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> expectedResultType) throws EvaluationException

Implements org.springframework.expression.Expression.getValue.

Doc from org.springframework.expression.Expression.getValue.

Evaluate this expression in the provided context which can resolve references to properties, methods, types, etc. The type of the evaluation result is expected to be of a particular type, and an exception will be thrown if it is not and cannot be converted to that type.j

The supplied root object overrides any specified in the supplied context.

Parameters
context:EvaluationContext

the context in which to evaluate the expression

rootObject:Object

the root object against which to evaluate the expression

expectedResultType:Class<T>

the type the caller would like the result to be

Returns:T

the evaluation result

Annotations
@SuppressWarnings:unchecked
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem during evaluation
getValueTypeback to summary
public Class<?> getValueType() throws EvaluationException

Implements org.springframework.expression.Expression.getValueType.

Doc from org.springframework.expression.Expression.getValueType.

Return the most general type that can be passed to the setValue(EvaluationContext, Object) method using the default context.

Returns:Class<?>

the most general type of value that can be set in this context

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem determining the type
getValueTypeback to summary
public Class<?> getValueType(Object rootObject) throws EvaluationException

Implements org.springframework.expression.Expression.getValueType.

Doc from org.springframework.expression.Expression.getValueType.

Return the most general type that can be passed to the setValue(Object, Object) method using the default context.

Parameters
rootObject:Object

the root object against which to evaluate the expression

Returns:Class<?>

the most general type of value that can be set in this context

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem determining the type
getValueTypeback to summary
public Class<?> getValueType(EvaluationContext context) throws EvaluationException

Implements org.springframework.expression.Expression.getValueType.

Doc from org.springframework.expression.Expression.getValueType.

Return the most general type that can be passed to the setValue(EvaluationContext, Object) method for the given context.

Parameters
context:EvaluationContext

the context in which to evaluate the expression

Returns:Class<?>

the most general type of value that can be set in this context

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem determining the type
getValueTypeback to summary
public Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException

Implements org.springframework.expression.Expression.getValueType.

Doc from org.springframework.expression.Expression.getValueType.

Return the most general type that can be passed to the setValue(EvaluationContext, Object, Object) method for the given context.

The supplied root object overrides any specified in the supplied context.

Parameters
context:EvaluationContext

the context in which to evaluate the expression

rootObject:Object

the root object against which to evaluate the expression

Returns:Class<?>

the most general type of value that can be set in this context

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem determining the type
getValueTypeDescriptorback to summary
public TypeDescriptor getValueTypeDescriptor() throws EvaluationException

Implements org.springframework.expression.Expression.getValueTypeDescriptor.

Doc from org.springframework.expression.Expression.getValueTypeDescriptor.

Return a descriptor for the most general type that can be passed to one of the setValue(...) methods using the default context.

Returns:TypeDescriptor

a type descriptor for values that can be set in this context

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem determining the type
getValueTypeDescriptorback to summary
public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException

Implements org.springframework.expression.Expression.getValueTypeDescriptor.

Doc from org.springframework.expression.Expression.getValueTypeDescriptor.

Return a descriptor for the most general type that can be passed to the setValue(Object, Object) method using the default context.

Parameters
rootObject:Object

the root object against which to evaluate the expression

Returns:TypeDescriptor

a type descriptor for values that can be set in this context

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem determining the type
getValueTypeDescriptorback to summary
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) throws EvaluationException

Implements org.springframework.expression.Expression.getValueTypeDescriptor.

Doc from org.springframework.expression.Expression.getValueTypeDescriptor.

Return a descriptor for the most general type that can be passed to the setValue(EvaluationContext, Object) method for the given context.

Parameters
context:EvaluationContext

the context in which to evaluate the expression

Returns:TypeDescriptor

a type descriptor for values that can be set in this context

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem determining the type
getValueTypeDescriptorback to summary
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException

Implements org.springframework.expression.Expression.getValueTypeDescriptor.

Doc from org.springframework.expression.Expression.getValueTypeDescriptor.

Return a descriptor for the most general type that can be passed to the setValue(EvaluationContext, Object, Object) method for the given context.

The supplied root object overrides any specified in the supplied context.

Parameters
context:EvaluationContext

the context in which to evaluate the expression

rootObject:Object

the root object against which to evaluate the expression

Returns:TypeDescriptor

a type descriptor for values that can be set in this context

Annotations
@Override
@Nullable
Exceptions
EvaluationException:
if there is a problem determining the type
isWritableback to summary
public boolean isWritable(Object rootObject) throws EvaluationException

Implements org.springframework.expression.Expression.isWritable.

Doc from org.springframework.expression.Expression.isWritable.

Determine if this expression can be written to, i.e. setValue() can be called.

Parameters
rootObject:Object

the root object against which to evaluate the expression

Returns:boolean

true if the expression is writable; false otherwise

Annotations
@Override
Exceptions
EvaluationException:
if there is a problem determining if it is writable
isWritableback to summary
public boolean isWritable(EvaluationContext context) throws EvaluationException

Implements org.springframework.expression.Expression.isWritable.

Doc from org.springframework.expression.Expression.isWritable.

Determine if this expression can be written to, i.e. setValue() can be called.

Parameters
context:EvaluationContext

the context in which the expression should be checked

Returns:boolean

true if the expression is writable; false otherwise

Annotations
@Override
Exceptions
EvaluationException:
if there is a problem determining if it is writable
isWritableback to summary
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException

Implements org.springframework.expression.Expression.isWritable.

Doc from org.springframework.expression.Expression.isWritable.

Determine if this expression can be written to, i.e. setValue() can be called.

The supplied root object overrides any specified in the supplied context.

Parameters
context:EvaluationContext

the context in which the expression should be checked

rootObject:Object

the root object against which to evaluate the expression

Returns:boolean

true if the expression is writable; false otherwise

Annotations
@Override
Exceptions
EvaluationException:
if there is a problem determining if it is writable
revertToInterpretedback to summary
public void revertToInterpreted()

Cause an expression to revert to being interpreted if it has been using a compiled form. It also resets the compilation attempt failure count (an expression is normally no longer considered compilable if it cannot be compiled after 100 attempts).

setEvaluationContextback to summary
public void setEvaluationContext(EvaluationContext evaluationContext)

Set the evaluation context that will be used if none is specified on an evaluation call.

Parameters
evaluationContext:EvaluationContext

the evaluation context to use

setValueback to summary
public void setValue(Object rootObject, Object value) throws EvaluationException

Implements org.springframework.expression.Expression.setValue.

Doc from org.springframework.expression.Expression.setValue.

Set this expression in the provided context to the value provided.

Parameters
rootObject:Object

the root object against which to evaluate the expression

value:Object

the new value

Annotations
@Override
Exceptions
EvaluationException:
if there is a problem during evaluation
setValueback to summary
public void setValue(EvaluationContext context, Object value) throws EvaluationException

Implements org.springframework.expression.Expression.setValue.

Doc from org.springframework.expression.Expression.setValue.

Set this expression in the provided context to the value provided.

Parameters
context:EvaluationContext

the context in which to set the value of the expression

value:Object

the new value

Annotations
@Override
Exceptions
EvaluationException:
if there is a problem during evaluation
setValueback to summary
public void setValue(EvaluationContext context, Object rootObject, Object value) throws EvaluationException

Implements org.springframework.expression.Expression.setValue.

Doc from org.springframework.expression.Expression.setValue.

Set this expression in the provided context to the value provided.

The supplied root object overrides any specified in the supplied context.

Parameters
context:EvaluationContext

the context in which to set the value of the expression

rootObject:Object

the root object against which to evaluate the expression

value:Object

the new value

Annotations
@Override
Exceptions
EvaluationException:
if there is a problem during evaluation
toStringASTback to summary
public String toStringAST()

Produce a string representation of the Abstract Syntax Tree for the expression. This should ideally look like the input expression, but properly formatted since any unnecessary whitespace will have been discarded during the parse of the expression.

Returns:String

the string representation of the AST

toTypedValueback to summary
private TypedValue toTypedValue(Object object)