diff dwtx/core/internal/jobs/JobActivator.d @ 122:9d0585bcb7aa

Add core.jobs package
author Frank Benoit <benoit@tionex.de>
date Tue, 12 Aug 2008 02:34:21 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/core/internal/jobs/JobActivator.d	Tue Aug 12 02:34:21 2008 +0200
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 IBM Corporation 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:
+ *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
+ *******************************************************************************/
+module dwtx.core.internal.jobs.JobActivator;
+
+import dwt.dwthelper.utils;
+
+// import org.osgi.framework.BundleActivator;
+// import org.osgi.framework.BundleContext;
+// import org.osgi.framework.ServiceRegistration;
+
+import dwtx.core.runtime.jobs.IJobManager;
+
+/**
+ * The Jobs plugin class.
+ */
+public class JobActivator /+: BundleActivator+/ {
+
+    /**
+     * Eclipse property. Set to <code>false</code> to avoid registering JobManager
+     * as an OSGi service.
+     */
+    private static const String PROP_REGISTER_JOB_SERVICE = "eclipse.service.jobs"; //$NON-NLS-1$
+/++
+    /**
+     * The bundle associated this plug-in
+     */
+    private static BundleContext bundleContext;
+
+    /**
+     * This plugin provides a JobManager service.
+     */
+    private ServiceRegistration jobManagerService = null;
+
+    /**
+     * This method is called upon plug-in activation
+     */
+    public void start(BundleContext context) throws Exception {
+        bundleContext = context;
+        JobOSGiUtils.getDefault().openServices();
+
+        bool shouldRegister = !"false".equalsIgnoreCase(context.getProperty(PROP_REGISTER_JOB_SERVICE)); //$NON-NLS-1$
+        if (shouldRegister)
+            registerServices();
+    }
+
+    /**
+     * This method is called when the plug-in is stopped
+     */
+    public void stop(BundleContext context) throws Exception {
+        unregisterServices();
+        JobManager.shutdown();
+        JobOSGiUtils.getDefault().closeServices();
+        bundleContext = null;
+    }
+
+    static BundleContext getContext() {
+        return bundleContext;
+    }
+
+    private void registerServices() {
+        jobManagerService = bundleContext.registerService(IJobManager.class.getName(), JobManager.getInstance(), new Hashtable());
+    }
+
+    private void unregisterServices() {
+        if (jobManagerService !is null) {
+            jobManagerService.unregister();
+            jobManagerService = null;
+        }
+    }
+++/
+}