1 11 package org.eclipse.core.internal.resources.mapping; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 import org.eclipse.core.internal.utils.Policy; 16 import org.eclipse.core.resources.ResourcesPlugin; 17 import org.eclipse.core.resources.mapping.IModelProviderDescriptor; 18 import org.eclipse.core.resources.mapping.ModelProvider; 19 import org.eclipse.core.runtime.*; 20 21 public class ModelProviderManager { 22 23 private static Map descriptors; 24 private static ModelProviderManager instance; 25 26 public synchronized static ModelProviderManager getDefault() { 27 if (instance == null) { 28 instance = new ModelProviderManager(); 29 } 30 return instance; 31 } 32 33 private void detectCycles() { 34 36 } 37 38 public IModelProviderDescriptor getDescriptor(String id) { 39 lazyInitialize(); 40 return (IModelProviderDescriptor) descriptors.get(id); 41 } 42 43 public IModelProviderDescriptor[] getDescriptors() { 44 lazyInitialize(); 45 return (IModelProviderDescriptor[]) descriptors.values().toArray(new IModelProviderDescriptor[descriptors.size()]); 46 } 47 48 public ModelProvider getModelProvider(String modelProviderId) throws CoreException { 49 IModelProviderDescriptor desc = getDescriptor(modelProviderId); 50 if (desc == null) 51 return null; 52 return desc.getModelProvider(); 53 } 54 55 protected void lazyInitialize() { 56 if (descriptors != null) 57 return; 58 IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(ResourcesPlugin.PI_RESOURCES, ResourcesPlugin.PT_MODEL_PROVIDERS); 59 IExtension[] extensions = point.getExtensions(); 60 descriptors = new HashMap (extensions.length * 2 + 1); 61 for (int i = 0, imax = extensions.length; i < imax; i++) { 62 IModelProviderDescriptor desc = null; 63 try { 64 desc = new ModelProviderDescriptor(extensions[i]); 65 } catch (CoreException e) { 66 Policy.log(e); 67 } 68 if (desc != null) 69 descriptors.put(desc.getId(), desc); 70 } 71 detectCycles(); 74 } 75 76 } 77 | Popular Tags |