diff options
5 files changed, 122 insertions, 24 deletions
diff --git a/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF index e04e237fd..5d5593285 100644 --- a/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF +++ b/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF @@ -16,4 +16,7 @@ Import-Package: org.eclipse.core.runtime, org.eclipse.osgi.service.debug;version="1.0.0", org.eclipse.osgi.util;version="1.0.0", org.osgi.framework;version="1.3.0", + org.osgi.service.log;version="1.3.0", org.osgi.util.tracker;version="1.3.2" +Require-Bundle: org.eclipse.equinox.common, + org.eclipse.equinox.registry diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java index 1da69358e..8d767304e 100644 --- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java +++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java @@ -210,7 +210,7 @@ public class IDFactory implements IIDFactory { Trace.throwing(Activator.PLUGIN_ID, IdentityDebugOptions.EXCEPTIONS_THROWING, IDFactory.class, "logAndThrow", e); //$NON-NLS-1$ - Activator.getDefault().getLog().log( + Activator.getDefault().log( new Status(IStatus.ERROR, Activator.PLUGIN_ID, IDENTITY_CREATION_ERRORCODE, s, e)); throw e; diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/Namespace.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/Namespace.java index b413aae9f..3c11115d7 100644 --- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/Namespace.java +++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/Namespace.java @@ -12,7 +12,8 @@ import java.io.Serializable; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.ecf.internal.core.identity.Activator; import org.eclipse.ecf.internal.core.identity.Messages; /** @@ -235,7 +236,9 @@ public abstract class Namespace implements Serializable, IAdaptable { if (adapter.isInstance(this)) { return this; } else { - return Platform.getAdapterManager().loadAdapter(this, adapter.getName()); + IAdapterManager manager = Activator.getDefault().getAdapterManager(); + if (manager == null) return null; + else return manager.loadAdapter(this, adapter.getName()); } } diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/LogHelper.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/LogHelper.java new file mode 100644 index 000000000..f862032b0 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/LogHelper.java @@ -0,0 +1,54 @@ +/**************************************************************************** + * 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.util.Arrays; + +import org.eclipse.core.runtime.IStatus; +import org.osgi.service.log.LogService; + +public class LogHelper { + + public static int getLogCode(IStatus status) { + switch (status.getCode()) { + case IStatus.CANCEL: + return LogService.LOG_INFO; + case IStatus.ERROR: + return LogService.LOG_ERROR; + case IStatus.INFO: + return LogService.LOG_INFO; + case IStatus.OK: + return LogService.LOG_INFO; + case IStatus.WARNING: + return LogService.LOG_WARNING; + default: + return IStatus.INFO; + } + } + + /** + * @param status + * @return + */ + public static String getLogMessage(IStatus status) { + if (status == null) return ""; + StringBuffer buf = new StringBuffer(status.getClass().getName()+"["); + buf.append("plugin=").append(status.getPlugin()); + buf.append(";code=").append(status.getCode()); + buf.append(";message=").append(status.getMessage()); + buf.append(";severity").append(status.getSeverity()); + buf.append(";exception=").append(status.getException()); + buf.append(";children=").append(Arrays.asList(status.getChildren())).append("]"); + return buf.toString(); + } + +} 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 33b09e1cc..1d37d4d22 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 @@ -9,6 +9,7 @@ package org.eclipse.ecf.internal.core.identity; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdapterManager; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionDelta; @@ -17,21 +18,25 @@ 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.Plugin; +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.Trace; import org.eclipse.osgi.service.debug.DebugOptions; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; +import org.osgi.service.log.LogService; import org.osgi.util.tracker.ServiceTracker; /** * The activator class controls the plug-in life cycle */ -public class Activator extends Plugin { +public class Activator implements BundleActivator { // The plug-in ID public static final String PLUGIN_ID = "org.eclipse.ecf.identity"; //$NON-NLS-1$ @@ -54,6 +59,8 @@ public class Activator extends Plugin { // The shared instance private static Activator plugin; + private BundleContext context = null; + private IRegistryChangeListener registryManager = null; private ServiceRegistration idFactoryServiceRegistration = null; @@ -61,7 +68,9 @@ public class Activator extends Plugin { private ServiceTracker extensionRegistryTracker = null; private ServiceTracker debugOptionsTracker = null; - + + private ServiceTracker logServiceTracker = null; + /** * The constructor */ @@ -69,32 +78,36 @@ public class Activator extends Plugin { } public IExtensionRegistry getExtensionRegistry() { + if (extensionRegistryTracker == null) { + extensionRegistryTracker = new ServiceTracker(context, + IExtensionRegistry.class.getName(), null); + extensionRegistryTracker.open(); + } return (IExtensionRegistry) extensionRegistryTracker.getService(); } public DebugOptions getDebugOptions() { + if (debugOptionsTracker == null) { + debugOptionsTracker = new ServiceTracker(context, + DebugOptions.class.getName(), null); + debugOptionsTracker.open(); + } return (DebugOptions) debugOptionsTracker.getService(); } - + /* * (non-Javadoc) * * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) */ public void start(BundleContext context) throws Exception { - super.start(context); plugin = this; - this.extensionRegistryTracker = new ServiceTracker(context, - IExtensionRegistry.class.getName(), null); - this.extensionRegistryTracker.open(); + this.context = context; IExtensionRegistry reg = getExtensionRegistry(); if (reg != null) { this.registryManager = new IdentityRegistryManager(); reg.addRegistryChangeListener(registryManager); } - this.debugOptionsTracker = new ServiceTracker(context, - DebugOptions.class.getName(), null); - this.debugOptionsTracker.open(); this.setupNamespaceExtensionPoint(); Trace .exiting(Activator.PLUGIN_ID, @@ -156,11 +169,10 @@ public class Activator extends Plugin { "removeNamespaceExtensions.removedNamespace(" //$NON-NLS-1$ + n + ")"); //$NON-NLS-1$ } catch (Exception e) { - org.eclipse.ecf.core.util.Trace.catching( - Activator.PLUGIN_ID, + org.eclipse.ecf.core.util.Trace.catching(Activator.PLUGIN_ID, IdentityDebugOptions.EXCEPTIONS_CATCHING, Activator.class, "removeNamespaceExtensions", e); //$NON-NLS-1$ - getDefault().getLog().log( + getDefault().log( new Status(IStatus.ERROR, Activator.PLUGIN_ID, REMOVE_NAMESPACE_ERRORCODE, "Exception removing namespace", e)); //$NON-NLS-1$ @@ -171,6 +183,36 @@ public class Activator extends Plugin { "removeNamespaceExtensions", members); //$NON-NLS-1$ } + public Bundle getBundle() { + if (context == null) + return null; + else + return context.getBundle(); + } + + protected LogService getLogService() { + if (logServiceTracker == null) { + logServiceTracker = new ServiceTracker(this.context, + LogService.class.getName(), null); + logServiceTracker.open(); + } + return (LogService) logServiceTracker.getService(); + } + + public void log(IStatus status) { + LogService logService = getLogService(); + if (logService != null) { + logService.log(LogHelper.getLogCode(status), LogHelper + .getLogMessage(status), status.getException()); + } + } + + public IAdapterManager getAdapterManager() { + // XXX todo...replace with new adaptermanager service + return Platform.getAdapterManager(); + //return null; + } + /** * Add identity namespace extension point extensions * @@ -222,14 +264,12 @@ public class Activator extends Plugin { "addNamespaceExtensions.addedNamespaceToFactory(" + ns //$NON-NLS-1$ + ")"); //$NON-NLS-1$ } catch (CoreException e) { - getDefault().getLog().log(e.getStatus()); - org.eclipse.ecf.core.util.Trace.catching( - Activator.PLUGIN_ID, + getDefault().log(e.getStatus()); + org.eclipse.ecf.core.util.Trace.catching(Activator.PLUGIN_ID, IdentityDebugOptions.EXCEPTIONS_CATCHING, Activator.class, "addNamespaceExtensions", e); //$NON-NLS-1$ } catch (Exception e) { getDefault() - .getLog() .log( new Status( Status.ERROR, @@ -241,8 +281,7 @@ public class Activator extends Plugin { + extension .getExtensionPointUniqueIdentifier(), null)); - org.eclipse.ecf.core.util.Trace.catching( - Activator.PLUGIN_ID, + org.eclipse.ecf.core.util.Trace.catching(Activator.PLUGIN_ID, IdentityDebugOptions.EXCEPTIONS_CATCHING, Activator.class, "addNamespaceExtensions", e); //$NON-NLS-1$ } @@ -294,7 +333,6 @@ public class Activator extends Plugin { idFactoryServiceRegistration.unregister(); idFactoryServiceRegistration = null; } - super.stop(context); } /** |