Java Reference
In-Depth Information
public Configuration getConfiguration(String pid) throws IOException;
public Configuration[] listConfigurations(String filter) throws
IOException, InvalidSyntaxException;
}
Configuration objects are represented by the following interface:
public interface Configuration{
public String getPid();
public Dictionary getProperties();
public void update(Dictionary properties) throws IOException;
public void delete() throws IOException;
public String getFactoryPid();
public void update() throws IOException;
public void setBundleLocation(String location);
public String getBundleLocation();
}
To i l l u s t r a t e h o w t h e s e a l l f i t t o g e t h e r, y o u c o n t i n u e t o i m p r o v e t h e s h e l l e x a m p l e i n
the following listing by creating a new command to manage configurations.
Listing 9.3 ConfigurationAdmin service shell command
public class ConfigAdminCommand extends BasicCommand {
public void exec(String args, PrintStream out, PrintStream err)
throws Exception {
args=args.trim();
if (args.startsWith("list")) {
listConfigurations(args.substring("list".length()).trim(),
out);
} else if (args.startsWith("add-cfg")) {
addConfiguration(args.substring("add-cfg".length()).trim());
} else if (args.startsWith("remove-cfg")) {
removeConfiguration(args.substring(
"remove-cfg".length()).trim());
} else if (args.startsWith("add-factory-cfg")) {
addFactoryConfiguration(args.substring("add-factory-
cfg".length()).trim());
} else if (args.startsWith("remove-factory-cfg")) {
removeFactoryConfiguration(args.substring(
"remove-factory-cfg".length()).trim());
}
}
In this example, you create a cm command that accepts five different subcommands:
list , add-cfg , remove-cfg , add-factory-cfg , and remove-factory-cfg . The code is
largely responsible for delegating to private methods to perform the functionality of
the subcommands.
The following code shows how cm list lists available configurations.
Listing 9.4 Implementing the cm list subcommand
private void listConfigurations(String filter, PrintStream out)
throws IOException, InvalidSyntaxException {
Configuration[] configurations = admin().listConfigurations(
 
Search WWH ::




Custom Search