org.springframework.expression.common
Class CompositeStringExpression

java.lang.Object
  extended by org.springframework.expression.common.CompositeStringExpression
All Implemented Interfaces:
Expression

public class CompositeStringExpression
extends java.lang.Object
implements Expression

Represents a template expression broken into pieces. Each piece will be an Expression but pure text parts to the template will be represented as LiteralExpression objects. An example of a template expression might be:

 "Hello ${getName()}"
which will be represented as a CompositeStringExpression of two parts. The first part being a LiteralExpression representing 'Hello ' and the second part being a real expression that will call getName() when invoked.

Since:
3.0
Author:
Andy Clement, Juergen Hoeller

Field Summary
private  Expression[] expressions
          The array of expressions that make up the composite expression
private  java.lang.String expressionString
           
 
Constructor Summary
CompositeStringExpression(java.lang.String expressionString, Expression[] expressions)
           
 
Method Summary
 Expression[] getExpressions()
           
 java.lang.String getExpressionString()
          Returns the original string used to create this expression, unmodified.
 java.lang.String getValue()
          Evaluate this expression in the default standard context.
<T> T
getValue(java.lang.Class<T> expectedResultType)
          Evaluate the expression in the default context.
 java.lang.String getValue(EvaluationContext context)
          Evaluate this expression in the provided context and return the result of evaluation.
<T> T
getValue(EvaluationContext context, java.lang.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.
 java.lang.String getValue(EvaluationContext context, java.lang.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, java.lang.Object rootObject, java.lang.Class<T> desiredResultType)
          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.
 java.lang.String getValue(java.lang.Object rootObject)
          Evaluate this expression against the specified root object
<T> T
getValue(java.lang.Object rootObject, java.lang.Class<T> desiredResultType)
          Evaluate the expression in the default context against the specified root object.
 java.lang.Class getValueType()
          Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method using the default context.
 java.lang.Class getValueType(EvaluationContext context)
          Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method for the given context.
 java.lang.Class getValueType(EvaluationContext context, java.lang.Object rootObject)
          Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method for the given context.
 java.lang.Class getValueType(java.lang.Object rootObject)
          Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method using the default 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.
 TypeDescriptor getValueTypeDescriptor(EvaluationContext context, java.lang.Object rootObject)
          Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method for the given context.
 TypeDescriptor getValueTypeDescriptor(java.lang.Object rootObject)
          Returns the most general type that can be passed to the Expression.setValue(EvaluationContext, Object) method using the default context.
 boolean isWritable(EvaluationContext context)
          Determine if an expression can be written to, i.e.
 boolean isWritable(EvaluationContext context, java.lang.Object rootObject)
          Determine if an expression can be written to, i.e.
 boolean isWritable(java.lang.Object rootObject)
          Determine if an expression can be written to, i.e.
 void setValue(EvaluationContext context, java.lang.Object value)
          Set this expression in the provided context to the value provided.
 void setValue(EvaluationContext context, java.lang.Object rootObject, java.lang.Object value)
          Set this expression in the provided context to the value provided.
 void setValue(java.lang.Object rootObject, java.lang.Object value)
          Set this expression in the provided context to the value provided.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expressionString

private final java.lang.String expressionString

expressions

private final Expression[] expressions
The array of expressions that make up the composite expression

Constructor Detail

CompositeStringExpression

public CompositeStringExpression(java.lang.String expressionString,
                                 Expression[] expressions)
Method Detail

getExpressionString

public final java.lang.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

getValue

public java.lang.String 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 java.lang.String getValue(java.lang.Object rootObject)
                          throws EvaluationException
Description copied from interface: Expression
Evaluate this expression against the specified root object

Specified by:
getValue in interface Expression
Parameters:
rootObject - the root object against which properties/etc will be resolved
Returns:
the evaluation result
Throws:
EvaluationException - if there is a problem during evaluation

getValue

public java.lang.String 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 java.lang.String getValue(EvaluationContext context,
                                 java.lang.Object rootObject)
                          throws EvaluationException
Description copied from interface: Expression
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.

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

getValueType

public java.lang.Class getValueType(EvaluationContext context)
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

getValueType

public java.lang.Class getValueType()
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

getValueTypeDescriptor

public TypeDescriptor getValueTypeDescriptor(EvaluationContext context)
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

getValueTypeDescriptor

public TypeDescriptor getValueTypeDescriptor()
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

setValue

public void setValue(EvaluationContext context,
                     java.lang.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

getValue

public <T> T getValue(EvaluationContext context,
                      java.lang.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

getValue

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

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

isWritable

public boolean isWritable(EvaluationContext context)
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

getExpressions

public Expression[] getExpressions()

getValue

public <T> T getValue(java.lang.Object rootObject,
                      java.lang.Class<T> desiredResultType)
           throws EvaluationException
Description copied from interface: Expression
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.

Specified by:
getValue in interface Expression
Parameters:
rootObject - the root object against which properties/etc will be resolved
desiredResultType - 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 <T> T getValue(EvaluationContext context,
                      java.lang.Object rootObject,
                      java.lang.Class<T> desiredResultType)
           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. The supplied root object overrides any default specified on the supplied context.

Specified by:
getValue in interface Expression
Parameters:
context - the context in which to evaluate the expression
rootObject - the root object against which properties/etc will be resolved
desiredResultType - 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 java.lang.Class getValueType(java.lang.Object rootObject)
                             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
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
Throws:
EvaluationException - if there is a problem determining the type

getValueType

public java.lang.Class getValueType(EvaluationContext context,
                                    java.lang.Object rootObject)
                             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. The supplied root object overrides any specified in the context.

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

getValueTypeDescriptor

public TypeDescriptor getValueTypeDescriptor(java.lang.Object rootObject)
                                      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
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
Throws:
EvaluationException - if there is a problem determining the type

getValueTypeDescriptor

public TypeDescriptor getValueTypeDescriptor(EvaluationContext context,
                                             java.lang.Object rootObject)
                                      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. The supplied root object overrides any specified in the context.

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

isWritable

public boolean isWritable(EvaluationContext context,
                          java.lang.Object rootObject)
                   throws EvaluationException
Description copied from interface: Expression
Determine if an expression can be written to, i.e. setValue() can be called. The supplied root object overrides any specified in the context.

Specified by:
isWritable in interface Expression
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
Throws:
EvaluationException - if there is a problem determining if it is writable

setValue

public void setValue(EvaluationContext context,
                     java.lang.Object rootObject,
                     java.lang.Object value)
              throws EvaluationException
Description copied from interface: Expression
Set this expression in the provided context to the value provided. The supplied root object overrides any specified in the context.

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

isWritable

public boolean isWritable(java.lang.Object rootObject)
                   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:
rootObject - the root object against which to evaluate the expression
Returns:
true if the expression is writable
Throws:
EvaluationException - if there is a problem determining if it is writable

setValue

public void setValue(java.lang.Object rootObject,
                     java.lang.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:
rootObject - the root object against which to evaluate the expression
value - the new value
Throws:
EvaluationException - if there is a problem during evaluation