Search in sources :

Example 6 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 7 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 8 with WeldContainer

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

the class ACCJCDIServiceImpl method createManagedObject.

@Override
public <T> JCDIInjectionContext<T> createManagedObject(Class<T> managedClass, BundleDescriptor bundle, boolean invokePostConstruct) {
    JCDIInjectionContext<T> context = null;
    T managedObject = null;
    try {
        managedObject = createEEManagedObject(bundle.getManagedBeanByBeanClass(managedClass.getName()));
    } catch (Exception e) {
        e.printStackTrace();
    }
    WeldContainer wc = getWeldContainer();
    if (wc != null) {
        BeanManager beanManager = wc.getBeanManager();
        AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(managedClass);
        InjectionTarget<T> target = beanManager.createInjectionTarget(annotatedType);
        CreationalContext<T> cc = beanManager.createCreationalContext(null);
        target.inject(managedObject, cc);
        if (invokePostConstruct) {
            target.postConstruct(managedObject);
        }
        context = new JCDIInjectionContextImpl<>(target, cc, managedObject);
    }
    return context;
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) BeanManager(javax.enterprise.inject.spi.BeanManager) NamingException(javax.naming.NamingException)

Example 9 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project camel by apache.

the class CamelCdiDeployment method apply.

@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            WeldContainer container = weld.initialize();
            context.setBeanManager(container.getBeanManager());
            try {
                base.evaluate();
            } finally {
                container.shutdown();
                context.unsetBeanManager();
            }
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) WeldContainer(org.jboss.weld.environment.se.WeldContainer)

Example 10 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project indy by Commonjava.

the class DefaultIndyConfigFactoryTest method weldInjection_IterateIndyConfigurators.

@Test
public void weldInjection_IterateIndyConfigurators() {
    Weld weld = new Weld();
    WeldContainer container = weld.initialize();
    List<String> sections = new ArrayList<>();
    container.instance().select(IndyConfigInfo.class).iterator().forEachRemaining((instance) -> {
        String section = ConfigUtils.getSectionName(instance);
        System.out.printf("Got instance: %s with section: %s\n", instance, section);
        sections.add(section);
    });
    System.out.println(sections);
    assertThat(sections.contains(ConfigurationSectionListener.DEFAULT_SECTION), equalTo(true));
    assertThat(sections.contains("flatfiles"), equalTo(true));
    assertThat(sections.contains("ui"), equalTo(true));
    assertThat(sections.contains("storage-default"), equalTo(true));
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) ArrayList(java.util.ArrayList) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Aggregations

WeldContainer (org.jboss.weld.environment.se.WeldContainer)16 Weld (org.jboss.weld.environment.se.Weld)12 Test (org.junit.Test)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintStream (java.io.PrintStream)3 BeanManager (javax.enterprise.inject.spi.BeanManager)3 File (java.io.File)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Bean (javax.enterprise.inject.spi.Bean)1 NamingException (javax.naming.NamingException)1 KieServicesImpl (org.drools.compiler.kie.builder.impl.KieServicesImpl)1 Statement (org.junit.runners.model.Statement)1