void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event, final BeanManager beanManager) { // We are in provided mode if (this.context == null) { // This is not really clean : it couples the inject to the application notion // but avoiding that would mean to introduce more complex stuff and so // it's fine for the moment try { final ClassLoader cl = Thread.currentThread().getContextClassLoader(); InputStream in = cl.getResourceAsStream("juzu/config.json"); String serializedConfig = Tools.read(in); JSON config = (JSON) JSON.parse(serializedConfig); JSON applications = config.getJSON("application"); if (applications.names().size() != 1) { throw new RuntimeException( "Was expecting application size to be 1 instead of " + applications); } String packageFQN = applications.names().iterator().next(); ApplicationDescriptor descriptor = ApplicationDescriptor.create(cl, packageFQN); // For now we don't resolve anything... ResourceResolver resourceResolver = new ResourceResolver() { public URL resolve(String uri) { return null; } }; // ProvidedCDIInjector injector = new ProvidedCDIInjector(cl, beanManager, descriptor, resourceResolver); // We start the application // it should: // - instantiate the plugins // - bind the beans from the plugins in the container // we rely on the lazy nature of the beans for not really starting... Application application = injector.getApplication(); application.start(); // At this point the application is not really started // we must go through the other CDI phases for effectively registering // the beans in the container this.context = (CDIContext) application.getInjectionContext(); } catch (Exception e) { throw new UnsupportedOperationException(e); } } }
public Application() throws Exception { this.descriptor = ApplicationDescriptor.create(getClass()); }