blob: d76fdcd41011e4f5e2bc0ef921fdff9b67136181 (
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*******************************************************************************
* Copyright (c) 2008 Jan S. Rellermeyer, 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:
* Jan S. Rellermeyer - initial API and implementation
******************************************************************************/
package org.eclipse.ecf.internal.provider.r_osgi;
import ch.ethz.iks.r_osgi.RemoteOSGiService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.util.tracker.ServiceTracker;
/**
* The activator class controls the plug-in life cycle.
*
* @author Jan S. Rellermeyer, ETH Zurich
*/
public final class Activator implements BundleActivator {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.ecf.provider.r_osgi"; //$NON-NLS-1$
// The shared instance
static Activator plugin;
// The bundle context
private BundleContext context;
// The service tracker for the R-OSGi remote service
private ServiceTracker r_osgi_tracker;
// The package admin service tracker
private ServiceTracker pkg_admin_tracker;
/**
* The constructor.
*/
public Activator() {
plugin = this;
}
/**
* Called when the OSGi framework starts the bundle.
*
* @param bc
* the bundle context.
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(final BundleContext bc) throws Exception {
this.context = bc;
r_osgi_tracker = new ServiceTracker(context, RemoteOSGiService.class.getName(), null);
r_osgi_tracker.open();
pkg_admin_tracker = new ServiceTracker(context, PackageAdmin.class.getName(), null);
pkg_admin_tracker.open();
}
/**
* Called when the OSGi framework stops the bundle.
*
* @param bc
* the bundle context.
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(final BundleContext bc) throws Exception {
r_osgi_tracker.close();
r_osgi_tracker = null;
pkg_admin_tracker.close();
pkg_admin_tracker = null;
this.context = null;
plugin = null;
}
/**
* get the bundle context.
*
* @return the bundle context.
*/
public BundleContext getContext() {
return context;
}
/**
* get the R-OSGi service instance.
*
* @return the R-OSGi service instance or null, if there is none.
*/
public RemoteOSGiService getRemoteOSGiService() {
if (r_osgi_tracker == null) {
return null;
}
return (RemoteOSGiService) r_osgi_tracker.getService();
}
/**
* Returns the shared instance.
*
* @return the shared instance
*/
public static synchronized Activator getDefault() {
if (plugin == null) {
plugin = new Activator();
}
return plugin;
}
/**
* get the PackageAdmin service instance.
*
* @return the PackageAdmin service instance or null, if there is none.
*/
public PackageAdmin getPackageAdmin() {
if (pkg_admin_tracker == null) {
return null;
}
return (PackageAdmin) pkg_admin_tracker.getService();
}
}
|