Hi,
>From the original question I would say "No, there is no way for a host bundle
>to receive a notification when a fragment attaches". Fragments only attach at
>resolution time, therefore the host bundle can never see the attachment
>because it is, by definition, not resolved yet!
What you can do is the following at startup (On OSGi 4.3):
public void start(BundleContext ctx) throws BundleException {
Bundle hostBundle = ctx.getBundle();
BundleWiring wiring = hostBundle.adapt(BundleWiring.class);
Collection<BundleWire> fragmentWires = wiring.
getProvidedWires(BundleRevision.HOST_NAMESPACE);
for(BundleWire wire : fragmentWires) {
Bundle fragment = wire.getRequirerWiring().getBundle();
//Do some stuff with this fragment
}
}
This will allow you to find out which fragments were wired to your bundle when
it resolved.
Regards,
Tim
From: [email protected]
Date: Wed, 7 Sep 2011 08:54:57 +0100
Subject: Re: OSGi (Blueprint) fragment and host bundle notification
To: [email protected]
Hi Matt, A web search for "osgi bundle tracker fragment" yields this article:
http://java.dzone.com/articles/osgi-junit-test-extender-using. This uses a
BundleTrackerCustomizer,
bundleTracker = new BundleTracker(context, Bundle.RESOLVED, testExtender);
bundleTracker.open();
Which then tests to see if it's been given a fragment:
String fragment =
bundle.getHeaders().get(org.osgi.framework.Constants.FRAGMENT_HOST) + "";
> Thanks in advance!
You're welcome!
Regards, Mark
On 6 September 2011 23:14, Matt Madhavan <[email protected]> wrote:
Hello,I would like to know when a new BluePrint fragment attaches it self to a
host bundle will the host bundle be notified? I would like to do some work
inside of the host bundle anytime a fragment attaches itself to a host.
Any ideas?
Thanks in advance!Matt Madhavan