public class

SpelExpression

extends Object
implements Expression
java.lang.Object
   ↳ org.springframework.expression.spel.standard.SpelExpression

Class Overview

A SpelExpressions 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, methods.

Summary

Public Constructors
SpelExpression(String expression, SpelNodeImpl ast, SpelParserConfiguration configuration)
Construct an expression, only used by the parser.
Public Methods
SpelNode getAST()
EvaluationContext getEvaluationContext()
Return the default evaluation context that will be used if none is supplied on an evaluation call
String getExpressionString()
Returns the original string used to create this expression, unmodified.
Object getValue(Object rootObject)
Evaluate this expression against the specified root object
<T> T getValue(Object rootObject, Class<T> expectedResultType)
Evaluate the expression in the default context against the specified root object.
<T> T getValue(Class<T> expectedResultType)
Evaluate the expression in the default context.
Object getValue(EvaluationContext context, Object rootObject)
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.
<T> T getValue(EvaluationContext context, Object rootObject, Class<T> expectedResultType)
Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc - the type of the evaluation result is expected to be of a particular class and an exception will be thrown if it is not and cannot be converted to that type.
<T> T getValue(EvaluationContext context, Class<T> expectedResultType)
Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc - the type of the evaluation result is expected to be of a particular class and an exception will be thrown if it is not and cannot be converted to that type.
Object getValue()
Evaluate this expression in the default standard context.
Object getValue(EvaluationContext context)
Evaluate this expression in the provided context and return the result of evaluation.
Class getValueType(Object rootObject)
Returns the most general type that can be passed to the setValue(EvaluationContext, Object) method using the default context.
Class getValueType(EvaluationContext context)
Returns the most general type that can be passed to the setValue(EvaluationContext, Object) method for the given context.
Class getValueType()
Returns the most general type that can be passed to the setValue(EvaluationContext, Object) method using the default context.
Class getValueType(EvaluationContext context, Object rootObject)
Returns the most general type that can be passed to the setValue(EvaluationContext, Object) method for the given context.
TypeDescriptor getValueTypeDescriptor()
Returns the most general type that can be passed to the setValue(EvaluationContext, Object) method using the default context.
TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject)
Returns the most general type that can be passed to the setValue(EvaluationContext, Object) method for the given context.
TypeDescriptor getValueTypeDescriptor(EvaluationContext context)
Returns the most general type that can be passed to the setValue(EvaluationContext, Object) method for the given context.
TypeDescriptor getValueTypeDescriptor(Object rootObject)
Returns the most general type that can be passed to the setValue(EvaluationContext, Object) method using the default context.
boolean isWritable(Object rootObject)
Determine if an expression can be written to, i.e.
boolean isWritable(EvaluationContext context)
Determine if an expression can be written to, i.e.
boolean isWritable(EvaluationContext context, Object rootObject)
Determine if an expression can be written to, i.e.
void setEvaluationContext(EvaluationContext context)
Set the evaluation context that will be used if none is specified on an evaluation call.
void setValue(EvaluationContext context, Object value)
Set this expression in the provided context to the value provided.
void setValue(EvaluationContext context, Object rootObject, Object value)
Set this expression in the provided context to the value provided.
void setValue(Object rootObject, Object value)
Set this expression in the provided context to the value provided.
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.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.expression.Expression

Public Constructors

public SpelExpression (String expression, SpelNodeImpl ast, SpelParserConfiguration configuration)

Construct an expression, only used by the parser.

Public Methods

public SpelNode getAST ()

Returns
  • return the Abstract Syntax Tree for the expression

public EvaluationContext getEvaluationContext ()

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

Returns
  • the default evaluation context

public String getExpressionString ()

Returns the original string used to create this expression, unmodified.

Returns
  • the original expression string

public Object getValue (Object rootObject)

Evaluate this expression against the specified root object

Parameters
rootObject the root object against which properties/etc will be resolved
Returns
  • the evaluation result

public T getValue (Object rootObject, Class<T> expectedResultType)

Evaluate the 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 returned.

Parameters
rootObject the root object against which properties/etc will be resolved
expectedResultType the class the caller would like the result to be
Returns
  • the evaluation result

