diff options
author | slewis | 2007-10-08 21:19:57 +0000 |
---|---|---|
committer | slewis | 2007-10-08 21:19:57 +0000 |
commit | 9460390a85fe77494ad9513aee6b669819fc628c (patch) | |
tree | 4c25cff8e3b811ccc0b254626d15c3fa664a627d /framework/bundles/org.eclipse.ecf | |
parent | 63ea8c7a71ef01294f4a6651be21398d7dd6f242 (diff) | |
download | org.eclipse.ecf-9460390a85fe77494ad9513aee6b669819fc628c.tar.gz org.eclipse.ecf-9460390a85fe77494ad9513aee6b669819fc628c.tar.xz org.eclipse.ecf-9460390a85fe77494ad9513aee6b669819fc628c.zip |
Added SystemLogService class to implement osgi LogService interface. Setup org.eclipse.ecf and org.eclipse.ecf.identity bundles to use this LogService if no others are available.
Diffstat (limited to 'framework/bundles/org.eclipse.ecf')
-rw-r--r-- | framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java | 147 |
1 files changed, 48 insertions, 99 deletions
diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java index 81299debb..0b9dbc686 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java @@ -33,6 +33,7 @@ import org.eclipse.ecf.core.start.ECFStartJob; import org.eclipse.ecf.core.start.IECFStart; import org.eclipse.ecf.core.util.LogHelper; import org.eclipse.ecf.core.util.PlatformHelper; +import org.eclipse.ecf.core.util.SystemLogService; import org.eclipse.ecf.core.util.Trace; import org.eclipse.osgi.util.NLS; import org.osgi.framework.Bundle; @@ -50,15 +51,13 @@ public class ECFPlugin implements BundleActivator { private static final String CONTAINER_FACTORY_NAME = "containerFactory"; //$NON-NLS-1$ - private static final String CONTAINER_FACTORY_EPOINT = ECFNAMESPACE - + "." + CONTAINER_FACTORY_NAME; //$NON-NLS-1$ + private static final String CONTAINER_FACTORY_EPOINT = ECFNAMESPACE + "." + CONTAINER_FACTORY_NAME; //$NON-NLS-1$ private static final String STARTUP_NAME = "startup"; //$NON-NLS-1$ public static final String START_EPOINT = ECFNAMESPACE + "." + STARTUP_NAME; //$NON-NLS-1$ - public static final String PLUGIN_RESOURCE_BUNDLE = ECFNAMESPACE - + ".ECFPluginResources"; //$NON-NLS-1$ + public static final String PLUGIN_RESOURCE_BUNDLE = ECFNAMESPACE + ".ECFPluginResources"; //$NON-NLS-1$ public static final String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$ @@ -91,25 +90,23 @@ public class ECFPlugin implements BundleActivator { private ServiceTracker logServiceTracker = null; + private LogService logService = 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 = new ServiceTracker(this.context, IAdapterManager.class.getName(), null); adapterManagerTracker.open(); } - IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker - .getService(); + 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$ + getDefault().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Cannot get adapter manager", null)); //$NON-NLS-1$ return adapterManager; } @@ -140,27 +137,25 @@ public class ECFPlugin implements BundleActivator { protected LogService getLogService() { if (logServiceTracker == null) { - logServiceTracker = new ServiceTracker(this.context, - LogService.class.getName(), null); + logServiceTracker = new ServiceTracker(this.context, LogService.class.getName(), null); logServiceTracker.open(); } - return (LogService) logServiceTracker.getService(); + logService = (LogService) logServiceTracker.getService(); + if (logService == null) + logService = new SystemLogService(PLUGIN_ID); + return logService; } public void log(IStatus status) { final LogService logService = getLogService(); if (logService != null) { - logService.log(LogHelper.getLogCode(status), LogHelper - .getLogMessage(status), status.getException()); + logService.log(LogHelper.getLogCode(status), LogHelper.getLogMessage(status), status.getException()); } } - protected void logException(IStatus status, String method, - Throwable exception) { + protected void logException(IStatus status, String method, Throwable exception) { log(status); - Trace.catching(ECFPlugin.PLUGIN_ID, - ECFDebugOptions.EXCEPTIONS_CATCHING, ECFPlugin.class, method, - exception); + Trace.catching(ECFPlugin.PLUGIN_ID, ECFDebugOptions.EXCEPTIONS_CATCHING, ECFPlugin.class, method, exception); } /** @@ -169,11 +164,9 @@ public class ECFPlugin implements BundleActivator { * @param members * the members to remove */ - protected void removeContainerFactoryExtensions( - IConfigurationElement[] members) { + protected void removeContainerFactoryExtensions(IConfigurationElement[] members) { final String method = "removeContainerFactoryExtensions"; //$NON-NLS-1$ - Trace.entering(ECFPlugin.PLUGIN_ID, ECFDebugOptions.METHODS_ENTERING, - ECFPlugin.class, method, members); + Trace.entering(ECFPlugin.PLUGIN_ID, ECFDebugOptions.METHODS_ENTERING, ECFPlugin.class, method, members); // For each configuration element for (int m = 0; m < members.length; m++) { final IConfigurationElement member = members[m]; @@ -187,21 +180,15 @@ public class ECFPlugin implements BundleActivator { name = member.getAttribute(CLASS_ATTRIBUTE); } final IContainerFactory factory = ContainerFactory.getDefault(); - final ContainerTypeDescription cd = factory - .getDescriptionByName(name); + final ContainerTypeDescription cd = factory.getDescriptionByName(name); if (cd == null || !factory.containsDescription(cd)) { continue; } // remove factory.removeDescription(cd); - Trace.trace(ECFPlugin.PLUGIN_ID, ECFDebugOptions.DEBUG, method - + ".removed " + cd + " from factory"); //$NON-NLS-1$ //$NON-NLS-2$ + Trace.trace(ECFPlugin.PLUGIN_ID, ECFDebugOptions.DEBUG, method + ".removed " + cd + " from factory"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (final Exception e) { - logException(new Status(Status.ERROR, getDefault().getBundle() - .getSymbolicName(), IStatus.ERROR, NLS.bind( - Messages.ECFPlugin_Container_Name_Collision_Prefix, - name, extension.getExtensionPointUniqueIdentifier()), - null), method, e); + logException(new Status(Status.ERROR, getDefault().getBundle().getSymbolicName(), IStatus.ERROR, NLS.bind(Messages.ECFPlugin_Container_Name_Collision_Prefix, name, extension.getExtensionPointUniqueIdentifier()), null), method, e); } } } @@ -214,8 +201,7 @@ public class ECFPlugin implements BundleActivator { */ protected void addContainerFactoryExtensions(IConfigurationElement[] members) { final String method = "addContainerFactoryExtensions"; //$NON-NLS-1$ - Trace.entering(ECFPlugin.PLUGIN_ID, ECFDebugOptions.METHODS_ENTERING, - ECFPlugin.class, method, members); + Trace.entering(ECFPlugin.PLUGIN_ID, ECFDebugOptions.METHODS_ENTERING, ECFPlugin.class, method, members); // For each configuration element for (int m = 0; m < members.length; m++) { final IConfigurationElement member = members[m]; @@ -239,45 +225,25 @@ public class ECFPlugin implements BundleActivator { } String s = member.getAttribute(SERVER_ATTRIBUTE); - final boolean server = (s == null) ? false : Boolean.valueOf(s) - .booleanValue(); + final boolean server = (s == null) ? false : Boolean.valueOf(s).booleanValue(); s = member.getAttribute(HIDDEN_ATTRIBUTE); - final boolean hidden = (s == null) ? false : Boolean.valueOf(s) - .booleanValue(); + final boolean hidden = (s == null) ? false : Boolean.valueOf(s).booleanValue(); // Now make description instance - final ContainerTypeDescription scd = new ContainerTypeDescription( - name, (IContainerInstantiator) exten, description, - server, hidden); + final ContainerTypeDescription scd = new ContainerTypeDescription(name, (IContainerInstantiator) exten, description, server, hidden); final IContainerFactory factory = ContainerFactory.getDefault(); if (factory.containsDescription(scd)) { - throw new CoreException( - new Status( - Status.ERROR, - getDefault().getBundle().getSymbolicName(), - IStatus.ERROR, - NLS - .bind( - Messages.ECFPlugin_Container_Name_Collision_Prefix, - name, - extension - .getExtensionPointUniqueIdentifier()), - null)); + throw new CoreException(new Status(Status.ERROR, getDefault().getBundle().getSymbolicName(), IStatus.ERROR, NLS.bind(Messages.ECFPlugin_Container_Name_Collision_Prefix, name, extension.getExtensionPointUniqueIdentifier()), null)); } // Now add the description and we're ready to go. factory.addDescription(scd); - Trace.trace(ECFPlugin.PLUGIN_ID, ECFDebugOptions.DEBUG, method - + ".added " + scd + " to factory " + factory); //$NON-NLS-1$ //$NON-NLS-2$ + Trace.trace(ECFPlugin.PLUGIN_ID, ECFDebugOptions.DEBUG, method + ".added " + scd + " to factory " + factory); //$NON-NLS-1$ //$NON-NLS-2$ } catch (final CoreException e) { logException(e.getStatus(), method, e); } catch (final Exception e) { - logException(new Status(Status.ERROR, getDefault().getBundle() - .getSymbolicName(), IStatus.ERROR, NLS.bind( - Messages.ECFPlugin_Container_Name_Collision_Prefix, - name, extension.getExtensionPointUniqueIdentifier()), - null), method, e); + logException(new Status(Status.ERROR, getDefault().getBundle().getSymbolicName(), IStatus.ERROR, NLS.bind(Messages.ECFPlugin_Container_Name_Collision_Prefix, name, extension.getExtensionPointUniqueIdentifier()), null), method, e); } } } @@ -291,13 +257,11 @@ public class ECFPlugin implements BundleActivator { protected void setupContainerFactoryExtensionPoint(BundleContext bc) { final IExtensionRegistry reg = getExtensionRegistry(); if (reg != null) { - final IExtensionPoint extensionPoint = reg - .getExtensionPoint(CONTAINER_FACTORY_EPOINT); + final IExtensionPoint extensionPoint = reg.getExtensionPoint(CONTAINER_FACTORY_EPOINT); if (extensionPoint == null) { return; } - addContainerFactoryExtensions(extensionPoint - .getConfigurationElements()); + addContainerFactoryExtensions(extensionPoint.getConfigurationElements()); } } @@ -314,8 +278,7 @@ public class ECFPlugin implements BundleActivator { protected void setupStartExtensionPoint(BundleContext bc) { final IExtensionRegistry reg = getExtensionRegistry(); if (reg != null) { - final IExtensionPoint extensionPoint = reg - .getExtensionPoint(START_EPOINT); + final IExtensionPoint extensionPoint = reg.getExtensionPoint(START_EPOINT); if (extensionPoint == null) { return; } @@ -323,8 +286,7 @@ public class ECFPlugin implements BundleActivator { } } - protected void runStartExtensions( - IConfigurationElement[] configurationElements) { + protected void runStartExtensions(IConfigurationElement[] configurationElements) { final String method = "runStartExtensions"; //$NON-NLS-1$ // For each configuration element for (int m = 0; m < configurationElements.length; m++) { @@ -333,27 +295,22 @@ public class ECFPlugin implements BundleActivator { String name = null; try { // The only required attribute is "class" - exten = (IECFStart) member - .createExecutableExtension(CLASS_ATTRIBUTE); + exten = (IECFStart) member.createExecutableExtension(CLASS_ATTRIBUTE); // Get name and get version, if available name = member.getAttribute(NAME_ATTRIBUTE); if (name == null) name = exten.getClass().getName(); - startExtension(name, exten, Boolean.valueOf( - member.getAttribute(SYNCH_ATTRIBUTE)).booleanValue()); + startExtension(name, exten, Boolean.valueOf(member.getAttribute(SYNCH_ATTRIBUTE)).booleanValue()); } catch (final CoreException e) { logException(e.getStatus(), method, e); } catch (final Exception e) { - logException(new Status(Status.ERROR, getDefault().getBundle() - .getSymbolicName(), IStatus.ERROR, - "Unknown start exception", e), method, e); //$NON-NLS-1$ + logException(new Status(Status.ERROR, getDefault().getBundle().getSymbolicName(), IStatus.ERROR, "Unknown start exception", e), method, e); //$NON-NLS-1$ } } } - private void startExtension(String name, IECFStart exten, - boolean synchronous) { + private void startExtension(String name, IECFStart exten, boolean synchronous) { // Create job to do start, and schedule if (synchronous) { IStatus result = null; @@ -361,8 +318,7 @@ public class ECFPlugin implements BundleActivator { result = exten.startup(new NullProgressMonitor()); } catch (final Exception e) { final String message = "startup extension error"; //$NON-NLS-1$ - logException(new Status(IStatus.ERROR, PLUGIN_ID, - IStatus.ERROR, message, e), message, e); + logException(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, e), message, e); } if (result != null && !result.isOK()) logException(result, result.getMessage(), result.getException()); @@ -378,38 +334,30 @@ public class ECFPlugin implements BundleActivator { public void start(BundleContext context) throws Exception { plugin = this; this.context = context; - this.extensionRegistryTracker = new ServiceTracker(context, - IExtensionRegistry.class.getName(), null); + this.extensionRegistryTracker = new ServiceTracker(context, IExtensionRegistry.class.getName(), null); this.extensionRegistryTracker.open(); final IExtensionRegistry registry = getExtensionRegistry(); if (registry != null) { this.registryManager = new ECFRegistryManager(); registry.addRegistryChangeListener(registryManager); } - containerFactoryServiceRegistration = context.registerService( - IContainerFactory.class.getName(), ContainerFactory - .getDefault(), null); - containerManagerServiceRegistration = context.registerService( - IContainerManager.class.getName(), ContainerFactory - .getDefault(), null); + containerFactoryServiceRegistration = context.registerService(IContainerFactory.class.getName(), ContainerFactory.getDefault(), null); + containerManagerServiceRegistration = context.registerService(IContainerManager.class.getName(), ContainerFactory.getDefault(), null); setupContainerFactoryExtensionPoint(context); setupStartExtensionPoint(context); } protected class ECFRegistryManager implements IRegistryChangeListener { public void registryChanged(IRegistryChangeEvent event) { - final IExtensionDelta delta[] = event.getExtensionDeltas( - ECFNAMESPACE, CONTAINER_FACTORY_NAME); + final IExtensionDelta delta[] = event.getExtensionDeltas(ECFNAMESPACE, CONTAINER_FACTORY_NAME); for (int i = 0; i < delta.length; i++) { switch (delta[i].getKind()) { - case IExtensionDelta.ADDED: - addContainerFactoryExtensions(delta[i].getExtension() - .getConfigurationElements()); - break; - case IExtensionDelta.REMOVED: - removeContainerFactoryExtensions(delta[i].getExtension() - .getConfigurationElements()); - break; + case IExtensionDelta.ADDED : + addContainerFactoryExtensions(delta[i].getExtension().getConfigurationElements()); + break; + case IExtensionDelta.REMOVED : + removeContainerFactoryExtensions(delta[i].getExtension().getConfigurationElements()); + break; } } } @@ -428,6 +376,7 @@ public class ECFPlugin implements BundleActivator { if (logServiceTracker != null) { logServiceTracker.close(); logServiceTracker = null; + logService = null; } if (extensionRegistryTracker != null) { extensionRegistryTracker.close(); |