Skip to main content
summaryrefslogtreecommitdiffstats
blob: cb103b0ae60894e390ce453373e4f77ab0bc94ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
 * Copyright (c) 2005 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
 *******************************************************************************/

package org.eclipse.equinox.internal.app;

import org.eclipse.equinox.registry.IExtensionRegistry;
import org.eclipse.osgi.service.debug.DebugOptions;
import org.osgi.framework.*;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

public class Activator implements BundleActivator, ServiceTrackerCustomizer{
	public static final String PI_APP = "org.eclipse.equinox.app"; //$NON-NLS-1$
	public static boolean DEBUG = false;
	private BundleContext bContext;
	private ContainerManager containerMgr;
	// tracks the extension registry
	private ServiceTracker registryTracker;
	public void start(BundleContext context) throws Exception {
		this.bContext = context;
		getDebugOptions(context);
		// set the app manager context before starting the containerMgr
		AppManager.setBundleContext(context);
		registryTracker = new ServiceTracker(context, IExtensionRegistry.class.getName(), this);
		registryTracker.open();
		// start the app commands for the console
		try {
			AppCommands.create(context);
		} catch(NoClassDefFoundError e) {
			// catch incase CommandProvider is not available
		}
	}

	public void stop(BundleContext context) throws Exception {
		// stop the app commands for the console
		try {
			AppCommands.destroy(context);
		} catch(NoClassDefFoundError e) {
			// catch incase CommandProvider is not available
		}
		// close the registry tracker; this will stop the containerMgr if it was started
		registryTracker.close();
		registryTracker = null;
		// unset the app manager context after the containerMgr has been stopped
		AppManager.setBundleContext(null);
		bContext = null;
	}

	private void getDebugOptions(BundleContext context) {
		ServiceReference debugRef = context.getServiceReference(DebugOptions.class.getName());
		if (debugRef == null)
			return;
		DebugOptions debugOptions = (DebugOptions) context.getService(debugRef);
		DEBUG = debugOptions.getBooleanOption(PI_APP + "/debug", false); //$NON-NLS-1$
		context.ungetService(debugRef);
	}

	public Object addingService(ServiceReference reference) {
		if (containerMgr != null)
			return null;
		// create and start the app containerMgr
		IExtensionRegistry registry = (IExtensionRegistry) bContext.getService(reference);
		containerMgr = new ContainerManager(bContext, registry);
		containerMgr.startContainer();
		return registry;
	}

	public void modifiedService(ServiceReference reference, Object service) {
		// do nothing
	}

	public void removedService(ServiceReference reference, Object service) {
		if (containerMgr == null)
			return;
		// stop the app containerMgr
		containerMgr.stopContainer();
		containerMgr = null;
	}
}

Back to the top