Updating a Bundle from with the Java Code
I want to be able to intiate a bundle update from either 1)within the bundle itself or 2)from another bundle.
I found the method Bundle.update() which looks as though it should do the trick, but I'm not sure how it initialize it to point the the active instance of existing bundle. How do I do this? Is there a this.Bundle command to point a bundle to itself (can I initiate an update of a bundle from within itself?)? Is there a method I'm missing that retrieves an active bundle object based on the bundle name or ID?
Any help would be much appreciated. If you have a code example.. that would be even better (I bought the "programming OSGI with JES technology book, but it make no references to update bundles other than the fact that the Bundle.update command exists).
Thanks
Michael
[828 byte] By [
Biltz] at [2007-9-26 14:58:41]

When you start your bundle you receive BundleContext object. This BundleContext gives you access to framework itself and other bundles (but security manager may limit your access).
So if you want to get your Bundle it should be something like this:
public void start(BundleContext bc) throws BundleException {
Bundle myBundle = bc.getBundle();
System.out.println("Bundle is installed from: " +
myBundle.getLocation());
Bundle[] bundles = bc.getBundle();
for(int i=0;i<bundles.length;i++) {
System.out.println("Bundle #" +
bundles[i].getBundleId() +
" was installed from " +
bundles[i].getLocation()
);
}
}
The code above will print
1. the location of your bundle
2. IDs and locations of all installed bundles.
This is a simple way for working with bundles. I'm curious why do you want your bundle to update itself. Actually this is not neccesary. OSGi framework is supposed to work in conjunction with Service Agregation (Management) platform - so the service provider, using that platform could update any bundle when client requested so or service provider has bugfix or new release of the bundle.>