Search in sources :

Example 11 with InjectionTarget

use of javax.enterprise.inject.spi.InjectionTarget in project HotswapAgent by HotswapProjects.

the class BeanClassRefreshAgent method createAnnotatedTypeForExistingBeanClass.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static void createAnnotatedTypeForExistingBeanClass(BeanManagerImpl beanManager, Class<?> beanClass, InjectionTargetBean bean) {
    WebBeansContext wbc = beanManager.getWebBeansContext();
    AnnotatedElementFactory annotatedElementFactory = wbc.getAnnotatedElementFactory();
    // Clear AnnotatedElementFactory caches
    annotatedElementFactory.clear();
    AnnotatedType annotatedType = annotatedElementFactory.newAnnotatedType(beanClass);
    ReflectionHelper.set(bean, InjectionTargetBean.class, "annotatedType", annotatedType);
    // Updated members that were set by bean attributes
    BeanAttributesImpl attributes = BeanAttributesBuilder.forContext(wbc).newBeanAttibutes(annotatedType).build();
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "types", attributes.getTypes());
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "qualifiers", attributes.getQualifiers());
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "scope", attributes.getScope());
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "name", attributes.getName());
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "stereotypes", attributes.getStereotypes());
    ReflectionHelper.set(bean, BeanAttributesImpl.class, "alternative", attributes.isAlternative());
    InjectionTargetFactory factory = new InjectionTargetFactoryImpl(annotatedType, bean.getWebBeansContext());
    InjectionTarget injectionTarget = factory.createInjectionTarget(bean);
    ReflectionHelper.set(bean, InjectionTargetBean.class, "injectionTarget", injectionTarget);
    LOGGER.debug("New annotated type created for bean '{}'", beanClass.getName());
}
Also used : AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeanAttributesImpl(org.apache.webbeans.component.BeanAttributesImpl) InjectionTargetFactory(javax.enterprise.inject.spi.InjectionTargetFactory) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget) AnnotatedElementFactory(org.apache.webbeans.portable.AnnotatedElementFactory) InjectionTargetFactoryImpl(org.apache.webbeans.container.InjectionTargetFactoryImpl)

Example 12 with InjectionTarget

use of javax.enterprise.inject.spi.InjectionTarget in project cucumber-jvm by cucumber.

the class Cdi2Factory method addBean.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void addBean(AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager, Class<?> clazz) {
    AnnotatedType clazzAnnotatedType = beanManager.createAnnotatedType(clazz);
    // @formatter:off
    InjectionTarget injectionTarget = beanManager.getInjectionTargetFactory(clazzAnnotatedType).createInjectionTarget(null);
    // @formatter:on
    // @formatter:off
    afterBeanDiscovery.addBean().read(clazzAnnotatedType).createWith(callback -> {
        CreationalContext c = (CreationalContext) callback;
        Object instance = injectionTarget.produce(c);
        injectionTarget.inject(instance, c);
        injectionTarget.postConstruct(instance);
        return instance;
    });
// @formatter:on
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget)

Aggregations

InjectionTarget (javax.enterprise.inject.spi.InjectionTarget)12 BeanManager (javax.enterprise.inject.spi.BeanManager)6 CreationalContext (javax.enterprise.context.spi.CreationalContext)4 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Field (java.lang.reflect.Field)1 Member (java.lang.reflect.Member)1 Method (java.lang.reflect.Method)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 InjectionTargetFactory (javax.enterprise.inject.spi.InjectionTargetFactory)1 ProcessInjectionTarget (javax.enterprise.inject.spi.ProcessInjectionTarget)1 BeanAttributesImpl (org.apache.webbeans.component.BeanAttributesImpl)1 WebBeansContext (org.apache.webbeans.config.WebBeansContext)1 InjectionTargetFactoryImpl (org.apache.webbeans.container.InjectionTargetFactoryImpl)1 AnnotatedElementFactory (org.apache.webbeans.portable.AnnotatedElementFactory)1 WebBeansConfigurationListener (org.apache.webbeans.servlet.WebBeansConfigurationListener)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1 ComponentSupport (org.jboss.as.weld.spi.ComponentSupport)1