|
Re: How to get BundleContext of a plugin? [message #906031 is a reply to message #906022] |
Fri, 31 August 2012 13:42 |
|
Why do you want the bundle context?
The bundle context is the context that your bundle runs under, this is something that should NEVER be passed outside of the bundle that owns it. Rarely will I ever even pass it out of the activator. But to get it from the activator, it looks like this:
public class Activator implements BundleActivator {
static private Activator defaultInstance;
private BundleContext bundleContext;
// List any services here
// private ServiceTracker myService;
public Activator() {
defaultInstance = this;
}
public static Activator getDefault() {
return defaultInstance;
}
public void start(BundleContext context) throws Exception {
bundleContext = context;
}
public void stop(BundleContext context) throws Exception {
// Stop your services here
// if (myService != null) {
// myService.close();
// myService = null;
// }
bundleContext = null;
}
// Notice that this method is -> ONLY <- available within the package
BundleContext getBundleContext() {
return bundleContext;
}
// Retrieve and start your service here, something like:
// public MyService getMyService() {
// if (myService == null) {
// if (bundleContext == null)
// return null;
// myService = new ServiceTracker(bundleContext, MyService.class.getName(), null);
// myService.open();
// }
// return (MyService) myService.getService();
// }
}
JD
[Updated on: Fri, 31 August 2012 13:42] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04268 seconds