System.out.println("Beginning creation of implicit objects...");
}
// TODO RPr: I enabled the "setClassLoader" here
Factory.setClassLoader(ctx.getContextClassLoader());
final ApplicationEx app = ctx.getApplicationEx();
final Map<Class<?>, List<?>> cache = new HashMap<Class<?>, List<?>>();
Factory.setServiceLocator(new Factory.AppServiceLocator() {
@SuppressWarnings("rawtypes")
@Override
public <T> List<T> findApplicationServices(final Class<T> serviceClazz) {
List<T> ret = (List<T>) cache.get(serviceClazz);
if (ret == null) {
ret = AccessController.doPrivileged(new PrivilegedAction<List<T>>() {
@Override
public List<T> run() {
return app.findServices(serviceClazz.getName());
}
});
if (Comparable.class.isAssignableFrom(serviceClazz)) {
Collections.sort((List<? extends Comparable>) ret);
}
cache.put(serviceClazz, ret);
}
return ret;
}
});
FunctionFactory.setServiceLocator(new FunctionFactory.AppServiceLocator() {
@SuppressWarnings("rawtypes")
@Override
public <T> List<T> findApplicationServices(final Class<T> serviceClazz) {
List<T> ret = (List<T>) cache.get(serviceClazz);
if (ret == null) {
ret = AccessController.doPrivileged(new PrivilegedAction<List<T>>() {
@Override
public List<T> run() {
return app.findServices(serviceClazz.getName());
}
});
if (Comparable.class.isAssignableFrom(serviceClazz)) {
Collections.sort((List<? extends Comparable>) ret);
}