org.springframework.expression.spel
Class SpelExpression

java.lang.Object
  extended by org.springframework.expression.spel.SpelExpression
All Implemented Interfaces:
Expression

public class SpelExpression
extends Object
implements Expression

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.

Since:
3.0
Author:
Andy Clement

Field Summary
 SpelNodeImpl ast
           
 int configuration
           
 
Constructor Summary
SpelExpression(String expression, SpelNodeImpl ast, int configuration)
          Construct an expression, only used by the parser.
 
Method Summary
 SpelNode getAST()
           
 String getExpressionString()
          Returns the original string used to create this expression, unmodified.
 Object getValue()
          Evaluate this expression in the default standard context.
<T> T
getValue(Class<T> expectedResultType)
          Evaluate the expression in the default standard context.
 Object getValue(EvaluationContext context)
          Evaluate this expression in the provided context and return the result of evaluation.
<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.
 Class getValueType()
          Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method using the default context.
 Class getValueType(EvaluationContext context)
          Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method for the given context.
 TypeDescriptor getValueTypeDescriptor()
          Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method using the default context.
 TypeDescriptor getValueTypeDescriptor(EvaluationContext context)
          Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method for the given context.
 boolean isWritable(EvaluationContext context)
          Determine if an expression can be written to, i.e.
 void setValue(EvaluationContext context, 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ast

public final SpelNodeImpl ast

configuration

public final int configuration
Constructor Detail

SpelExpression

public SpelExpression(String expression,
                      SpelNodeImpl ast,
                      int configuration)
Construct an expression, only used by the parser.

Method Detail

getValue

public Object getValue()
                throws EvaluationException
Description copied from interface: Expression
Evaluate this expression in the default standard context.

Specified by:
getValue in interface Expression
Returns:
the evaluation result
Throws:
EvaluationException - if there is a problem during evaluation

getValue

public <T> T getValue(Class<T> expectedResultType)
           throws EvaluationException
Description copied from interface: Expression
Evaluate the expression in the default standard 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.

Specified by:
getValue in interface Expression
Parameters:
expectedResultType - the class the caller would like the result to be
Returns:
the evaluation result
Throws:
EvaluationException - if there is a problem during evaluation

getValue

public Object getValue(EvaluationContext context)
                throws EvaluationException
Description copied from interface: Expression
Evaluate this expression in the provided context and return the result of evaluation.

Specified by:
getValue in interface Expression
Parameters:
context - the context in which to evaluate the expression
Returns:
the evaluation result
Throws:
EvaluationException - if there is a problem during evaluation

getValue

public <T> T getValue(EvaluationContext context,
                      Class<T> expectedResultType)
           throws EvaluationException
Description copied from interface: Expression
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.

Specified by:
getValue in interface Expression
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
Throws:
EvaluationException - if there is a problem during evaluation

getValueType

public Class getValueType()
                   throws EvaluationException
Description copied from interface: Expression
Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method using the default context.

Specified by:
getValueType in interface Expression
Returns:
the most general type of value that can be set on this context
Throws:
EvaluationException - if there is a problem determining the type

getValueType

public Class getValueType(EvaluationContext context)
                   throws EvaluationException
Description copied from interface: Expression
Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method for the given context.

Specified by:
getValueType in interface Expression
Parameters:
context - the context in which to evaluate the expression
Returns:
the most general type of value that can be set on this context
Throws:
EvaluationException - if there is a problem determining the type

getValueTypeDescriptor

public TypeDescriptor getValueTypeDescriptor()
                                      throws EvaluationException
Description copied from interface: Expression
Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method using the default context.

Specified by:
getValueTypeDescriptor in interface Expression
Returns:
a type descriptor for the most general type of value that can be set on this context
Throws:
EvaluationException - if there is a problem determining the type

getValueTypeDescriptor

public TypeDescriptor getValueTypeDescriptor(EvaluationContext context)
                                      throws EvaluationException
Description copied from interface: Expression
Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method for the given context.

Specified by:
getValueTypeDescriptor in interface Expression
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
Throws:
EvaluationException - if there is a problem determining the type

getExpressionString

public String getExpressionString()
Description copied from interface: Expression
Returns the original string used to create this expression, unmodified.

Specified by:
getExpressionString in interface Expression
Returns:
the original expression string

isWritable

public boolean isWritable(EvaluationContext context)
                   throws EvaluationException
Description copied from interface: Expression
Determine if an expression can be written to, i.e. setValue() can be called.

Specified by:
isWritable in interface Expression
Parameters:
context - the context in which the expression should be checked
Returns:
true if the expression is writable
Throws:
EvaluationException - if there is a problem determining if it is writable

setValue

public void setValue(EvaluationContext context,
                     Object value)
              throws EvaluationException
Description copied from interface: Expression
Set this expression in the provided context to the value provided.

Specified by:
setValue in interface Expression
Parameters:
context - the context in which to set the value of the expression
value - the new value
Throws:
EvaluationException - if there is a problem during evaluation

getAST

public SpelNode getAST()
Returns:
return the Abstract Syntax Tree for the expression

toStringAST

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