KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > base > entitylist > EntityManagerViewRegistry


1 /*
2  * Created on Jun 1, 2005
3  * by alex
4  *
5  */

6 package com.nightlabs.base.entitylist;
7
8 import java.util.HashMap JavaDoc;
9 import java.util.HashSet JavaDoc;
10 import java.util.Map JavaDoc;
11 import java.util.Set JavaDoc;
12
13 import org.eclipse.core.runtime.IConfigurationElement;
14
15 import com.nightlabs.rcp.extensionpoint.AbstractEPProcessor;
16 import com.nightlabs.rcp.extensionpoint.EPProcessorException;
17
18 /**
19  * Holds extensions to the entityManagerView extension point.
20  *
21  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
22  *
23  */

24 public class EntityManagerViewRegistry extends AbstractEPProcessor {
25     
26     public static final String JavaDoc EXTENSION_POINT_ID = "com.nightlabs.base.entitymanagerview";
27
28     /**
29      * key: String listViewID<br/>
30      * value: Map<br/>
31      * key: String managerViewID<br/>
32      * value: Set of String entityID<br/>
33      */

34     private Map JavaDoc managedEntitiesByListViews = new HashMap JavaDoc();
35     
36     /**
37      * key: String managerViewID<br/>
38      * value: Set of String listViewID<br/>
39      */

40     private Map JavaDoc listViewsByManager = new HashMap JavaDoc();
41
42     /**
43      * key: String listViewID<br/>
44      * value: Map<br/>
45      * key: String entityID<br/>
46      * value: Set of String managerViewID<br/>
47      */

48     private Map JavaDoc managerViewsByWrappedEntities = new HashMap JavaDoc();
49
50     /**
51      * key: String enityID<br/>
52      * value: Set of String managerViewID<br/>
53      */

54     private Map JavaDoc managerViewsByEntities = new HashMap JavaDoc();
55     
56     /**
57      * key: String managerViewID<br/>
58      * value: Set of String entityID<br/>
59      */

60     private Map JavaDoc managedEnitiesByManagerView = new HashMap JavaDoc();
61     
62     public EntityManagerViewRegistry() {
63         super();
64     }
65
66     /**
67      * @see com.nightlabs.rcp.extensionpoint.AbstractEPProcessor#getExtensionPointID()
68      */

69     public String JavaDoc getExtensionPointID() {
70         return EXTENSION_POINT_ID;
71     }
72     
73     /**
74      * All viewIDs of Views managing the given entityID in a Set or null
75      * if no managers are registered to this entityID.
76      *
77      * @param entityID The entityID managers are searched for
78      * @return All viewIDs of Views managing the given entityID in a Set or null
79      */

80     public Set JavaDoc getManagerViewsForEntityID(String JavaDoc entityID) {
81         if (!isProcessed())
82             try {
83                 process();
84             } catch (EPProcessorException e) {
85                 throw new RuntimeException JavaDoc(e);
86             }
87         return (Set JavaDoc)managerViewsByEntities.get(entityID);
88     }
89
90     /**
91      * All viewIDs of Views managing the given entityID whithin the
92      * given listViewID in a Set or null
93      * if no managers are registered to this entityID.
94      *
95      * @param entityID The entityID managers are searched for
96      * @return All viewIDs of Views managing the given entityID in a Set or null
97      */

98     public Set JavaDoc getManagerViewsForEntityID(String JavaDoc listViewID, String JavaDoc entityID) {
99         if (!isProcessed())
100             try {
101                 process();
102             } catch (EPProcessorException e) {
103                 throw new RuntimeException JavaDoc(e);
104             }
105         Map JavaDoc managerViewsMap = (Map JavaDoc)managerViewsByWrappedEntities.get(listViewID);
106         if (managerViewsMap == null)
107             return null;
108         
109         return (Set JavaDoc)managerViewsMap.get(entityID);
110     }
111
112     /**
113      * Retrurns all entityIDs managed by the View with the given managerViewID in a Set or null
114      * if no managed entities are registered to this viewID.
115      * This will include all registrations no matter to what listViewID they point.
116      *
117      * @param managerViewID The viewID managed entities are searched for
118      * @return All entityIDs managed by the View with the given viewID in a Set or null
119      */

120     public Set JavaDoc getManagedEntitiesForManagerViewID(String JavaDoc managerViewID) {
121         if (!isProcessed())
122             try {
123                 process();
124             } catch (EPProcessorException e) {
125                 throw new RuntimeException JavaDoc(e);
126             }
127         return (Set JavaDoc)managedEnitiesByManagerView.get(managerViewID);
128     }
129
130     /**
131      * Returns all listViewID the given View with the managerViewID
132      * was registered to.
133      *
134      * @param managerViewID
135      * @return
136      */

137     public Set JavaDoc getListViewsForManagerView(String JavaDoc managerViewID) {
138         if (!isProcessed())
139             try {
140                 process();
141             } catch (EPProcessorException e) {
142                 throw new RuntimeException JavaDoc(e);
143             }
144         return (Set JavaDoc)listViewsByManager.get(managerViewID);
145     }
146     /**
147      * @see com.nightlabs.rcp.extensionpoint.AbstractEPProcessor#processElement(org.eclipse.core.runtime.IConfigurationElement)
148      */

149     public void processElement(IConfigurationElement element)
150             throws EPProcessorException {
151         if (element.getName().equalsIgnoreCase("entityManagerView")) {
152             
153             String JavaDoc entityID = element.getAttribute("entityID");
154             if (entityID == null || "".equals(entityID))
155                 throw new EPProcessorException("Element entityManagerView has to define an attribute entityID");
156                 
157             String JavaDoc listViewID = element.getAttribute("listViewID");
158             if (listViewID == null || "".equals(listViewID))
159                 throw new EPProcessorException("Element entityManagerView has to define an attribute listViewID");
160
161             String JavaDoc managerViewID = element.getAttribute("managerViewID");
162             if (managerViewID == null || "".equals(managerViewID))
163                 throw new EPProcessorException("Element entityManagerView has to define an attribute managerViewID");
164
165             
166             /*
167              * key: String listViewID<br/>
168              * value: Map<br/>
169              * key: String managerViewID<br/>
170              * value: Set of String entityID<br/>
171              */

172             {
173                 Map JavaDoc managerViewEntities = (Map JavaDoc)managedEntitiesByListViews.get(listViewID);
174                 if (managerViewEntities == null) {
175                     managerViewEntities = new HashMap JavaDoc();
176                     managedEntitiesByListViews.put(listViewID, managerViewEntities);
177                 }
178                 Set JavaDoc entities = (Set JavaDoc)managerViewEntities.get(managerViewID);
179                 if (entities == null) {
180                     entities = new HashSet JavaDoc();
181                     managerViewEntities.put(managerViewID, entities);
182                 }
183                 entities.add(entityID);
184             }
185             
186             /*
187              * key: String managerViewID<br/>
188              * value: Set of String listViewID<br/>
189              */

190             {
191                 Set JavaDoc listViews = (Set JavaDoc)listViewsByManager.get(managerViewID);
192                 if (listViews == null) {
193                     listViews = new HashSet JavaDoc();
194                     listViewsByManager.put(managerViewID, listViews);
195                 }
196                 listViews.add(listViewID);
197             }
198
199             /*
200              * key: String listViewID<br/>
201              * value: Map<br/>
202              * key: String entityID<br/>
203              * value: Set of String managerViewID<br/>
204              */

205             {
206                 Map JavaDoc managerMap = (Map JavaDoc)managerViewsByWrappedEntities.get(listViewID);
207                 if (managerMap == null) {
208                     managerMap = new HashMap JavaDoc();
209                     managerViewsByWrappedEntities.put(listViewID, managerMap);
210                 }
211                 Set JavaDoc managers = (Set JavaDoc)managerMap.get(entityID);
212                 if (managers == null) {
213                     managers = new HashSet JavaDoc();
214                     managerMap.put(entityID, managers);
215                 }
216                 managers.add(managerViewID);
217             }
218
219             /*
220              * key: String enityID<br/>
221              * value: Set of String managerViewID<br/>
222              */

223             {
224                 Set JavaDoc managers = (Set JavaDoc)managerViewsByEntities.get(entityID);
225                 if (managers == null) {
226                     managers = new HashSet JavaDoc();
227                     managerViewsByEntities.put(entityID, managers);
228                 }
229                 managers.add(managerViewID);
230             }
231             
232             /*
233              * key: String managerViewID<br/>
234              * value: Set of String entityID<br/>
235              */

236             {
237                 Set JavaDoc entities = (Set JavaDoc)managedEnitiesByManagerView.get(managerViewID);
238                 if (entities == null) {
239                     entities = new HashSet JavaDoc();
240                     managedEnitiesByManagerView.put(managerViewID, entities);
241                 }
242                 entities.add(entityID);
243             }
244             
245         }
246     }
247     
248     
249     private static EntityManagerViewRegistry sharedInstance;
250     
251     public static EntityManagerViewRegistry getSharedInstance() {
252         if (sharedInstance == null)
253             sharedInstance = new EntityManagerViewRegistry();
254         return sharedInstance;
255     }
256
257 }
258
Popular Tags