KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > CompoundTransform


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
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
17 import java.util.LinkedList JavaDoc;
18 import java.util.Iterator JavaDoc;
19
20 import org.apache.commons.digester.Digester;
21 import org.apache.commons.digester.plugins.PluginCreateRule;
22
23 /**
24  * An implementation of the Transform interface which is configured with
25  * a sequence of "subtransforms", and applies them one by one to the input
26  * data.
27  * <p>
28  * This demonstrates that a plugged-in class can itself define plugin-points
29  * for user-defined classes if it wishes.
30  */

31
32 public class CompoundTransform implements Transform {
33     private LinkedList JavaDoc transforms = new LinkedList JavaDoc();
34     
35     public void addTransform(Transform transform) {
36         transforms.add(transform);
37     }
38     
39     public String JavaDoc transform(String JavaDoc s) {
40         for(Iterator JavaDoc i = transforms.iterator(); i.hasNext(); ) {
41             Transform t = (Transform) i.next();
42             s = t.transform(s);
43         }
44         return s;
45     }
46     
47     public static void addRules(Digester d, String JavaDoc patternPrefix) {
48         PluginCreateRule pcr = new PluginCreateRule(Transform.class);
49         d.addRule(patternPrefix+"/subtransform", pcr);
50         d.addSetNext(patternPrefix+"/subtransform", "addTransform");
51     }
52 }
53
Popular Tags