Search in sources :

Example 66 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.

the class OpenEjbContainerControl method getContextControl.

@Override
public synchronized ContextControl getContextControl() {
    if (ctxCtrl == null) {
        BeanManager beanManager = getBeanManager();
        if (beanManager == null) {
            LOG.warning("If the CDI-container was started by the environment, you can't use this helper." + "Instead you can resolve ContextControl manually " + "(e.g. via BeanProvider.getContextualReference(ContextControl.class) ). " + "If the container wasn't started already, you have to use CdiContainer#boot before.");
            return null;
        }
        Set<Bean<?>> beans = beanManager.getBeans(ContextControl.class);
        ctxCtrlBean = (Bean<ContextControl>) beanManager.resolve(beans);
        ctxCtrlCreationalContext = getBeanManager().createCreationalContext(ctxCtrlBean);
        ctxCtrl = (ContextControl) getBeanManager().getReference(ctxCtrlBean, ContextControl.class, ctxCtrlCreationalContext);
    }
    return ctxCtrl;
}
Also used : ContextControl(org.apache.deltaspike.cdise.api.ContextControl) BeanManager(javax.enterprise.inject.spi.BeanManager) Bean(javax.enterprise.inject.spi.Bean)

Example 67 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.

the class JsfSystemEventBroadcaster method processEvent.

@Override
public void processEvent(SystemEvent e) throws AbortProcessingException {
    if (!this.isActivated) {
        return;
    }
    BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
    beanManager.fireEvent(e);
}
Also used : BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 68 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.

the class JndiUtilsTest method testLookup.

/**
     * Tests {@link JndiUtils#lookup(String, Class)} by looking up the {@link BeanManager}
     */
@Test
public void testLookup() {
    BeanManager beanManager = JndiUtils.lookup("java:comp/BeanManager", BeanManager.class);
    assertNotNull("JNDI lookup failed", beanManager);
}
Also used : BeanManager(javax.enterprise.inject.spi.BeanManager) Test(org.junit.Test)

Example 69 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project deltaspike by apache.

the class DeltaSpikeProxyContextualLifecycle method instantiateDelegateInvocationHandler.

protected H instantiateDelegateInvocationHandler() {
    Set<Bean<H>> handlerBeans = BeanProvider.getBeanDefinitions(this.delegateInvocationHandlerClass, false, true);
    if (handlerBeans.size() != 1) {
        StringBuilder beanInfo = new StringBuilder();
        for (Bean<H> bean : handlerBeans) {
            if (beanInfo.length() != 0) {
                beanInfo.append(", ");
            }
            beanInfo.append(bean);
            if (bean instanceof PassivationCapable) {
                beanInfo.append(" bean-id: ").append(((PassivationCapable) bean).getId());
            }
        }
        throw new IllegalStateException(handlerBeans.size() + " beans found for " + this.delegateInvocationHandlerClass + " found beans: " + beanInfo.toString());
    }
    Bean<H> handlerBean = handlerBeans.iterator().next();
    BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
    CreationalContext<?> creationalContext = beanManager.createCreationalContext(handlerBean);
    H handlerInstance = (H) beanManager.getReference(handlerBean, this.delegateInvocationHandlerClass, creationalContext);
    if (handlerBean.getScope().equals(Dependent.class)) {
        this.creationalContextOfDependentHandler = creationalContext;
    }
    return handlerInstance;
}
Also used : PassivationCapable(javax.enterprise.inject.spi.PassivationCapable) BeanManager(javax.enterprise.inject.spi.BeanManager) Bean(javax.enterprise.inject.spi.Bean)

Example 70 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project aries by apache.

the class CdiBeanTests method testBundleContextInjection.

public void testBundleContextInjection() throws Exception {
    BeanManager beanManager = cdiContainer.getBeanManager();
    assertNotNull(beanManager);
    @SuppressWarnings("serial") Set<Bean<?>> beans = beanManager.getBeans(Object.class, new AnnotationLiteral<BundleContextBeanQualifier>() {
    });
    Bean<?> bean = beanManager.resolve(beans);
    CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
    Object bcb = beanManager.getReference(bean, Object.class, ctx);
    assertNotNull(bcb);
    @SuppressWarnings("unchecked") BeanService<BundleContext> bti = (BeanService<BundleContext>) bcb;
    assertNotNull(bti.get());
    assertTrue(bti.get() instanceof BundleContext);
}
Also used : BundleContextBeanQualifier(org.apache.aries.cdi.test.interfaces.BundleContextBeanQualifier) BeanManager(javax.enterprise.inject.spi.BeanManager) BeanService(org.apache.aries.cdi.test.interfaces.BeanService) Bean(javax.enterprise.inject.spi.Bean) BundleContext(org.osgi.framework.BundleContext)

Aggregations

BeanManager (javax.enterprise.inject.spi.BeanManager)83 Bean (javax.enterprise.inject.spi.Bean)34 Test (org.junit.Test)16 NamingException (javax.naming.NamingException)7 Annotation (java.lang.annotation.Annotation)6 ArrayList (java.util.ArrayList)6 InjectionTarget (javax.enterprise.inject.spi.InjectionTarget)6 CdiContainer (org.apache.deltaspike.cdise.api.CdiContainer)6 CreationalContext (javax.enterprise.context.spi.CreationalContext)5 InitialContext (javax.naming.InitialContext)5 ValidatorFactory (javax.validation.ValidatorFactory)5 CarRepair (org.apache.deltaspike.cdise.tck.beans.CarRepair)5 HashMap (java.util.HashMap)4 Set (java.util.Set)4 TransactionManager (javax.transaction.TransactionManager)4 ContextControl (org.apache.deltaspike.cdise.api.ContextControl)4 Type (java.lang.reflect.Type)3 Map (java.util.Map)3 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)3 Validator (javax.validation.Validator)3