synchronized (this) {
services = m_services.toArray();
}
for (int i = 0; i < services.length; i++) {
DependencyService ds = (DependencyService) services[i];
if (makeUnavailable) {
ds.dependencyUnavailable(this);
// when the dependency is optional or the dependency is instance bound and the component is instantiated (and the dependency is required)
// then remove is invoked. In other cases the removed has been when the component was unconfigured.
if (!isRequired() || (ds.isInstantiated() && isInstanceBound())) {
invokeRemoved(ds, ref, service);
}
} else {
// Some dependencies are still available: first inject the remaining highest ranked dependency
// in component class field, if the dependency is configured in autoconfig mode.
ds.autoConfig(this);
// Next, invoke "removed" callback. If the dependency is aspect aware, we only invoke removed cb
// if the removed service is the highest ranked service. Note that if the cb is not called, we don't
// propagate the remaining dependency properties.
if (invokeRemoved(ds, ref, service)) {
// Finally, since we have lost one dependency, we have to possibly propagate the highest ranked
// dependency available.
ds.propagate(this);
}
}
}
// unget what we got in addingService (see ServiceTracker 701.4.1)
m_context.ungetService(ref);