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 FeatureTypeFactory { 24 25 private static FeatureTypeFactory inst; 26 private Map factories; 27 28 private static final String SIMPLE_EXTENSION_ID = "featureTypes"; 30 33 private FeatureTypeFactory() { 34 } 35 36 39 public static FeatureTypeFactory getInstance() { 40 if (inst == null) 41 inst = new FeatureTypeFactory(); 42 return inst; 43 } 44 45 48 public IFeatureFactory getFactory(String type) throws CoreException { 49 Object instance = getFactories().get(type); 51 if (instance == null) { 52 instance = createFactoryFor(type); 53 getFactories().put(type, instance); 54 } 55 return (IFeatureFactory) instance; 56 } 57 58 61 private IFeatureFactory createFactoryFor(String type) throws CoreException { 62 IFeatureFactory result = null; 63 64 String pluginID = 65 UpdateCore.getPlugin().getBundle().getSymbolicName(); 66 IExtensionRegistry registry = Platform.getExtensionRegistry(); 67 IConfigurationElement[] elements = 68 registry.getConfigurationElementsFor(pluginID, SIMPLE_EXTENSION_ID, type); 69 70 if (elements == null || elements.length == 0) { 71 throw Utilities.newCoreException( 72 NLS.bind(Messages.FeatureTypeFactory_UnableToFindFeatureFactory, (new String [] { type })), 73 null); 74 } 75 76 IConfigurationElement element = elements[0]; 77 result = (IFeatureFactory) element.createExecutableExtension("class"); return result; 79 } 80 81 84 private Map getFactories() { 85 if (factories == null) 86 factories = new HashMap (); 87 return factories; 88 } 89 } 90 | Popular Tags |