1 6 package com.nightlabs.base.entitylist; 7 8 import java.util.Collection ; 9 import java.util.HashMap ; 10 import java.util.Map ; 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 24 public class EntityListRegistry extends AbstractEPProcessor { 25 26 public static final String EXTENSION_POINT_ID = "com.nightlabs.base.entitylist"; 27 28 34 private Map entityListsByViews = new HashMap (); 35 36 public EntityListRegistry() { 37 super(); 38 } 39 40 43 public String getExtensionPointID() { 44 return EXTENSION_POINT_ID; 45 } 46 47 54 public Collection getEntityLists(String viewID) { 55 if (!isProcessed()) 56 try { 57 process(); 58 } catch (EPProcessorException e) { 59 throw new RuntimeException (e); 60 } 61 Map listMap = (Map )entityListsByViews.get(viewID); 62 if (listMap == null) 63 return null; 64 return listMap.values(); 65 } 66 67 68 71 public void processElement(IConfigurationElement element) 72 throws EPProcessorException { 73 if (element.getName().equalsIgnoreCase("entityList")) { 74 String id = element.getAttribute("id"); 75 if (id == null || "".equals(id)) 76 throw new EPProcessorException("Element entityList must define an attribute id."); 77 String 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 listMap = (Map )entityListsByViews.get(viewID); 88 if (listMap == null) { 89 listMap = new HashMap (); 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 |