KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > DecoratingComponent


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 8, 2005
10  *
11  * Author Ben Yu
12  * ZBS
13  */

14 package jfun.yan;
15
16 import jfun.yan.factory.Pool;
17
18 /**
19  * Base class for component decorators that do not change the result
20  * returned from the target component it decorates and causes no side-effect
21  * by itself other than those caused by the target component.
22  * <p>
23  * Some decorator classes of Component may want to forward calls to
24  * singleton(), guard(), proxy() to the Component that it delegates
25  * and then re-decorate the result.
26  * </p>
27  * <p>
28  * This class provides the basic facility for this logic.
29  * Implement the decorate() method
30  * and this class will forward and re-decorate for you.
31  * </p>
32  * <p>
33  * Use it with caution because it could cause infinite loop
34  * if used inappropriately
35  * </p>
36  * <p>
37  * Codehaus.org.
38  *
39  * @author Ben Yu
40  *
41  */

42 public abstract class DecoratingComponent extends DelegatingComponent {
43
44   /**
45    * Create a new DeleratingComponent object.
46    * @param cc the Component object to decorate.
47    */

48   public DecoratingComponent(Component cc) {
49     super(cc);
50   }
51   /**
52    * Decorate a Component object.
53    * @param c the Component to decorate.
54    * @return the decorated Component.
55    */

56   protected abstract Component decorate(Component c);
57   public Component singleton(){
58     final Component result = decorate(getDelegateTarget().singleton());
59     return result;//new SingletonComponent(result);
60
}
61   public Component singleton(Pool scope){
62     final Component result = decorate(getDelegateTarget().singleton(scope));
63     return result;//new PooledComponent(result, scope);
64
}
65   public Component guard(){
66     return decorate(getDelegateTarget().guard());
67   }
68   public Component proxy(){
69     return decorate(getDelegateTarget().proxy());
70   }
71   public Component proxy(Class JavaDoc itf){
72     return decorate(getDelegateTarget().proxy(itf));
73   }
74   public Component proxy(Class JavaDoc[] itfs){
75     return decorate(getDelegateTarget().proxy(itfs));
76   }
77   public boolean isSingleton(){
78     return getDelegateTarget().isSingleton();
79   }
80 }
81
Popular Tags