KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > mapping > ModelProviderManager


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.resources.mapping;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
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 JavaDoc 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         // TODO Auto-generated method stub
35

36     }
37
38     public IModelProviderDescriptor getDescriptor(String JavaDoc 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 JavaDoc 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 JavaDoc(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         //do cycle detection now so it only has to be done once
72
//cycle detection on a graph subset is a pain
73
detectCycles();
74     }
75
76 }
77
Popular Tags