01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.springframework.binding.expression.support;
17:
18: import org.springframework.binding.expression.EvaluationContext;
19: import org.springframework.binding.expression.EvaluationException;
20: import org.springframework.binding.expression.Expression;
21: import org.springframework.core.style.ToStringCreator;
22:
23: /**
24: * Evaluates an array of expressions to build a concatenated string.
25: *
26: * @author Keith Donald
27: */
28: public class CompositeStringExpression implements Expression {
29:
30: /**
31: * The expression array.
32: */
33: private Expression[] expressions;
34:
35: /**
36: * Creates a new composite string expression.
37: * @param expressions the ordered set of expressions that when evaluated
38: * will have their results stringed together to build the composite string
39: */
40: public CompositeStringExpression(Expression[] expressions) {
41: this .expressions = expressions;
42: }
43:
44: public Object evaluate(Object target,
45: EvaluationContext evaluationContext)
46: throws EvaluationException {
47: StringBuffer buffer = new StringBuffer(128);
48: for (int i = 0; i < expressions.length; i++) {
49: buffer.append(expressions[i].evaluate(target,
50: evaluationContext));
51: }
52: return buffer.toString();
53: }
54:
55: public String toString() {
56: return new ToStringCreator(this ).append("expressions",
57: expressions).toString();
58: }
59: }
|