KickJava   Java API By Example, From Geeks To Geeks.

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


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

6 package com.nightlabs.base.entitylist;
7
8 import java.util.Collection JavaDoc;
9 import java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11
12 import org.eclipse.core.runtime.CoreException;
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 entityList extension point.
20  *
21  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
22  *
23  */

24 public class EntityListRegistry extends AbstractEPProcessor {
25
26     public static final String JavaDoc EXTENSION_POINT_ID = "com.nightlabs.base.entitylist";
27     
28     /**
29      * key: String viewID;<br/>
30      * value: Map entityLists<br/>
31      * key: String entityListID<br/>
32      * value: EntityList<br/>
33      */

34     private Map JavaDoc entityListsByViews = new HashMap JavaDoc();
35     
36     public EntityListRegistry() {
37         super();
38     }
39
40     /**
41      * @see com.nightlabs.rcp.extensionpoint.AbstractEPProcessor#getExtensionPointID()
42      */

43     public String JavaDoc getExtensionPointID() {
44         return EXTENSION_POINT_ID;
45     }
46     
47     /**
48      * Will return a Collection of all EntityLists
49      * registered to this viewID or null.
50      *
51      * @param viewID
52      * @return Collection of EntityLists or null
53      */

54     public Collection JavaDoc getEntityLists(String JavaDoc viewID) {
55         if (!isProcessed())
56             try {
57                 process();
58             } catch (EPProcessorException e) {
59                 throw new RuntimeException JavaDoc(e);
60             }
61         Map JavaDoc listMap = (Map JavaDoc)entityListsByViews.get(viewID);
62         if (listMap == null)
63             return null;
64         return listMap.values();
65     }
66     
67
68     /**
69      * @see com.nightlabs.rcp.extensionpoint.AbstractEPProcessor#processElement(org.eclipse.core.runtime.IConfigurationElement)
70      */

71     public void processElement(IConfigurationElement element)
72             throws EPProcessorException {
73         if (element.getName().equalsIgnoreCase("entityList")) {
74             String JavaDoc id = element.getAttribute("id");
75             if (id == null || "".equals(id))
76                 throw new EPProcessorException("Element entityList must define an attribute id.");
77             String JavaDoc viewID = element.getAttribute("viewID");
78             if (viewID == null || "".equals(viewID))
79                 throw new EPProcessorException("Element entityList must define an attribute viewID.");
80             
81             EntityList entityList = null;
82             try {
83                 entityList = (EntityList)element.createExecutableExtension("class");
84             } catch (CoreException e) {
85                 throw new EPProcessorException(e);
86             }
87             Map JavaDoc listMap = (Map JavaDoc)entityListsByViews.get(viewID);
88             if (listMap == null) {
89                 listMap = new HashMap JavaDoc();
90                 entityListsByViews.put(viewID, listMap);
91             }
92             listMap.put(id, entityList);
93         }
94     }
95     
96     private static EntityListRegistry sharedInstance;
97     
98     public static EntityListRegistry getSharedInstance() {
99         if (sharedInstance == null)
100             sharedInstance = new EntityListRegistry();
101         return sharedInstance;
102     }
103
104 }
105
Popular Tags