Java Reference
In-Depth Information
This sets the Configuration object's bundle location to null , which means it isn't
currently associated with any bundle. You finish initializing the new configuration
by getting any existing properties, parsing the specified properties and merging
them with existing properties, and finally updating the configuration. Because you
handle existing properties, you can use the add-cfg subcommand to create and
modify configurations.
Configuration and location binding
When you create a Configuration object using either getConfiguration() or
createFactoryConfiguration() , it becomes bound to the location of the calling bun-
dle. You can obtain this location via the calling bundle's getLocation() method. Lo-
cation binding is a security feature to ensure that only management bundles can modify
configuration data, and other bundles can only modify their own configuration data.
If the bundle location of a configuration for a given PID is set to null (as in list-
ing 9.5), the Configuration Admin Service binds the first bundle registering a managed
service with the given PID to this configuration. After the bundle location is set, then
configurations for the given PID are only delivered to the bundle with that location.
When this dynamically bound bundle is subsequently uninstalled, the location is set
to null again automatically so it can be bound again later.
You can use the remove-cfg subcommand to remove Configuration objects. The
implementation of this subcommand is much simpler:
private void removeConfiguration(String pid) {
Configuration conf = admin.getConfiguration(pid);
conf.delete();
}
The subcommand accepts a PID that you use to get the Configuration object from
the ConfigurationAdmin service. When you have the Configuration object, you call
delete() on it.
The add-factory-cfg subcommand creates a Configuration object for a man-
aged service factory. It's implemented as follows:
private void addFactoryConfiguration(String args) {
String pid = args.substring(0, args.indexOf(" ")).trim();
Configuration conf = admin.createFactoryConfiguration(pid, null);
createConfiguration(args.substring(pid.length()).trim(), pid, conf);
}
It accepts the PID of the managed service factory and the configuration properties as a
whitespace-delimited list of name-value pairs. It's similar to the add-cfg subcommand,
except that you use ConfigurationAdmin.createFactoryConfiguration() to create
a new Configuration object for the factory. This always creates a new Configuration
object for the factory service (unlike getConfiguration() , which creates one only the
first time for a given PID ).
Search WWH ::




Custom Search