Search in sources :

Example 51 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project Payara by payara.

the class ACCJCDIServiceImpl method createInterceptorInstance.

@Override
public <T> T createInterceptorInstance(Class<T> interceptorClass, EjbDescriptor ejbDesc, JCDIService.JCDIInjectionContext<T> ejbContext, Set<EjbInterceptor> ejbInterceptors) {
    T interceptorInstance = null;
    WeldContainer wc = getWeldContainer();
    if (wc != null) {
        BeanManager beanManager = wc.getBeanManager();
        AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(interceptorClass);
        InjectionTarget<T> target = ((WeldManager) beanManager).getInjectionTargetFactory(annotatedType).createInterceptorInjectionTarget();
        CreationalContext<T> cc = beanManager.createCreationalContext(null);
        interceptorInstance = target.produce(cc);
        target.inject(interceptorInstance, cc);
    }
    return interceptorInstance;
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 52 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project drools by kiegroup.

the class CDIExampleWithInclusion method main.

public static void main(String[] args) {
    Weld w = new Weld();
    WeldContainer wc = w.initialize();
    CDIExampleWithInclusion bean = wc.instance().select(CDIExampleWithInclusion.class).get();
    bean.go(System.out);
    w.shutdown();
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld)

Example 53 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project drools by kiegroup.

the class CDIInstanceExample method main.

public static void main(String[] args) {
    Weld w = new Weld();
    WeldContainer wc = w.initialize();
    CDIInstanceExample bean = wc.instance().select(CDIInstanceExample.class).get();
    bean.go(System.out);
    w.shutdown();
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld)

Example 54 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project drools by kiegroup.

the class CDITest method testCDI.

@Test
public void testCDI() {
    // DROOLS-34
    Weld w = new Weld();
    WeldContainer wc = w.initialize();
    CDIBean bean = wc.instance().select(CDIBean.class).get();
    bean.test(env);
    w.shutdown();
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 55 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project drools by kiegroup.

the class KieProjectCDITest method createMultpleJarAndFileResources.

@Test
public void createMultpleJarAndFileResources() throws IOException, ClassNotFoundException, InterruptedException {
    createKieModule("jar1", true);
    createKieModule("jar2", true);
    createKieModule("jar3", true);
    createKieModule("fol4", false);
    ClassLoader origCl = Thread.currentThread().getContextClassLoader();
    try {
        java.io.File file1 = fileManager.newFile("jar1-1.0-SNAPSHOT.jar");
        java.io.File file2 = fileManager.newFile("jar2-1.0-SNAPSHOT.jar");
        java.io.File file3 = fileManager.newFile("jar3-1.0-SNAPSHOT.jar");
        java.io.File fol4 = fileManager.newFile("fol4-1.0-SNAPSHOT");
        URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { file1.toURI().toURL(), file2.toURI().toURL(), file3.toURI().toURL(), fol4.toURI().toURL() });
        Thread.currentThread().setContextClassLoader(urlClassLoader);
        Enumeration<URL> e = urlClassLoader.getResources(KieModuleModelImpl.KMODULE_JAR_PATH.asString());
        while (e.hasMoreElements()) {
            URL url = e.nextElement();
            System.out.println(url);
        }
        Class cls = Thread.currentThread().getContextClassLoader().loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar1");
        assertNotNull(cls);
        cls = Thread.currentThread().getContextClassLoader().loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar2");
        assertNotNull(cls);
        cls = Thread.currentThread().getContextClassLoader().loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar3");
        assertNotNull(cls);
        Weld weld = CDITestRunner.createWeld(KProjectTestClass.class.getName(), KPTestLiteral.class.getName(), "org.drools.compiler.cdi.test.KProjectTestClassjar1", "org.drools.compiler.cdi.test.KProjectTestClassjar2", "org.drools.compiler.cdi.test.KProjectTestClassjar3", "org.drools.compiler.cdi.test.KProjectTestClassfol4");
        ((KieServicesImpl) KieServices.Factory.get()).nullKieClasspathContainer();
        WeldContainer container = weld.initialize();
        Set<Bean<?>> beans = container.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("jar1"));
        Bean bean = (Bean) beans.toArray()[0];
        KProjectTestClass o1 = (KProjectTestClass) bean.create(container.getBeanManager().createCreationalContext(null));
        assertNotNull(o1);
        testEntry(o1, "jar1");
        beans = container.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("jar2"));
        bean = (Bean) beans.toArray()[0];
        KProjectTestClass o2 = (KProjectTestClass) bean.create(container.getBeanManager().createCreationalContext(null));
        assertNotNull(o2);
        testEntry(o2, "jar2");
        beans = container.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("jar3"));
        bean = (Bean) beans.toArray()[0];
        KProjectTestClass o3 = (KProjectTestClass) bean.create(container.getBeanManager().createCreationalContext(null));
        assertNotNull(o3);
        testEntry(o3, "jar3");
        beans = container.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("fol4"));
        bean = (Bean) beans.toArray()[0];
        KProjectTestClass o4 = (KProjectTestClass) bean.create(container.getBeanManager().createCreationalContext(null));
        assertNotNull(o4);
        testEntry(o4, "fol4");
        weld.shutdown();
    } finally {
        // FIXME Java 7+
        // on Windows, the URLClassLoader will not release all resources,
        // so the attempt to delete the temporary files will fail.
        // an explicit dispose call is needed, but it has not been introduced until Java7+
        // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4950148
        /*
            ((URLClassLoader) Thread.currentThread().getContextClassLoader()).close();
            */
        Thread.currentThread().setContextClassLoader(origCl);
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) URL(java.net.URL) Weld(org.jboss.weld.environment.se.Weld) Bean(javax.enterprise.inject.spi.Bean) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) KieServicesImpl(org.drools.compiler.kie.builder.impl.KieServicesImpl) Test(org.junit.Test)

Aggregations

WeldContainer (org.jboss.weld.environment.se.WeldContainer)115 Weld (org.jboss.weld.environment.se.Weld)100 Test (org.junit.Test)98 CountDownLatch (java.util.concurrent.CountDownLatch)8 Bean (javax.enterprise.inject.spi.Bean)8 BeanManager (javax.enterprise.inject.spi.BeanManager)8 Type (java.lang.reflect.Type)7 URLClassLoader (java.net.URLClassLoader)7 ArrayList (java.util.ArrayList)7 URL (java.net.URL)6 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)6 Fabric8Extension (io.fabric8.cdi.Fabric8Extension)4 ParameterizedType (java.lang.reflect.ParameterizedType)4 List (java.util.List)4 CreationalContext (javax.enterprise.context.spi.CreationalContext)4 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)3 PrintStream (java.io.PrintStream)3 ServiceRegistry (org.jboss.weld.bootstrap.api.ServiceRegistry)3