This commit is contained in:
Keith Donald 2009-11-12 21:18:17 +00:00
parent 61a8fa0ebd
commit 3361de3875
1 changed files with 29 additions and 19 deletions

View File

@ -20,7 +20,6 @@ import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
import org.springframework.expression.Expression; import org.springframework.expression.Expression;
import org.springframework.util.ObjectUtils;
/** /**
* Represents a template expression broken into pieces. Each piece will be an Expression but pure text parts to the * Represents a template expression broken into pieces. Each piece will be an Expression but pure text parts to the
@ -58,15 +57,10 @@ public class CompositeStringExpression implements Expression {
public String getValue() throws EvaluationException { public String getValue() throws EvaluationException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Expression expression : this.expressions) { for (Expression expression : this.expressions) {
sb.append(ObjectUtils.getDisplayString(expression.getValue())); String value = expression.getValue(String.class);
} if (value != null) {
return sb.toString(); sb.append(value);
} }
public String getValue(EvaluationContext context) throws EvaluationException {
StringBuilder sb = new StringBuilder();
for (Expression expression : this.expressions) {
sb.append(ObjectUtils.getDisplayString(expression.getValue(context)));
} }
return sb.toString(); return sb.toString();
} }
@ -74,11 +68,35 @@ public class CompositeStringExpression implements Expression {
public String getValue(Object rootObject) throws EvaluationException { public String getValue(Object rootObject) throws EvaluationException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Expression expression : this.expressions) { for (Expression expression : this.expressions) {
sb.append(ObjectUtils.getDisplayString(expression.getValue(rootObject))); String value = expression.getValue(rootObject, String.class);
if (value != null) {
sb.append(value);
}
} }
return sb.toString(); return sb.toString();
} }
public String getValue(EvaluationContext context) throws EvaluationException {
StringBuilder sb = new StringBuilder();
for (Expression expression : this.expressions) {
String value = expression.getValue(context, String.class);
if (value != null) {
sb.append(value);
}
}
return sb.toString();
}
public String getValue(EvaluationContext context, Object rootObject) throws EvaluationException {
StringBuilder sb = new StringBuilder();
for (Expression expression : this.expressions) {
String value = expression.getValue(context, rootObject, String.class);
if (value != null) {
sb.append(value);
}
}
return sb.toString();
}
public Class getValueType(EvaluationContext context) { public Class getValueType(EvaluationContext context) {
return String.class; return String.class;
@ -124,14 +142,6 @@ public class CompositeStringExpression implements Expression {
return ExpressionUtils.convert(null, value, desiredResultType); return ExpressionUtils.convert(null, value, desiredResultType);
} }
public String getValue(EvaluationContext context, Object rootObject) throws EvaluationException {
StringBuilder sb = new StringBuilder();
for (Expression expression : this.expressions) {
sb.append(ObjectUtils.getDisplayString(expression.getValue(context,rootObject)));
}
return sb.toString();
}
public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> desiredResultType) public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> desiredResultType)
throws EvaluationException { throws EvaluationException {
Object value = getValue(context,rootObject); Object value = getValue(context,rootObject);