Oops, I forgot to reply-all:
On Sun, Nov 29, 2009 at 6:21 PM, Peter Royle <howardmoon@screamingcoder.com> wrote:
Hi,
I've got this extension which I'm using to explicitly register all of the managed beans used by Weld Java SE:
public class WeldSEBeanRegistrant implements Extension
{
private final ClassTransformer transformer = new ClassTransformer(new TypeStore());
public void registerWeldSEBeans(@Observes AfterBeanDiscovery event, BeanManagerImpl beanManager)
{
addBean(ShutdownManager.class, beanManager, event);
addBean(ParametersFactory.class, beanManager, event);
}
private void addBean(final Class<?> klass, BeanManagerImpl beanManager, AfterBeanDiscovery event)
{
WeldClass<?> weldClass = WeldClassImpl.of(klass, transformer);
ManagedBean<?> bean = ManagedBean.of(weldClass, beanManager);
event.addBean(bean);
bean.initialize( ___environment___);
}
}
Well, I believe the portable way to do this is:Bean newBean = createBean(beanManager.createInjectionTarget(klass), beanManager.createAnnotatedType(klass));
private void addBean(final Class<?> klass, BeanManagerImpl beanManager, AfterBeanDiscovery event)
{
beanManager.addBean(newBean);
}
where createBean() can either manually create an implementation of Bean that delegates appropriately to the InjectionTarget and AnnotatedType, or you can use BeanImpl from the weld-extensions project (you'd have to throw in an extraneous Reannotated() call, but no biggie).
I think if you do it this way, you won't have to worry about Weld's ManagedBean.initialize().
Haven't tried it though.
-Matt
Cheers,
Pete.
_______________________________________________
weld-dev mailing list
weld-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/weld-dev