Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: df6788f4e408575b43514bae9f871738ec15525e (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
/*******************************************************************************
 * Copyright (c) 2005, 2007 Cognos Incorporated, 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:
 *     Cognos Incorporated - initial API and implementation
 *     IBM Corporation - bug fixes and enhancements
 *******************************************************************************/

package org.eclipse.equinox.http.registry.internal;

import org.eclipse.core.runtime.IExtensionRegistry;
import org.osgi.framework.*;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

public class Activator implements BundleActivator, ServiceTrackerCustomizer {

	private ServiceTracker httpServiceTracker;
	private ServiceTracker packageAdminTracker;
	private ServiceTracker registryTracker;

	private PackageAdmin packageAdmin;
	private IExtensionRegistry registry;
	private BundleContext context;

	public void start(BundleContext context) throws Exception {
		this.context = context;
		packageAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), this);
		packageAdminTracker.open();

		registryTracker = new ServiceTracker(context, IExtensionRegistry.class.getName(), this);
		registryTracker.open();
	}

	public void stop(BundleContext context) throws Exception {
		packageAdminTracker.close();
		packageAdminTracker = null;
		registryTracker.close();
		registryTracker = null;
		this.context = null;
	}

	public Object addingService(ServiceReference reference) {
		Object service = context.getService(reference);

		if (service instanceof PackageAdmin && packageAdmin == null)
			packageAdmin = (PackageAdmin) service;

		if (service instanceof IExtensionRegistry && registry == null)
			registry = (IExtensionRegistry) service;

		if (packageAdmin != null && registry != null) {
			httpServiceTracker = new HttpServiceTracker(context, packageAdmin, registry);
			httpServiceTracker.open();
		}

		return service;
	}

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

	public void removedService(ServiceReference reference, Object service) {
		if (service == packageAdmin)
			packageAdmin = null;

		if (service == registry)
			registry = null;

		if (packageAdmin == null || registry == null) {
			if (httpServiceTracker != null) {
				httpServiceTracker.close();
				httpServiceTracker = null;
			}
		}
		context.ungetService(reference);
	}

}

Back to the top