use of org.apache.webbeans.config.BeansDeployer in project HotswapAgent by HotswapProjects.
the class BeanClassRefreshAgent method doDefineNewBean.
private static void doDefineNewBean(BeanManagerImpl beanManager, Class<?> beanClass) {
WebBeansContext wbc = beanManager.getWebBeansContext();
AnnotatedElementFactory annotatedElementFactory = wbc.getAnnotatedElementFactory();
// Clear AnnotatedElementFactory caches (is it necessary for definition ?)
annotatedElementFactory.clear();
// Injection resolver cache must be cleared before / after definition
beanManager.getInjectionResolver().clearCaches();
AnnotatedType<?> annotatedType = annotatedElementFactory.newAnnotatedType(beanClass);
BeanAttributesImpl<?> attributes = BeanAttributesBuilder.forContext(wbc).newBeanAttibutes(annotatedType).build();
HashMap<AnnotatedType<?>, ExtendedBeanAttributes<?>> annotatedTypes = new HashMap<>();
BeansDeployer beansDeployer = new BeansDeployer(wbc);
try {
ReflectionHelper.invoke(beansDeployer, BeansDeployer.class, "defineManagedBean", new Class[] { javax.enterprise.inject.spi.AnnotatedType.class, javax.enterprise.inject.spi.BeanAttributes.class, java.util.Map.class }, annotatedType, attributes, annotatedTypes);
} catch (Exception e) {
LOGGER.error("Bean '{}' definition failed", beanClass.getName(), e);
}
}
Aggregations