KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > binding > expression > support > CompositeStringExpression


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc evaluate(Object JavaDoc target, EvaluationContext evaluationContext) throws EvaluationException {
45         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(128);
46         for (int i = 0; i < expressions.length; i++) {
47             buffer.append(expressions[i].evaluate(target, evaluationContext));
48         }
49         return buffer.toString();
50     }
51
52     public String JavaDoc toString() {
53         return new ToStringCreator(this).append("expressions", expressions).toString();
54     }
55 }
Popular Tags