KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > jobs > JobActivator


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.jobs;
12
13 import java.util.Hashtable JavaDoc;
14 import org.eclipse.core.runtime.jobs.IJobManager;
15 import org.osgi.framework.*;
16
17 /**
18  * The Jobs plugin class.
19  */

20 public class JobActivator implements BundleActivator {
21
22     /**
23      * Eclipse property. Set to <code>false</code> to avoid registering JobManager
24      * as an OSGi service.
25      */

26     private static final String JavaDoc PROP_REGISTER_JOB_SERVICE = "eclipse.service.jobs"; //$NON-NLS-1$
27

28     /**
29      * The bundle associated this plug-in
30      */

31     private static BundleContext bundleContext;
32
33     /**
34      * This plugin provides a JobManager service.
35      */

36     private ServiceRegistration jobManagerService = null;
37
38     /**
39      * This method is called upon plug-in activation
40      */

41     public void start(BundleContext context) throws Exception JavaDoc {
42         bundleContext = context;
43         JobOSGiUtils.getDefault().openServices();
44
45         boolean shouldRegister = !"false".equalsIgnoreCase(context.getProperty(PROP_REGISTER_JOB_SERVICE)); //$NON-NLS-1$
46
if (shouldRegister)
47             registerServices();
48     }
49
50     /**
51      * This method is called when the plug-in is stopped
52      */

53     public void stop(BundleContext context) throws Exception JavaDoc {
54         unregisterServices();
55         JobManager.shutdown();
56         JobOSGiUtils.getDefault().closeServices();
57         bundleContext = null;
58     }
59
60     static BundleContext getContext() {
61         return bundleContext;
62     }
63
64     private void registerServices() {
65         jobManagerService = bundleContext.registerService(IJobManager.class.getName(), JobManager.getInstance(), new Hashtable JavaDoc());
66     }
67
68     private void unregisterServices() {
69         if (jobManagerService != null) {
70             jobManagerService.unregister();
71             jobManagerService = null;
72         }
73     }
74 }
75
Popular Tags