Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I retrieve Bundle given its symbolic name?

Tags:

java

osgi

Documentation for BundleContext says it lets you

  • Get the list of bundles installed in the Framework.
  • Get the Bundle object for a bundle.

However, there is no getBundle(String symbolicName) method, only getBundle(long id) (and the unsuitable getBundle(String location). Of course, it's possible to call getBundles() and iterate over the returned array, but is there a better way?

like image 252
Alexey Romanov Avatar asked Nov 02 '11 09:11

Alexey Romanov


2 Answers

I think iterating through the array of getBundles() is fine. Maybe it shouldn't exist at all because the symbolic name does not identify uniquely a bundle. Maybe getBundles(String symbolicName)...

From OSGi Service Platform Core Specification, Release 4, Version 4.3:

3.6.2 Bundle-SymbolicName

The Bundle-SymbolicName manifest header is a mandatory header. The bundle symbolic name and bundle version identify a unique bundle. This does not always imply that this pair is unique in a framework, in certain cases the same bundle can be installed multiple times in the same framework, see Bundle Identifiers on page 89.

The referred page 89 (which actually is page 95):

4.4.1 Bundle Identifiers

[...]

Though the pair is unique, it is possible to install the same bundle multiple times if the org.osgi.framework.bsnversion framework launching property is set to multiple.

like image 165
palacsint Avatar answered Oct 12 '22 23:10

palacsint


I have never seen an example on how to do that. But there is the PackageAdmin service, maybe you want to have a look at this, but it seems to be deprecated. The replacement package org.osgi.framework.wiring does not seem to provide such a method.

And to clarify: What is your purpose of having an instance of a Bundle?

like image 39
thobens Avatar answered Oct 12 '22 23:10

thobens