Search in sources :

Example 6 with EnhancedAnnotatedType

use of org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType in project HotswapAgent by HotswapProjects.

the class BeanReloadExecutor method doReloadBean.

@SuppressWarnings({ "rawtypes", "unchecked", "serial" })
private static void doReloadBean(String bdaId, Class<?> beanClass, String oldSignatureByStrategy, BeanReloadStrategy reloadStrategy) {
    BeanManagerImpl beanManager = null;
    BeanManager bm = CDI.current().getBeanManager();
    if (bm instanceof WeldManager) {
        bm = ((WeldManager) bm).unwrap();
    }
    if (bm instanceof BeanManagerImpl) {
        beanManager = (BeanManagerImpl) bm;
    }
    // TODO: check if archive is excluded
    Set<Bean<?>> beans = beanManager.getBeans(beanClass, new AnnotationLiteral<Any>() {
    });
    if (beans != null && !beans.isEmpty()) {
        for (Bean<?> bean : beans) {
            if (bean instanceof AbstractClassBean) {
                EnhancedAnnotatedType eat = createAnnotatedTypeForExistingBeanClass(bdaId, beanClass);
                if (!eat.isAbstract() || !eat.getJavaClass().isInterface()) {
                    // injectionTargetCannotBeCreatedForInterface
                    ((AbstractClassBean) bean).setProducer(beanManager.getLocalInjectionTargetFactory(eat).createInjectionTarget(eat, bean, false));
                    if (isReinjectingContext(bean)) {
                        doReloadAbstractClassBean(beanManager, beanClass, (AbstractClassBean) bean, oldSignatureByStrategy, reloadStrategy);
                        LOGGER.debug("Bean reloaded '{}'", beanClass.getName());
                        continue;
                    }
                }
                LOGGER.info("Bean '{}' redefined", beanClass.getName());
            } else {
                LOGGER.warning("Bean '{}' reloading not supported.", beanClass.getName());
            }
        }
    } else {
        doDefineNewManagedBean(beanManager, bdaId, beanClass);
    }
}
Also used : EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) AbstractClassBean(org.jboss.weld.bean.AbstractClassBean) BeanManager(javax.enterprise.inject.spi.BeanManager) Any(javax.enterprise.inject.Any) WeldManager(org.jboss.weld.manager.api.WeldManager) AbstractClassBean(org.jboss.weld.bean.AbstractClassBean) ManagedBean(org.jboss.weld.bean.ManagedBean) Bean(javax.enterprise.inject.spi.Bean)

Aggregations

EnhancedAnnotatedType (org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType)6 Type (java.lang.reflect.Type)4 HashSet (java.util.HashSet)3 ParameterizedType (java.lang.reflect.ParameterizedType)2 MethodSignature (org.jboss.weld.annotated.enhanced.MethodSignature)2 SlimAnnotatedType (org.jboss.weld.annotated.slim.SlimAnnotatedType)2 ClassTransformer (org.jboss.weld.resources.ClassTransformer)2 WildcardType (java.lang.reflect.WildcardType)1 Dependent (javax.enterprise.context.Dependent)1 Event (javax.enterprise.event.Event)1 Any (javax.enterprise.inject.Any)1 Instance (javax.enterprise.inject.Instance)1 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)1 Bean (javax.enterprise.inject.spi.Bean)1 BeanAttributes (javax.enterprise.inject.spi.BeanAttributes)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 Provider (javax.inject.Provider)1 SlimAnnotatedTypeStore (org.jboss.weld.annotated.slim.SlimAnnotatedTypeStore)1 AbstractClassBean (org.jboss.weld.bean.AbstractClassBean)1 DecoratorImpl (org.jboss.weld.bean.DecoratorImpl)1