use of org.webpieces.router.api.routing.WebAppMeta in project webpieces by deanhiller.
the class RouteLoader method loadImpl.
private WebAppMeta loadImpl(ClassForName loader, Consumer<Injector> startupFunction) throws IOException {
log.info("loading the master " + WebAppMeta.class.getSimpleName() + " class file");
VirtualFile fileWithMetaClassName = config.getMetaFile();
String moduleName;
Charset fileEncoding = config.getFileEncoding();
String contents = fileWithMetaClassName.contentAsString(fileEncoding);
moduleName = contents.trim();
log.info(WebAppMeta.class.getSimpleName() + " class to load=" + moduleName);
Class<?> clazz = loader.clazzForName(moduleName);
//In development mode, the ClassLoader here will be the CompilingClassLoader so stuff it into the thread context
//just in case plugins will need it(most won't, hibernate will). In production, this is really a no-op and does
//nothing. I don't like dev code existing in production :( so perhaps we should abstract this out at some
//point perhaps with a lambda of a lambda function
ClassLoader original = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(clazz.getClassLoader());
Object obj = newInstance(clazz);
if (!(obj instanceof WebAppMeta))
throw new IllegalArgumentException("name=" + moduleName + " does not implement " + WebAppMeta.class.getSimpleName());
log.info(WebAppMeta.class.getSimpleName() + " loaded. initializing next");
WebAppMeta routerModule = (WebAppMeta) obj;
routerModule.initialize(config.getWebAppMetaProperties());
log.info(WebAppMeta.class.getSimpleName() + " initialized.");
Injector injector = createInjector(routerModule);
pluginSetup.wireInPluginPoints(injector, startupFunction);
loadAllRoutes(routerModule, injector);
return routerModule;
} finally {
Thread.currentThread().setContextClassLoader(original);
}
}
Aggregations