Search in sources :

Example 51 with BeanManager

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

the class CamelCdiRunner method createTest.

@Override
protected Object createTest() {
    BeanManager manager = context.getBeanManager();
    Set<Bean<?>> beans = manager.getBeans(getTestClass().getJavaClass(), AnyLiteral.INSTANCE);
    Bean<?> bean = beans.iterator().next();
    // TODO: manage lifecycle of @Dependent beans
    return manager.getReference(bean, bean.getBeanClass(), manager.createCreationalContext(bean));
}
Also used : BeanManager(javax.enterprise.inject.spi.BeanManager) Bean(javax.enterprise.inject.spi.Bean)

Example 52 with BeanManager

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

the class FrameworkMethodCdiInjection method evaluate.

@Override
public void evaluate() throws Throwable {
    BeanManager manager = context.getBeanManager();
    Type[] types = method.getMethod().getGenericParameterTypes();
    Object[] parameters = new Object[types.length];
    for (int i = 0; i < types.length; i++) {
        // TODO: use a proper CreationalContext...
        parameters[i] = manager.getInjectableReference(new FrameworkMethodInjectionPoint(method.getMethod(), i, manager), manager.createCreationalContext(null));
    }
    method.invokeExplosively(test, parameters);
}
Also used : Type(java.lang.reflect.Type) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 53 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project wildfly by wildfly.

the class WeldJspExpressionFactoryWrapper method wrap.

@Override
public ExpressionFactory wrap(ExpressionFactory expressionFactory, ServletContext servletContext) {
    BeanManager beanManager = getBeanManager();
    if (beanManager == null) {
        //this should never happen
        return expressionFactory;
    }
    // get JspApplicationContext.
    JspApplicationContext jspAppContext = JspFactory.getDefaultFactory().getJspApplicationContext(servletContext);
    // register compositeELResolver with JSP
    jspAppContext.addELResolver(beanManager.getELResolver());
    jspAppContext.addELContextListener(Reflections.<ELContextListener>newInstance("org.jboss.weld.el.WeldELContextListener", getClass().getClassLoader()));
    return beanManager.wrapExpressionFactory(expressionFactory);
}
Also used : JspApplicationContext(javax.servlet.jsp.JspApplicationContext) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 54 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project wildfly by wildfly.

the class PortableExtensionInExternalModuleTestCase method assertPortableExtensionInjection.

private void assertPortableExtensionInjection(PortableExtensionLookup injectionTarget) {
    Assert.assertNotNull(injectionTarget);
    PortableExtension extension = injectionTarget.getPortableExtension();
    Assert.assertNotNull(extension);
    BeanManager beanManager = extension.getBeanManager();
    Assert.assertNotNull(beanManager);
}
Also used : BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 55 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project wildfly by wildfly.

the class WeldBeanManagerServiceProcessor method bindBeanManager.

private void bindBeanManager(ServiceTarget serviceTarget, ServiceName beanManagerServiceName, ServiceName contextServiceName, final Collection<ServiceName> dependencies, final ServiceRegistry serviceRegistry) {
    final ServiceName beanManagerBindingServiceName = contextServiceName.append("BeanManager");
    dependencies.add(beanManagerBindingServiceName);
    BinderService beanManagerBindingService = new BinderService("BeanManager");
    final BeanManagerManagedReferenceFactory referenceFactory = new BeanManagerManagedReferenceFactory();
    serviceTarget.addService(beanManagerBindingServiceName, beanManagerBindingService).addInjection(beanManagerBindingService.getManagedObjectInjector(), referenceFactory).addDependency(contextServiceName, ServiceBasedNamingStore.class, beanManagerBindingService.getNamingStoreInjector()).addDependency(beanManagerServiceName, BeanManager.class, referenceFactory.beanManager).install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ServiceName(org.jboss.msc.service.ServiceName) BeanManager(javax.enterprise.inject.spi.BeanManager)

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