});
if (references != null) {
Context initialContext = null;
for (ServiceReference reference : references) {
InitialContextFactory factory = (InitialContextFactory) Utils.getServicePrivileged(context, reference);
try {
initialContext = factory.getInitialContext(environment);
if (initialContext != null) {
provider = new SingleContextProvider(context, reference, initialContext);
break;
}
} finally {
if (provider == null) context.ungetService(reference);
}
}
}
}
} else {
ServiceReference ref = ServiceTrackerCustomizers.ICF_CACHE.find(contextFactoryClass);
if (ref != null) {
Context initialContext = null;
InitialContextFactory factory = (InitialContextFactory) Utils.getServicePrivileged(context, ref);
if (factory != null) {
try {
initialContext = factory.getInitialContext(environment);
provider = new SingleContextProvider(context, ref, initialContext);
} finally {
if (provider == null) context.ungetService(ref);
}
}