// Get the instance PID and perform a sanity check to make sure that it
// is valid.
String pid = configuration.getPid();
ValidationHelper.checkPID(pid);
FactoryAssociation association = getFactoryAssociation(factoryPid);
if (!usingAdminMethod) {
// Check to see if the factory PID is bound to a specific
// location that is not the current bundle.
String boundLocation = association.getBundleLocation();
if (boundLocation == null) {
// Binds to first bundle that registers
// ManagedServiceFactory with the same factory PID.
} else if (!callingLocation.equals(boundLocation)
&& !hasConfigurationPermission) {
// The association 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_FACTORYPID +
" '" + factoryPid +
"' which is bound to bundle '" +
boundLocation + "'");
} else {
// A factory has already been registered with the pid that
// matches this pid so bind it to the service immediately.
configuration.bindToLocation(boundLocation);
}
}
// Add the configuration to the set managed by the association.
association.addConfiguration(configuration);
// Create a mapping from pid to configuration.
pid2Configuration.put(pid, configuration);
return configuration;