Following code has worked [1] for me so far. Might be useful in your usecase

BundleWiring bw = b.adapt(BundleWiring.class)
List<BundleWire> wires = bw.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE)

for(BundleWire w : wires){
    String pkgName =
(String)w.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE)
}

Chetan Mehrotra
[1] https://gist.github.com/chetanmeh/10971530


On Mon, Aug 11, 2014 at 8:02 PM, Christopher BROWN <[email protected]> wrote:
> Hello,
>
> I'm upgrading some code that used PackageAdmin with Felix 3.2.2 to Felix
> 4.4.1 and am trying to find the equivalent code that can (for a given
> class) determine a version number, if a bundle exports that class' package.
>  The code, which works with PackageAdmin, is like this (I've simplified):
>
> // b is a bundle, in a loop:
> // for (Bundle b : bundleContext.getBundles())
> //
> // c is the class of a service interface, in a loop:
> //
> Package p = c.getPackage();
> String packageName = p.getName();
> ExportedPackage[] exports = packageAdmin.getExportedPackages(b);
> if (exports != null)
> {
>
> for (ExportedPackage export : exports)
> {
>
> if (packageName.equals(export.getName())) return export.getVersion();
>
> }
>
> }
>
> I'm a bit stuck finding the equivalent code with the "bundlewiring"
> package, which is apparently the equivalent in OSGi R5.  I can't find
> anything as obvious as "packages", it's all wires and requirements and
> capabilities, which seem promising but I can't see how to just get at the
> packages.
>
> Thanks in advance for advice,
> Christopher

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to