Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4791bf408f5e72bdfc5769a479f2360843bfabcb (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
package org.eclipse.ecf.provider.internal.remoteservice.java8;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.ecf.core.ContainerTypeDescription;
import org.eclipse.ecf.core.util.AdapterManagerTracker;
import org.eclipse.ecf.core.util.ExtensionRegistryRunnable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {

	private List<IAdapterFactory> rscAdapterFactories;

	private static IAdapterManager getAdapterManager(BundleContext ctx) {
		AdapterManagerTracker t = new AdapterManagerTracker(ctx);
		t.open();
		IAdapterManager am = t.getAdapterManager();
		t.close();
		return am;
	}

	@Override
	public void start(final BundleContext context) throws Exception {
		SafeRunner.run(new ExtensionRegistryRunnable(context) {
			protected void runWithoutRegistry() throws Exception {
				context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(J8GenericContainerInstantiator.JAVA8_SERVER_NAME, new J8GenericContainerInstantiator(), "ECF Java8 Generic Server", true, false), null); //$NON-NLS-1$
				context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(J8GenericContainerInstantiator.JAVA8_CLIENT_NAME, new J8GenericContainerInstantiator(), "ECF Java8 Generic Client", false, false), null); //$NON-NLS-1$
				context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(J8SSLGenericContainerInstantiator.JAVA8_SSL_CLIENT_NAME, new J8SSLGenericContainerInstantiator(), "ECF Java8 SSL Generic Client", false, false), null); //$NON-NLS-1$
				context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(J8SSLGenericContainerInstantiator.JAVA8_SSL_SERVER_NAME, new J8SSLGenericContainerInstantiator(), "ECF Java8 SSL Generic Server", true, false), null); //$NON-NLS-1$
				IAdapterManager am = getAdapterManager(context);
				if (am != null) {
					rscAdapterFactories = new ArrayList<IAdapterFactory>();
					IAdapterFactory af = new J8RemoteServiceContainerAdapterFactory();
					am.registerAdapters(af, J8SSLServerSOContainer.class);
					rscAdapterFactories.add(af);
					af = new J8RemoteServiceContainerAdapterFactory();
					am.registerAdapters(af, J8TCPServerSOContainer.class);
					rscAdapterFactories.add(af);
					af = new J8RemoteServiceContainerAdapterFactory();
					am.registerAdapters(af, J8SSLClientSOContainer.class);
					rscAdapterFactories.add(af);
					af = new J8RemoteServiceContainerAdapterFactory();
					am.registerAdapters(af, J8TCPClientSOContainer.class);
					rscAdapterFactories.add(af);
				}
			}
		});

	}

	@Override
	public void stop(BundleContext context) throws Exception {
		if (rscAdapterFactories != null) {
			IAdapterManager am = getAdapterManager(context);
			if (am != null) {
				for (IAdapterFactory af : rscAdapterFactories)
					am.unregisterAdapters(af);
			}
		}
	}

}

Back to the top