Java Reference
In-Depth Information
throws Exception {
StringTokenizer tok = new StringTokenizer(args);
if (tok.countTokens() == 1) {
out.println("Bundle " + args + " has level " +
getStartLevelService().getBundleStartLevel(
getBundle(tok.nextToken())));
} else {
String first = tok.nextToken();
if ("-i".equals(first)) {
getStartLevelService().setInitialBundleStartLevel(
Integer.parseInt(tok.nextToken()));
} else {
getStartLevelService().setBundleStartLevel(
getBundle(tok.nextToken()), Integer.parseInt(first));
}
}
}
...
}
Executing the startlevel command without an argument prints the framework's
active start level B . You implement this with the StartLevel.getStartLevel()
method. If the startlevel command is passed an argument, the new active start level
is parsed from the argument, and you call the StartLevel.setStartLevel() method,
which causes the framework to move to the specified active start level.
Next, the bundlelevel command allows you to set and get the start level of an indi-
vidual bundle. When the command is given only one argument, you use the argument
as the bundle identifier and retrieve and output the associated bundle's start level
with StartLevel.getBundleStartLevel() C . You add a -i switch to the command to
set the initial bundle start level using the StartLevel.setInitialBundle-
StartLevel() method. Finally, you add the ability to change an individual bundle's
start level by using the StartLevel.setBundleStartLevel() method.
When the framework's active start level is changed, the background thread doing
the work fires a FrameworkEvent.STARTLEVEL_CHANGED event to indicate that it's fin-
ished doing the work. Here's a simple session demonstrating what you can do with
these commands.
C
Outputs bundle's
start level
Listing 10.6 Using the startlevel and bundlelevel commands
-> bundles
ID State Name
[ 0] [ ACTIVE] System Bundle
Location: System Bundle
Symbolic-Name: system.bundle
[ 1] [ ACTIVE] Simple Shell
Location: file:org.foo.shell-1.0.jar
Symbolic-Name: org.foo.shell
-> startlevel
1
-> bundlelevel -i 2
Search WWH ::




Custom Search