KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > registry > RegistryCompatibilityHelper


1 /*******************************************************************************
2  * Copyright (c) 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.registry;
12
13 import java.lang.reflect.Method JavaDoc;
14 import org.eclipse.core.runtime.IPluginDescriptor;
15 import org.osgi.framework.Bundle;
16
17 /**
18  * This class isolates calls to the backward compatibility layer.
19  * It uses reflection so it can be loaded with success even in the absence of
20  * the compatibility plugin.
21  *
22  * @deprecated Marked as deprecated to suppress deprecation warnings.
23  */

24 public class RegistryCompatibilityHelper {
25     public static final String JavaDoc PI_RUNTIME_COMPATIBILITY = "org.eclipse.core.runtime.compatibility"; //$NON-NLS-1$
26
private static Bundle compatibility = null;
27
28     public synchronized static Bundle initializeCompatibility() {
29         // if compatibility is stale (has been uninstalled or unresolved)
30
// then we try to get a new resolved compatibility bundle
31
if (compatibility == null || (compatibility.getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED | Bundle.STOPPING)) != 0) {
32             compatibility = BundleHelper.getDefault().getBundle(PI_RUNTIME_COMPATIBILITY);
33         }
34         return compatibility;
35     }
36
37     public synchronized static IPluginDescriptor getPluginDescriptor(String JavaDoc pluginId) {
38         //Here we use reflection so the runtime code can run without the compatibility
39
initializeCompatibility();
40         if (compatibility == null)
41             throw new IllegalStateException JavaDoc();
42
43         Class JavaDoc oldInternalPlatform = null;
44         try {
45             oldInternalPlatform = compatibility.loadClass("org.eclipse.core.internal.plugins.InternalPlatform"); //$NON-NLS-1$
46
Method JavaDoc getPluginDescriptor = oldInternalPlatform.getMethod("getPluginDescriptor", new Class JavaDoc[] {String JavaDoc.class}); //$NON-NLS-1$
47
return (IPluginDescriptor) getPluginDescriptor.invoke(oldInternalPlatform, new Object JavaDoc[] {pluginId});
48         } catch (Exception JavaDoc e) {
49             //Ignore the exceptions, return null
50
}
51         return null;
52     }
53 }
54
Popular Tags