Java Reference
In-Depth Information
be resolved. The Package Admin Service can do a bit more than resolving bundles,
and it's a fairly important part of the framework; it also supports the following opera-
tions, among others:
Determines which bundle owns a particular class —In rare circumstances, you may
need to know which bundle owns a particular class. You can accomplish this
with the getBundle() method, which takes a Class and returns the Bundle to
which it belongs.
Introspects how the framework resolves bundle dependencies —You can use the get-
ExportedPackage() family of methods to find out which bundles are import-
ing a given package, whereas other methods inspect other types of depen-
dencies we won't talk about until chapter 5, such as getRequiredBundles()
and getFragments() .
Refreshes the dependency resolution for bundles —Because the installed set of bundles
can evolve over time, sometimes you need to have the framework recalculate
bundle dependencies. You can do this with the refreshBundles() method.
The most important feature of the Package Admin Service isn't the ability to resolve
bundles or introspect dependencies; it's the ability to refresh bundle dependencies,
which is another tool needed for managing bundles. But before we get into the details
of refreshing bundles, let's finish the discussion of explicitly resolving bundles.
To demonstrate how to use the Package Admin Service to explicitly resolve a bun-
dle, you'll create a new resolve command for the shell to instigate bundle resolution,
as shown next.
Listing 3.19 Bundle resolve command
package org.foo.shell;
import java.io.PrintStream;
import java.util.*;
import org.osgi.framework.Bundle;
import org.osgi.service.packageadmin.PackageAdmin;
public class ResolveCommand extends BasicCommand {
public void exec(String args, PrintStream out, PrintStream err)
throws Exception {
boolean success;
if (args == null) {
success =
getPackageAdminService().resolveBundles(null);
} else {
List<Bundle> bundles = new ArrayList<Bundle>();
StringTokenizer tok = new StringTokenizer(args);
while (tok.hasMoreTokens()) {
bundles.add(getBundle(tok.nextToken()));
}
success = getPackageAdminService().resolveBundles(
bundles.toArray(newBundle[bundles.size()]));
 
Search WWH ::




Custom Search