*/
public static void removeOneDescriptor(ServiceLocator locator, Descriptor descriptor, boolean includeAliasDescriptors) {
if (locator == null || descriptor == null) throw new IllegalArgumentException();
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration config = dcs.createDynamicConfiguration();
if (descriptor.getLocatorId() != null && descriptor.getServiceId() != null) {
Filter destructionFilter = BuilderHelper.createSpecificDescriptorFilter(descriptor);
config.addUnbindFilter(destructionFilter);
if (includeAliasDescriptors == true) {
List<ActiveDescriptor<?>> goingToDie = locator.getDescriptors(destructionFilter);
if (!goingToDie.isEmpty()) {
AliasFilter af = new AliasFilter(goingToDie);
config.addUnbindFilter(af);
}
}
config.commit();
return;
}
// Must use second algorithm, which is not as precise, but which still mainly works
final DescriptorImpl di;
if (descriptor instanceof DescriptorImpl) {
di = (DescriptorImpl) descriptor;
}
else {
di = new DescriptorImpl(descriptor);
}
Filter destructionFilter = new Filter() {
@Override
public boolean matches(Descriptor d) {
return di.equals(d);
}
};
config.addUnbindFilter(destructionFilter);
if (includeAliasDescriptors == true) {
List<ActiveDescriptor<?>> goingToDie = locator.getDescriptors(destructionFilter);
if (!goingToDie.isEmpty()) {
AliasFilter af = new AliasFilter(goingToDie);
config.addUnbindFilter(af);
}
}
config.commit();
}