public T getValue (Class<T> expectedResultType)

Evaluate the 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 returned.

Parameters
expectedResultType the class the caller would like the result to be
Returns
  • the evaluation result

public Object getValue (EvaluationContext context, Object rootObject)

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 the context in which to evaluate the expression
rootObject the root object against which properties/etc will be resolved
Returns
  • the evaluation result

public T getValue (EvaluationContext context, Object rootObject, Class<T> expectedResultType)

Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc - the type of the evaluation result is expected to be of a particular class and an exception will be thrown if it is not and cannot be converted to that type. The supplied root object overrides any default specified on the supplied context.

Parameters
context the context in which to evaluate the expression
rootObject the root object against which properties/etc will be resolved
expectedResultType the class the caller would like the result to be
Returns
  • the evaluation result

public T getValue (EvaluationContext context, Class<T> expectedResultType)

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

Parameters
context the context in which to evaluate the expression
expectedResultType the class the caller would like the result to be
Returns
  • the evaluation result

public Object getValue ()

Evaluate this expression in the default standard context.

Returns
  • the evaluation result

public Object getValue (EvaluationContext context)

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

Parameters
context the context in which to evaluate the expression
Returns
  • the evaluation result

public Class getValueType (Object rootObject)

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

Parameters
rootObject the root object against which to evaluate the expression
Returns
  • the most general type of value that can be set on this context

public Class getValueType (EvaluationContext context)

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

Parameters
context the context in which to evaluate the expression
Returns
  • the most general type of value that can be set on this context

public Class getValueType ()

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

Returns
  • the most general type of value that can be set on this context

public Class getValueType (EvaluationContext context, Object rootObject)

Returns the most general type that can be passed to the setValue(EvaluationContext, Object) method for the given context. The supplied root object overrides any specified in the context.

Parameters
context the context in which to evaluate the expression
rootObject the root object against which to evaluate the expression
Returns
  • the most general type of value that can be set on this context

public TypeDescriptor getValueTypeDescriptor ()

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

Returns
  • a type descriptor for the most general type of value that can be set on this context

public TypeDescriptor getValueTypeDescriptor (EvaluationContext context, Object rootObject)

Returns the most general type that can be passed to the setValue(EvaluationContext, Object) method for the given context. The supplied root object overrides any specified in the context.

Parameters
context the context in which to evaluate the expression
rootObject the root object against which to evaluate the expression
Returns
  • a type descriptor for the most general type of value that can be set on this context

public TypeDescriptor getValueTypeDescriptor (EvaluationContext context)

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

Parameters
context the context in which to evaluate the expression
Returns
  • a type descriptor for the most general type of value that can be set on this context

public TypeDescriptor getValueTypeDescriptor (Object rootObject)

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

Parameters
rootObject the root object against which to evaluate the expression
Returns
  • a type descriptor for the most general type of value that can be set on this context

public boolean isWritable (Object rootObject)

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

Parameters
rootObject the root object against which to evaluate the expression
Returns
  • true if the expression is writable

public boolean isWritable (EvaluationContext context)

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

Parameters
context the context in which the expression should be checked
Returns
  • true if the expression is writable

public boolean isWritable (EvaluationContext context, Object rootObject)

Determine if an expression can be written to, i.e. setValue() can be called. The supplied root object overrides any specified in the context.

Parameters
context the context in which the expression should be checked
rootObject the root object against which to evaluate the expression
Returns
  • true if the expression is writable

public void setEvaluationContext (EvaluationContext context)

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

Parameters
context an evaluation context

public void setValue (EvaluationContext context, Object value)

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

Parameters
context the context in which to set the value of the expression
value the new value

public void setValue (EvaluationContext context, Object rootObject, Object value)

Set this expression in the provided context to the value provided. The supplied root object overrides any specified in the context.

Parameters
context the context in which to set the value of the expression
rootObject the root object against which to evaluate the expression
value the new value

public void setValue (Object rootObject, Object value)

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

Parameters
rootObject the root object against which to evaluate the expression
value the new value

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
  • the string representation of the AST