Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1892e863144d30d1191583776f081f5ece7b3f3a (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
/*****************************************************************************
 * Copyright (c) 2016 Christian W. Damus 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:
 *   Christian W. Damus - Initial API and implementation
 *   
 *****************************************************************************/

package org.eclipse.papyrus.infra.emf.spi.resolver;

import org.eclipse.papyrus.infra.tools.util.CompositeServiceTracker;
import org.osgi.framework.BundleContext;

/**
 * A resolver that delegates to registered OSGi services in a <em>Chain of Command</em>
 * pattern to provide the first available service result.
 * 
 * @since 2.0
 */
public class EObjectResolverService implements IEObjectResolver {
	private final CompositeServiceTracker<IEObjectResolver> tracker;

	/**
	 * Initializes me with the bundle context in which I track resolver services.
	 * 
	 * @param context
	 *            the bundle context
	 */
	public EObjectResolverService(BundleContext context) {
		super();

		tracker = new CompositeServiceTracker<>(context,
				IEObjectResolver.class,
				IEObjectResolver.identity(),
				IEObjectResolver::compose);
		tracker.open();
	}

	public void dispose() {
		tracker.close();
	}

	@Override
	public Object resolve(Object object) {
		return tracker.getService().resolve(object);
	}
}

Back to the top