Java Reference
In-Depth Information
((filter.length() == 0) ? null : filter));
if (configurations != null) {
for (Configuration configuration : configurations) {
Dictionary properties = configuration.getProperties();
for (Enumeration e = properties.keys(); e.hasMoreElements();) {
Object key = e.nextElement();
out.println(key + "=" + properties.get(key));
}
out.println();
}
}
...
}
You get the ConfigurationAdmin service and use its listConfigurations() method
to get the Configuration objects. You can optionally specify an LDAP filter to limit
which configurations are returned; specifying no filter results in all configurations. In
either case, an array of Configuration objects is returned, which are the holders of
the actual configuration properties. Then you print the configuration properties,
using the getProperties() method of the Configuration object to retrieve them.
You can use the add-cfg subcommand to create new Configuration objects. The
subcommand accepts the PID of the ManagedService and the configuration proper-
ties as a whitespace-delimited list of name-value pairs, where the name and value are
separated by an equals sign. The implementation is as follows:
private void addConfiguration(String args) {
String pid = args.substring(0, args.indexOf(" ")).trim();
Configuration conf = admin.getConfiguration(pid, null);
createConfiguration(args.substring(pid.length()).trim(), pid, conf);
}
To c r e a t e a Configuration object, you call getConfiguration() on Configuration-
Admin . This method creates the Configuration object on the first call and returns the
same object on subsequent calls. You initialize the new configuration with a call to the
private method createConfiguration() , which is defined next.
Listing 9.5 Private method to initialize Configuration objects
private void createConfiguration(
String args, String pid, Configuration conf) throws IOException {
conf.setBundleLocation(null);
Dictionary dict = conf.getProperties();
if (dict == null) {
dict = new Properties();
}
StringTokenizer tok = new StringTokenizer(args, " ");
while (tok.hasMoreTokens()) {
String[] entry = tok.nextToken().split("=");
dict.put(entry[0], entry[1]);
}
conf.update(dict);
}
 
Search WWH ::




Custom Search