"configuration for other bundles");
}
// Get the association for the PID. This may use an existing
// association, or create a new one.
ServiceAssociation association = getServiceAssociation(pid);
// Make sure that the association has a configuration associated with
// it.
InternalConfiguration configuration;
configuration = association.getConfiguration();
if (configuration == null) {
configuration = store.createConfiguration(pid, bundleLocation);
association.setConfiguration(configuration);
pid2Configuration.put(pid, configuration);
}
String boundLocation =
configuration.getBundleLocation();
if (boundLocation == null) {
if (usingAdminMethod) {
// The specification specifically states that the admin
// method must not update the bundle location of an
// already existing configuration (if this configuration
// was newly created in this method then it would already
// have been bound). The presumption is that the caller
// will use the accessors on the configuration itself to
// manage the bundle location.
} else {
// The non admin method must bind the configuration to
// the location of the calling bundle.
configuration.setSpecifiedLocation(bundleLocation);
}
} else if (!boundLocation.equals(callingLocation)) {
if (!hasConfigurationPermission) {
// The configuration has been bound to another location but
// the caller does not have permission to modify the
// configuration of other bundles so this must fail.
throw new SecurityException(
"Bundle '" + callingLocation +
"' does not have permission to create " +
"configuration for " +
FrameworkConstants.SERVICE_PID +
" '" + pid +
"' which is bound to bundle '" +
boundLocation + "'");
}
}
// If the association has already been bound to a specific location
// then try and bind the configuration to the same location.
String serviceLocation = association.getBundleLocation();
if (serviceLocation != null) {
configuration.bindToLocation(serviceLocation);
}
// Return the configuration.