/******************************************************************************* * Copyright (c) 2009 EclipseSource 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: * EclipseSource - initial API and implementation *******************************************************************************/ package org.eclipse.ecf.internal.remoteservice.rest; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.SafeRunner; import org.eclipse.ecf.core.ContainerTypeDescription; import org.eclipse.ecf.core.identity.Namespace; import org.eclipse.ecf.core.util.*; import org.eclipse.ecf.remoteservice.rest.identity.RestNamespace; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.service.log.LogService; import org.osgi.util.tracker.ServiceTracker; /** * The activator class controls the plug-in life cycle */ public class Activator implements BundleActivator { // The plug-in ID public static final String PLUGIN_ID = "org.eclipse.ecf.remoteservice.rest"; //$NON-NLS-1$ // The shared instance private static Activator plugin; private BundleContext context; private ServiceTracker logServiceTracker = null; private LogService logService = null; /* * (non-Javadoc) * * @see * org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) */ public void start(final BundleContext context1) throws Exception { plugin = this; this.context = context1; SafeRunner.run(new ExtensionRegistryRunnable(context1) { protected void runWithoutRegistry() throws Exception { context1.registerService(Namespace.class, new RestNamespace(), null); context1.registerService(ContainerTypeDescription.class, new ContainerTypeDescription("ecf.rest.client", new RestClientContainerInstantiator(), "Rest Client Container"), null); //$NON-NLS-1$ //$NON-NLS-2$ } }); } /* * (non-Javadoc) * * @see * org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context1) throws Exception { if (logServiceTracker != null) { logServiceTracker.close(); logServiceTracker = null; logService = null; } plugin = null; this.context = null; } /** * Returns the shared instance * * @return the shared instance */ public static synchronized Activator getDefault() { if (plugin == null) { plugin = new Activator(); } return plugin; } public BundleContext getContext() { return context; } protected LogService getLogService() { if (logServiceTracker == null) { logServiceTracker = new ServiceTracker(this.context, LogService.class.getName(), null); logServiceTracker.open(); } logService = (LogService) logServiceTracker.getService(); if (logService == null) logService = new SystemLogService(PLUGIN_ID); return logService; } public void log(IStatus status) { if (logService == null) logService = getLogService(); if (logService != null) logService.log(LogHelper.getLogCode(status), LogHelper.getLogMessage(status), status.getException()); } }