Class CompositeStringExpression
- java.lang.Object
- org.springframework.expression.common.CompositeStringExpression
- All Implemented Interfaces:
Expression
public class CompositeStringExpression extends 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 callgetName()
when invoked.- Since:
- 3.0
- Author:
- Andy Clement, Juergen Hoeller
Constructor Summary
Constructors Constructor Description CompositeStringExpression(String expressionString, Expression[] expressions)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Expression[]
getExpressions()
String
getExpressionString()
Return the original string used to create this expression (unmodified).String
getValue()
Evaluate this expression in the default standard context.<T> T
getValue(Class<T> expectedResultType)
Evaluate the expression in the default context.String
getValue(Object rootObject)
Evaluate this expression against the specified root object.<T> T
getValue(Object rootObject, Class<T> desiredResultType)
Evaluate the expression in the default context against the specified root object.String
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.String
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> desiredResultType)
Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc.Class<?>
getValueType()
Return the most general type that can be passed to aExpression.setValue(java.lang.Object, java.lang.Object)
method using the default context.Class<?>
getValueType(Object rootObject)
Return the most general type that can be passed to theExpression.setValue(Object, Object)
method using the default context.Class<?>
getValueType(EvaluationContext context)
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object)
method for the given context.Class<?>
getValueType(EvaluationContext context, Object rootObject)
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object, Object)
method for the given context.TypeDescriptor
getValueTypeDescriptor()
Return the most general type that can be passed to aExpression.setValue(java.lang.Object, java.lang.Object)
method using the default context.TypeDescriptor
getValueTypeDescriptor(Object rootObject)
Return the most general type that can be passed to theExpression.setValue(Object, Object)
method using the default context.TypeDescriptor
getValueTypeDescriptor(EvaluationContext context)
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object)
method for the given context.TypeDescriptor
getValueTypeDescriptor(EvaluationContext context, Object rootObject)
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object, Object)
method for the given 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
setValue(Object rootObject, Object value)
Set this expression in the provided context to the value provided.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.
Constructor Detail
CompositeStringExpression
public CompositeStringExpression(String expressionString, Expression[] expressions)
Method Detail
getExpressionString
public final String getExpressionString()
Description copied from interface:Expression
Return the original string used to create this expression (unmodified).- Specified by:
getExpressionString
in interfaceExpression
- Returns:
- the original expression string
getExpressions
public final Expression[] getExpressions()
getValue
public String getValue() throws EvaluationException
Description copied from interface:Expression
Evaluate this expression in the default standard context.- Specified by:
getValue
in interfaceExpression
- 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 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 interfaceExpression
- 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 String getValue(Object rootObject) throws EvaluationException
Description copied from interface:Expression
Evaluate this expression against the specified root object.- Specified by:
getValue
in interfaceExpression
- Parameters:
rootObject
- the root object against which to evaluate the expression- Returns:
- the evaluation result
- Throws:
EvaluationException
- if there is a problem during evaluation
getValue
public <T> T getValue(Object rootObject, 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 interfaceExpression
- Parameters:
rootObject
- the root object against which to evaluate the expressiondesiredResultType
- 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 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 interfaceExpression
- 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 interfaceExpression
- Parameters:
context
- the context in which to evaluate the expressionexpectedResultType
- 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 String getValue(EvaluationContext context, 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 interfaceExpression
- Parameters:
context
- the context in which to evaluate the expressionrootObject
- the root object against 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, Object rootObject, 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 interfaceExpression
- Parameters:
context
- the context in which to evaluate the expressionrootObject
- the root object against which to evaluate the expressiondesiredResultType
- 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()
Description copied from interface:Expression
Return the most general type that can be passed to aExpression.setValue(java.lang.Object, java.lang.Object)
method using the default context.- Specified by:
getValueType
in interfaceExpression
- Returns:
- the most general type of value that can be set on this context
getValueType
public Class<?> getValueType(EvaluationContext context)
Description copied from interface:Expression
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object)
method for the given context.- Specified by:
getValueType
in interfaceExpression
- 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 Class<?> getValueType(Object rootObject) throws EvaluationException
Description copied from interface:Expression
Return the most general type that can be passed to theExpression.setValue(Object, Object)
method using the default context.- Specified by:
getValueType
in interfaceExpression
- 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 Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException
Description copied from interface:Expression
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object, Object)
method for the given context. The supplied root object overrides any specified in the context.- Specified by:
getValueType
in interfaceExpression
- Parameters:
context
- the context in which to evaluate the expressionrootObject
- 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()
Description copied from interface:Expression
Return the most general type that can be passed to aExpression.setValue(java.lang.Object, java.lang.Object)
method using the default context.- Specified by:
getValueTypeDescriptor
in interfaceExpression
- Returns:
- a type descriptor for values that can be set on this context
getValueTypeDescriptor
public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException
Description copied from interface:Expression
Return the most general type that can be passed to theExpression.setValue(Object, Object)
method using the default context.- Specified by:
getValueTypeDescriptor
in interfaceExpression
- Parameters:
rootObject
- the root object against which to evaluate the expression- Returns:
- a type descriptor for values that can be set on this context
- Throws:
EvaluationException
- if there is a problem determining the type
getValueTypeDescriptor
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context)
Description copied from interface:Expression
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object)
method for the given context.- Specified by:
getValueTypeDescriptor
in interfaceExpression
- Parameters:
context
- the context in which to evaluate the expression- Returns:
- a type descriptor for values that can be set on this context
getValueTypeDescriptor
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException
Description copied from interface:Expression
Return the most general type that can be passed to theExpression.setValue(EvaluationContext, Object, Object)
method for the given context. The supplied root object overrides any specified in the context.- Specified by:
getValueTypeDescriptor
in interfaceExpression
- Parameters:
context
- the context in which to evaluate the expressionrootObject
- the root object against which to evaluate the expression- Returns:
- a type descriptor for values that can be set on this context
- Throws:
EvaluationException
- if there is a problem determining the type
isWritable
public boolean isWritable(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 interfaceExpression
- Parameters:
rootObject
- the root object against which to evaluate the expression- Returns:
true
if the expression is writable;false
otherwise- Throws:
EvaluationException
- if there is a problem determining if it is writable
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 interfaceExpression
- Parameters:
context
- the context in which the expression should be checked- Returns:
true
if the expression is writable;false
otherwise
isWritable
public boolean isWritable(EvaluationContext context, 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 interfaceExpression
- Parameters:
context
- the context in which the expression should be checkedrootObject
- the root object against which to evaluate the expression- Returns:
true
if the expression is writable;false
otherwise- Throws:
EvaluationException
- if there is a problem determining if it is writable
setValue
public void setValue(Object rootObject, Object value) throws EvaluationException
Description copied from interface:Expression
Set this expression in the provided context to the value provided.- Specified by:
setValue
in interfaceExpression
- Parameters:
rootObject
- the root object against which to evaluate the expressionvalue
- the new value- Throws:
EvaluationException
- if there is a problem during evaluation
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 interfaceExpression
- Parameters:
context
- the context in which to set the value of the expressionvalue
- the new value- Throws:
EvaluationException
- if there is a problem during evaluation
setValue
public void setValue(EvaluationContext context, Object rootObject, 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 interfaceExpression
- Parameters:
context
- the context in which to set the value of the expressionrootObject
- the root object against which to evaluate the expressionvalue
- the new value- Throws:
EvaluationException
- if there is a problem during evaluation