Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5b28e4ec44bbf9a22e320c95bd64ee370c9d8196 (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
/*******************************************************************************
 * Copyright (c) 2005, 2018 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.equinox.internal.event;

import org.osgi.framework.*;
import org.osgi.service.event.EventAdmin;

public class Activator implements BundleActivator {
	private static final String PROP_USE_DS = "equinox.use.ds"; //$NON-NLS-1$
	private ServiceRegistration<EventAdmin> eventAdminService;
	private EventComponent eventAdmin;

	@Override
	public void start(BundleContext bundleContext) throws InvalidSyntaxException {
		if (Boolean.valueOf(bundleContext.getProperty(PROP_USE_DS)).booleanValue())
			return; // If this property is set we assume DS is being used.
		String serviceName = EventAdmin.class.getName();
		Filter serviceFilter = bundleContext.createFilter("(objectclass=" + serviceName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
		//don't register the service if this bundle has already registered it declaratively
		ServiceReference<?>[] refs = bundleContext.getBundle().getRegisteredServices();
		if (refs != null) {
			for (int i = 0; i < refs.length; i++)
				if (serviceFilter.match(refs[i]))
					return; // We found a service registered by this bundle already
		}

		eventAdmin = new EventComponent();
		eventAdmin.activate(bundleContext);
		eventAdminService = bundleContext.registerService(EventAdmin.class, eventAdmin, null);
	}

	@Override
	public void stop(BundleContext bundleContext) {
		if (eventAdmin != null) {
			eventAdminService.unregister();
			eventAdmin.deactivate(bundleContext);
		}
	}
}

Back to the top