KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > containers > ComponentTransformers


1 /*****************************************************************************
2  * Copyright (C) Codehaus.org. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 /*
9  * Created on Mar 9, 2005
10  *
11  * Author Ben Yu
12  * ZBS
13  */

14 package jfun.yan.containers;
15
16 import jfun.yan.Component;
17
18 /**
19  * This class provides basic ComponentTransformer objects
20  * as well as the pre-defined ComponentTransformer combinators.
21  * <p>
22  * Codehaus.org.
23  *
24  * @author Ben Yu
25  *
26  */

27 public class ComponentTransformers {
28   /**
29    * Create a new ComponentTransformer by sequencing
30    * two transformers.
31    * i.e., seq(t1,t2).transform(cc) is equivalent to
32    * t2.transform(t1.transform(cc)).
33    * @param t1 the first ComponentTransformer object.
34    * @param t2 the second ComponentTransformer object.
35    * @return the new ComponentTransformer object.
36    */

37   public static ComponentTransformer seq(final ComponentTransformer t1,
38       final ComponentTransformer t2){
39     return new SeqComponentTransformer(t1, t2);
40   }
41   private static final ComponentTransformer _singletor = new ComponentTransformer(){
42     public Component transform(Component cc){
43       return cc.singleton();
44     }
45   };
46   private static final ComponentTransformer _proxier = new ComponentTransformer(){
47     public Component transform(Component cc){
48       return cc.proxy();
49     }
50     public Component transform(Object JavaDoc key, Component cc){
51       if(key instanceof Class JavaDoc){
52         final Class JavaDoc type = (Class JavaDoc)key;
53         if(!type.isInterface()){
54           return cc;
55         }
56       }
57       return transform(cc);
58     }
59   };
60   /**
61    * Return the ComponentTransformer that transforms a Component to singleton.
62    * @return the ComponentTransformer object.
63    */

64   public static ComponentTransformer singletor(){
65     return _singletor;
66   }
67   /**
68    * Return the ComponentTransformer
69    * that transforms a Component to use dynamic proxy.
70    * @return the ComponentTransformer object.
71    */

72   public static ComponentTransformer proxier(){
73     return _proxier;
74   }
75 }
76
Popular Tags