1 11 package org.eclipse.update.internal.core; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.update.core.*; 19 20 23 public final class SiteTypeFactory { 24 25 26 29 public static final String SIMPLE_EXTENSION_ID = "siteTypes"; 31 32 private static SiteTypeFactory inst; 33 34 private Map factories; 35 36 39 private SiteTypeFactory() { 40 } 41 42 public static SiteTypeFactory getInstance() { 43 if (inst == null) 44 inst = new SiteTypeFactory(); 45 return inst; 46 } 47 48 49 52 public ISiteFactory getFactory(String type) throws CoreException { 53 Object instance = getFactories().get(type); 55 if (instance==null) { 56 instance = createFactoryFor(type); 57 getFactories().put(type,instance); 58 } 59 return (ISiteFactory) instance; 60 } 61 62 65 private ISiteFactory createFactoryFor(String type) throws CoreException { 66 ISiteFactory result = null; 67 68 String pluginID = UpdateCore.getPlugin().getBundle().getSymbolicName(); 69 IExtensionRegistry registry = Platform.getExtensionRegistry(); 70 IConfigurationElement[] elements = registry.getConfigurationElementsFor(pluginID,SIMPLE_EXTENSION_ID,type); 71 if (elements==null || elements.length==0){ 72 throw Utilities.newCoreException(NLS.bind(Messages.SiteTypeFactory_UnableToFindSiteFactory, (new String [] { type })),null); 73 } else { 74 IConfigurationElement element = elements[0]; 75 result = (ISiteFactory)element.createExecutableExtension("class"); } 77 return result; 78 } 79 80 84 private Map getFactories() { 85 if (factories==null) factories = new HashMap (); 86 return factories; 87 } 88 89 90 } 91 | Popular Tags |