KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > DelegatingComponentMap


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

14 package jfun.yan;
15
16 import java.util.Collection JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Set JavaDoc;
19
20 /**
21  * The base class for delegating to a ComponentMap object.
22  * It forwards all method call to the delegated ComponentMap object,
23  * which makes it handy for customizing a ComponentMap object by subclassing.
24  * <p>
25  * Codehaus.org.
26  *
27  * @author Ben Yu
28  *
29  */

30 public class DelegatingComponentMap implements ComponentMap {
31   private final ComponentMap cmap;
32
33
34   public boolean containsKey(Object JavaDoc key) {
35     return cmap.containsKey(key);
36   }
37   public boolean containsType(Class JavaDoc type) {
38     return cmap.containsType(type);
39   }
40   /**
41    * Create new DelegatingComponentMap object.
42    * @param cmap the ComponentMap object to delegate to.
43    */

44   public DelegatingComponentMap(final ComponentMap cmap) {
45     this.cmap = cmap;
46   }
47   public Dependency getDependencyOfType(Class JavaDoc type, ComponentMap cmap) {
48     return cmap.getDependencyOfType(type, cmap);
49   }
50   public Dependency getDependency(Object JavaDoc key, ComponentMap cmap) {
51     return cmap.getDependency(key, cmap);
52   }
53   public Component getComponent(Object JavaDoc key) {
54     return cmap.getComponent(key);
55   }
56   public boolean equals(Object JavaDoc other) {
57     if(other instanceof DelegatingComponentMap){
58       DelegatingComponentMap map2 = (DelegatingComponentMap)other;
59       return cmap.equals(map2.cmap);
60     }
61     else return cmap.equals(other);
62   }
63   public int hashCode() {
64     return cmap.hashCode();
65   }
66   public String JavaDoc toString() {
67     return cmap.toString();
68   }
69   /**
70    * Gets the ComponentMap object being delegated.
71    * @return the ComponentMap object.
72    */

73   protected final ComponentMap getDelegateTarget(){
74     return cmap;
75   }
76   
77   public Component getComponentOfType(Class JavaDoc type) {
78     return cmap.getComponentOfType(type);
79   }
80   public List JavaDoc getComponentsOfType(Class JavaDoc type) {
81     return cmap.getComponentsOfType(type);
82   }
83   public Collection JavaDoc getComponents() {
84     return cmap.getComponents();
85   }
86   public Set JavaDoc keys() {
87     return cmap.keys();
88   }
89 }
90
Popular Tags