Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-03-16 21:35:04 -0400
committerslewis2007-03-16 21:35:04 -0400
commitb85a774d6b480b32fd9c6a8d475926d2b3870634 (patch)
treed41eb075364024cec4a0cf996ea8a885e07eaa5e /framework/bundles/org.eclipse.ecf.identity/src
parentcd2107554fb6d3bbb5485e31293de8b3884b5a1a (diff)
downloadorg.eclipse.ecf-b85a774d6b480b32fd9c6a8d475926d2b3870634.tar.gz
org.eclipse.ecf-b85a774d6b480b32fd9c6a8d475926d2b3870634.tar.xz
org.eclipse.ecf-b85a774d6b480b32fd9c6a8d475926d2b3870634.zip
Added org.eclipse.ecf.util.PlatformHelper class to eliminate use of Platform directly (through dynamic classload of Platform class and use of reflection for calling getAdapterManager and/or getExtensionRegistry). Removed all ECF non-UI or example bundle references to Platform class and to org.eclipse.core.runtime package or bundle.
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.identity/src')
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/PlatformHelper.java109
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/internal/core/identity/Activator.java34
2 files changed, 136 insertions, 7 deletions
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/PlatformHelper.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/PlatformHelper.java
new file mode 100644
index 000000000..e2978a3ae
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/PlatformHelper.java
@@ -0,0 +1,109 @@
+/****************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.ecf.core.util;
+
+import java.lang.reflect.Method;
+
+import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ecf.internal.core.identity.Activator;
+
+/**
+ * Helper class for eliminating direct references to Platform static methods
+ * getAdapterManager and getExtensionRegistry. Note that instead of
+ * Platform.getAdapterManager(), clients can call
+ * PlatformHelper.getAdapterManager(). If this returns null, the Platform class
+ * is not available.
+ */
+public class PlatformHelper {
+
+ private static Class platformClass = null;
+
+ private static IAdapterManager adapterManagerCache = null;
+
+ private static IExtensionRegistry extensionRegistryCache = null;
+
+ static {
+ try {
+ platformClass = Class.forName("org.eclipse.core.runtime.Platform"); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ // Platform not available...just leave platformClass == null
+ }
+ }
+
+ public synchronized static boolean isPlatformAvailable() {
+ return platformClass != null;
+ }
+
+ public synchronized static IAdapterManager getPlatformAdapterManager() {
+ if (adapterManagerCache != null)
+ return adapterManagerCache;
+ if (!isPlatformAvailable()) {
+ Activator
+ .getDefault()
+ .log(
+ new Status(
+ IStatus.ERROR,
+ Activator.PLUGIN_ID,
+ IStatus.ERROR,
+ "org.eclipse.core.runtime.Platform class not available", //$NON-NLS-1$
+ null));
+ return null;
+ } else {
+ try {
+ Method m = platformClass.getMethod("getAdapterManager", null); //$NON-NLS-1$
+ adapterManagerCache = (IAdapterManager) m.invoke(null, null);
+ return adapterManagerCache;
+ } catch (Exception e) {
+ Activator.getDefault().log(
+ new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ IStatus.ERROR,
+ "exception in getPlatformAdapterManager", e)); //$NON-NLS-1$
+ return null;
+ }
+ }
+ }
+
+ public synchronized static IExtensionRegistry getExtensionRegistry() {
+ if (extensionRegistryCache != null)
+ return extensionRegistryCache;
+ if (!isPlatformAvailable()) {
+ Activator
+ .getDefault()
+ .log(
+ new Status(
+ IStatus.ERROR,
+ Activator.PLUGIN_ID,
+ IStatus.ERROR,
+ "org.eclipse.core.runtime.Platform class not available", //$NON-NLS-1$
+ null));
+ return null;
+ } else {
+ try {
+ Method m = platformClass
+ .getMethod("getExtensionRegistry", null); //$NON-NLS-1$
+ extensionRegistryCache = (IExtensionRegistry) m.invoke(null,
+ null);
+ return extensionRegistryCache;
+ } catch (Exception e) {
+ Activator.getDefault().log(
+ new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ IStatus.ERROR,
+ "exception in getExtensionRegistry", e)); //$NON-NLS-1$
+ return null;
+ }
+ }
+ }
+
+}
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/internal/core/identity/Activator.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/internal/core/identity/Activator.java
index 0f27c26a2..0e615139b 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/internal/core/identity/Activator.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/internal/core/identity/Activator.java
@@ -18,12 +18,12 @@ import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.identity.IIDFactory;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.util.LogHelper;
+import org.eclipse.ecf.core.util.PlatformHelper;
import org.eclipse.ecf.core.util.Trace;
import org.eclipse.osgi.service.debug.DebugOptions;
import org.osgi.framework.Bundle;
@@ -71,6 +71,28 @@ public class Activator implements BundleActivator {
private ServiceTracker logServiceTracker = null;
+ private ServiceTracker adapterManagerTracker = null;
+
+ public IAdapterManager getAdapterManager() {
+ // First, try to get the adapter manager via
+ if (adapterManagerTracker == null) {
+ adapterManagerTracker = new ServiceTracker(this.context,
+ IAdapterManager.class.getName(), null);
+ adapterManagerTracker.open();
+ }
+ IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker
+ .getService();
+ // Then, if the service isn't there, try to get from Platform class via
+ // PlatformHelper class
+ if (adapterManager == null)
+ adapterManager = PlatformHelper.getPlatformAdapterManager();
+ if (adapterManager == null)
+ getDefault().log(
+ new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
+ "Cannot get adapter manager", null)); //$NON-NLS-1$
+ return adapterManager;
+ }
+
/**
* The constructor
*/
@@ -207,12 +229,6 @@ public class Activator implements BundleActivator {
}
}
- public IAdapterManager getAdapterManager() {
- // XXX todo...replace with new adaptermanager service
- return Platform.getAdapterManager();
- //return null;
- }
-
/**
* Add identity namespace extension point extensions
*
@@ -337,6 +353,10 @@ public class Activator implements BundleActivator {
idFactoryServiceRegistration.unregister();
idFactoryServiceRegistration = null;
}
+ if (adapterManagerTracker != null) {
+ adapterManagerTracker.close();
+ adapterManagerTracker = null;
+ }
context = null;
}

Back to the top