Skip to main content
summaryrefslogtreecommitdiffstats
blob: 55ce4864f94037d44c9cc59513fadc1f700fa386 (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
/*******************************************************************************
 * Copyright (c) 2002, 2005 IBM Corporation.
 * 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.wireadmin;

import org.osgi.framework.*;
import org.osgi.service.wireadmin.Producer;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

public class ProducersCustomizer implements ServiceTrackerCustomizer {

	protected BundleContext context;
	protected WireAdmin wireAdmin;

	public ProducersCustomizer(BundleContext context, WireAdmin wireAdmin) {
		this.context = context;
		this.wireAdmin = wireAdmin;
	}

	/**
	 * @see ServiceTrackerCustomizer#addingService(ServiceReference)
	 */
	public Object addingService(ServiceReference reference) {
		Producer service = (Producer) context.getService(reference);
		String pid = (String) reference.getProperty("service.pid"); //$NON-NLS-1$

		try {
			//if a wire contains this producer, the wire notifies it
			if (wireAdmin.getWires(wireAdmin.producerFilter + pid + ")") == null) { //$NON-NLS-1$
				wireAdmin.notifyProducer(service, pid);
			}
		} catch (InvalidSyntaxException ex) {
			ex.printStackTrace();
		}

		return (service);
	}

	/**
	 * @see ServiceTrackerCustomizer#modifiedService(ServiceReference, Object)
	 */
	public void modifiedService(ServiceReference reference, Object service) {
		//do nothing
	}

	/**
	 * @see ServiceTrackerCustomizer#removedService(ServiceReference, Object)
	 */
	public void removedService(ServiceReference reference, Object service) {

		context.ungetService(reference);
	}
}

Back to the top