implement new Expression methods
This commit is contained in:
parent
ef8f882036
commit
98c82fe995
|
|
@ -11,16 +11,17 @@ import org.springframework.expression.Expression;
|
|||
* </pre></code> 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.
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class CompositeStringExpression implements Expression {
|
||||
|
||||
private String expressionString;
|
||||
private final String expressionString;
|
||||
|
||||
/**
|
||||
* The array of expressions that make up the composite expression
|
||||
*/
|
||||
private Expression[] expressions;
|
||||
private final Expression[] expressions;
|
||||
|
||||
public CompositeStringExpression(String expressionString, Expression[] expressions) {
|
||||
this.expressionString = expressionString;
|
||||
|
|
@ -34,7 +35,8 @@ public class CompositeStringExpression implements Expression {
|
|||
public String getValue() throws EvaluationException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
// TODO (asc) is stringify ok for the non literal components? or should the converters be used? see another case below
|
||||
// TODO is stringify ok for the non literal components? or should the converters be used? see another
|
||||
// case below
|
||||
sb.append(expressions[i].getValue());
|
||||
}
|
||||
return sb.toString();
|
||||
|
|
@ -52,6 +54,10 @@ public class CompositeStringExpression implements Expression {
|
|||
return String.class;
|
||||
}
|
||||
|
||||
public Class getValueType() throws EvaluationException {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
public void setValue(EvaluationContext context, Object value) throws EvaluationException {
|
||||
throw new EvaluationException(expressionString, "Cannot call setValue() on a composite expression");
|
||||
}
|
||||
|
|
@ -65,4 +71,8 @@ public class CompositeStringExpression implements Expression {
|
|||
Object value = getValue();
|
||||
return ExpressionUtils.convert(null, value, expectedResultType);
|
||||
}
|
||||
|
||||
public boolean isWritable(EvaluationContext context) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class LiteralExpression implements Expression {
|
|||
/**
|
||||
* Fixed literal value of this expression
|
||||
*/
|
||||
private String literalValue;
|
||||
private final String literalValue;
|
||||
|
||||
public LiteralExpression(String literalValue) {
|
||||
this.literalValue = literalValue;
|
||||
|
|
@ -40,7 +40,7 @@ public class LiteralExpression implements Expression {
|
|||
}
|
||||
|
||||
public void setValue(EvaluationContext context, Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression");
|
||||
throw new EvaluationException(literalValue, "Cannot call setValue() on a LiteralExpression");
|
||||
}
|
||||
|
||||
public Object getValue(EvaluationContext context, Class<?> expectedResultType) throws EvaluationException {
|
||||
|
|
@ -53,4 +53,12 @@ public class LiteralExpression implements Expression {
|
|||
return ExpressionUtils.convert(null, value, expectedResultType);
|
||||
}
|
||||
|
||||
public boolean isWritable(EvaluationContext context) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Class getValueType() throws EvaluationException {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue