Search in sources :

Example 1 with WebAppMeta

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);
    }
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) Injector(com.google.inject.Injector) WebAppMeta(org.webpieces.router.api.routing.WebAppMeta) Charset(java.nio.charset.Charset)

Aggregations

Injector (com.google.inject.Injector)1 Charset (java.nio.charset.Charset)1 WebAppMeta (org.webpieces.router.api.routing.WebAppMeta)1 VirtualFile (org.webpieces.util.file.VirtualFile)1