[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [equinox-dev] finding a BundleContext
- From: "Neil Bartlett" <njbartlett@xxxxxxxxx>
- Date: Sat, 23 Dec 2006 09:45:20 -0000 (GMT)
- Delivered-to: firstname.lastname@example.org
- Importance: Normal
- User-agent: SquirrelMail/1.4.5
Not in OSGi Release 4 (i.e. Equinox 3.2). There is no public API for
getting the BundleContext of another bundle, because the BundleContext is
a "capability" - it is a private interface between a particular bundle and
There are only very few valid reasons for Bundle-A to get the
BundleContext from Bundle-B. Implementing Declarative Services is one of
those reasons, and the stuff Spring does is another. Both at the moment
use reflection-based hacks to do it.
OSGi Release 4.1 (also known as JSR 291, which will be implemented by
Equinox 3.3) introduces a getBundleContext() method on the Bundle
interface in order to support those very few people who need to do this.
But it is still dangerous and should not be used willy-nilly. Can you
explain why you need to do it?
> I'm trying to find the BundleContext for some random bundle I received
> through a BundleEvent.
> I see spring-osgi does it like this:
> Method m = bundle.getClass().getDeclaredMethod("getContext", new
> return (BundleContext) m.invoke(bundle, new Object);
> Is there a better way ?
> equinox-dev mailing list