KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > DelegatingComponent


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

14 package jfun.yan;
15
16 /**
17  * Base class for delegating Component object.
18  * It forwards all method call to the delegated Component object,
19  * which makes it handy for customizing a Component object by subclassing.
20  * <p>
21  * Codehaus.org.
22  *
23  * @author Ben Yu
24  *
25  */

26 public abstract class DelegatingComponent extends Component {
27   private final Component cc;
28   
29   public boolean isConcrete(){
30     return cc.isConcrete();
31   }
32   public boolean isSingleton() {
33     return false;
34   }
35   /**
36    * Create a new DelegatingComponent object.
37    * @param cc the Component object to delegate.
38    */

39   public DelegatingComponent(final Component cc) {
40     this.cc = cc;
41   }
42   public Object JavaDoc getState(){
43     return cc.getState();
44   }
45   public Object JavaDoc create(Dependency dep){
46     return cc.create(dep);
47   }
48   public boolean equals(Object JavaDoc other) {
49     if(other instanceof DelegatingComponent){
50       final DelegatingComponent cc2 = (DelegatingComponent)other;
51       final Object JavaDoc s1 = getState();
52       final Object JavaDoc s2 = cc2.getState();
53       return cc.equals(cc2.cc)
54       &&
55       s1==null?s2==null:(s2!=null && s1.equals(s2));
56
57     }
58     else return cc.equals(other);
59   }
60   public Class JavaDoc getType() {
61     return cc.getType();
62   }
63   public int hashCode() {
64     return cc.hashCode();
65   }
66   public String JavaDoc toString() {
67     return cc.toString();
68   }
69   public Class JavaDoc verify(Dependency dep){
70     return cc.verify(dep);
71   }
72   /**
73    * Gets the Component object being delegated.
74    * @return the Component object.
75    */

76   protected final Component getDelegateTarget(){
77     return cc;
78   }
79 }
80
Popular Tags