KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > plugins > PluginRegistry


1 /*******************************************************************************
2  * Copyright (c) 2000, 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
12 package org.eclipse.core.internal.plugins;
13
14 import java.util.*;
15 import java.util.ArrayList JavaDoc;
16 import org.eclipse.core.internal.runtime.InternalPlatform;
17 import org.eclipse.core.runtime.*;
18 import org.osgi.framework.*;
19
20 /**
21  * @deprecated Marking as deprecated to remove the warnings
22  */

23 public class PluginRegistry implements IPluginRegistry {
24     private IExtensionRegistry extRegistry;
25     private RegistryListener listener;
26     
27     protected WeakHashMap descriptors = new WeakHashMap(); //key is a bundle object, value is a pluginDescriptor. The synchornization is required
28

29     public PluginRegistry() {
30         extRegistry = InternalPlatform.getDefault().getRegistry();
31         listener = new RegistryListener();
32         InternalPlatform.getDefault().getBundleContext().addBundleListener(listener);
33     }
34
35     public void close() {
36         InternalPlatform.getDefault().getBundleContext().removeBundleListener(listener);
37         listener = null;
38         descriptors = null;
39     }
40     
41     /**
42      * @deprecated Marking as deprecated to remove the warnings
43      */

44     public IConfigurationElement[] getConfigurationElementsFor(String JavaDoc uniqueId) {
45         return extRegistry.getConfigurationElementsFor(uniqueId);
46     }
47
48     /**
49      * @deprecated Marking as deprecated to remove the warnings
50      */

51     public IConfigurationElement[] getConfigurationElementsFor(String JavaDoc pluginId, String JavaDoc pointId) {
52         return extRegistry.getConfigurationElementsFor(pluginId, pointId);
53     }
54
55     /**
56      * @deprecated Marking as deprecated to remove the warnings
57      */

58     public IConfigurationElement[] getConfigurationElementsFor(String JavaDoc pluginId, String JavaDoc pointId, String JavaDoc extensionId) {
59         return extRegistry.getConfigurationElementsFor(pluginId, pointId, extensionId);
60     }
61
62     /**
63      * @deprecated Marking as deprecated to remove the warnings
64      */

65     public IExtension getExtension(String JavaDoc xptUniqueId, String JavaDoc extUniqueId) {
66         return extRegistry.getExtension(xptUniqueId, extUniqueId);
67     }
68
69     /**
70      * @deprecated Marking as deprecated to remove the warnings
71      */

72     public IExtension getExtension(String JavaDoc pluginId, String JavaDoc xptSimpleId, String JavaDoc extId) {
73         return extRegistry.getExtension(pluginId, xptSimpleId, extId);
74     }
75
76     /**
77      * @deprecated Marking as deprecated to remove the warnings
78      */

79     public IExtensionPoint getExtensionPoint(String JavaDoc xptUniqueId) {
80         return extRegistry.getExtensionPoint(xptUniqueId);
81     }
82
83     /**
84      * @deprecated Marking as deprecated to remove the warnings
85      */

86     public IExtensionPoint getExtensionPoint(String JavaDoc plugin, String JavaDoc xpt) {
87         return extRegistry.getExtensionPoint(plugin, xpt);
88     }
89
90     /**
91      * @deprecated Marking as deprecated to remove the warnings
92      */

93     public IExtensionPoint[] getExtensionPoints() {
94         return extRegistry.getExtensionPoints();
95     }
96     
97     /**
98      * @deprecated Marking as deprecated to remove the warnings
99      */

100     public IPluginDescriptor getPluginDescriptor(String JavaDoc plugin) {
101         Bundle correspondingBundle = InternalPlatform.getDefault().getBundle(plugin);
102         if (correspondingBundle == null)
103             return null;
104         return getPluginDescriptor(correspondingBundle);
105     }
106
107     private PluginDescriptor getPluginDescriptor(Bundle bundle) {
108         if (InternalPlatform.getDefault().isFragment(bundle) || descriptors == null) {
109             return null;
110         }
111         synchronized(descriptors) {
112             PluginDescriptor correspondingDescriptor = (PluginDescriptor) descriptors.get(bundle);
113             if (bundle != null) {
114                 // we haven't created a plugin descriptor yet or it was for a different bundle
115
if (correspondingDescriptor == null || correspondingDescriptor.getBundle() != bundle) {
116                     // create a new plugin descriptor and save it for the next time
117
correspondingDescriptor = new PluginDescriptor(bundle);
118                     descriptors.put(bundle, correspondingDescriptor);
119                 }
120                 return correspondingDescriptor;
121             }
122             // if a bundle does not exist, ensure we don't keep a plugin descriptor for it
123
if (correspondingDescriptor != null)
124                 descriptors.remove(bundle);
125         }
126         return null;
127     }
128     
129     /**
130      * @deprecated Marking as deprecated to remove the warnings
131      */

132     public IPluginDescriptor[] getPluginDescriptors(String JavaDoc plugin) {
133         Bundle[] bundles = InternalPlatform.getDefault().getBundles(plugin, null);
134         if (bundles == null)
135             return new IPluginDescriptor[0];
136         IPluginDescriptor[] results = new IPluginDescriptor[bundles.length];
137         int added = 0;
138         for (int i = 0; i < bundles.length; i++) {
139             PluginDescriptor desc = getPluginDescriptor(bundles[i]);
140             if (desc != null)
141                 results[added++] = desc;
142         }
143         if (added == bundles.length)
144             return results;
145         
146         if (added == 0)
147             return new IPluginDescriptor[0];
148         
149         IPluginDescriptor[] toReturn = new IPluginDescriptor[added];
150         System.arraycopy(results, 0, toReturn, 0, added);
151         return toReturn;
152     }
153
154     /**
155      * @deprecated Marking as deprecated to remove the warnings
156      */

157     public IPluginDescriptor getPluginDescriptor(String JavaDoc pluginId, PluginVersionIdentifier version) {
158         Bundle[] bundles = InternalPlatform.getDefault().getBundles(pluginId, version.toString());
159         if (bundles == null)
160             return null;
161         
162         return getPluginDescriptor(bundles[0]);
163     }
164
165     /**
166      * @deprecated Marking as deprecated to remove the warnings
167      */

168     public IPluginDescriptor[] getPluginDescriptors() {
169         Bundle[] bundles = InternalPlatform.getDefault().getBundleContext().getBundles();
170         ArrayList JavaDoc pds = new ArrayList JavaDoc(bundles.length);
171         for (int i = 0; i < bundles.length; i++) {
172             boolean isFragment = InternalPlatform.getDefault().isFragment(bundles[i]);
173             if (!isFragment && bundles[i].getSymbolicName() != null && (bundles[i].getState() == Bundle.RESOLVED || bundles[i].getState() == Bundle.STARTING || bundles[i].getState() == Bundle.ACTIVE))
174                 pds.add(getPluginDescriptor(bundles[i]));
175         }
176         IPluginDescriptor[] result = new IPluginDescriptor[pds.size()];
177         return (IPluginDescriptor[]) pds.toArray(result);
178     }
179
180     void logError(IStatus status) {
181         InternalPlatform.getDefault().log(status);
182         if (InternalPlatform.DEBUG)
183             System.out.println(status.getMessage());
184     }
185
186     public class RegistryListener implements BundleListener {
187         public void bundleChanged(BundleEvent event) {
188             if (descriptors == null)
189                 return;
190             
191             synchronized(descriptors) {
192                 if (event.getType() == BundleEvent.UNINSTALLED || event.getType() == BundleEvent.UNRESOLVED) {
193                     descriptors.remove(event.getBundle());
194                 }
195             }
196         }
197     }
198 }
199
Popular Tags