Browse Source

implement new Expression methods

conversation
Andy Clement 16 years ago
parent
commit
98c82fe995
  1. 16
      org.springframework.expression/src/main/java/org/springframework/expression/common/CompositeStringExpression.java
  2. 12
      org.springframework.expression/src/main/java/org/springframework/expression/common/LiteralExpression.java

16
org.springframework.expression/src/main/java/org/springframework/expression/common/CompositeStringExpression.java

@ -11,16 +11,17 @@ import org.springframework.expression.Expression; @@ -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 { @@ -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 { @@ -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 { @@ -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;
}
}

12
org.springframework.expression/src/main/java/org/springframework/expression/common/LiteralExpression.java

@ -17,7 +17,7 @@ public class LiteralExpression implements Expression { @@ -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 { @@ -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 { @@ -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…
Cancel
Save