[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] Get Bundle or BundleContext without Activator?



equinox-dev-bounces@xxxxxxxxxxx wrote on 2007-05-22 17:24:57:

> Thanks for response.
>
> Will Bundle/BundleContext be created if no activator is
> defined/called?


Yes. Every bundle has a Bundle object. Every bundle that is started has a BundleContext.

> Why there isn't a static method like
> BundleContext.getBundleContext()?
>


How would the implementation of BundleContext.getBundleContext() know which BundleContext to return? Since a bundle can import packages from other bundles, the information on the call stack cannot be used to determine the "calling bundle". So there is no such static way to obtain the bundle context. What some bundles do is implement a BundleActivator class which stores the injected BundleContext into a static field which can then be examined by other classes in the bundle. Eclipse's Plugin class does this. I don't think it is a best practice, but it does generally do the job.

> Regards,
> Ali
>

--

BJ Hargrave
Senior Technical Staff Member, IBM
OSGi Fellow and CTO of the
OSGi Alliance
hargrave@xxxxxxxxxx

office: +1 386 848 1781
mobile: +1 386 848 3788