Oops, I forgot to reply-all:
On Mon, Nov 30, 2009 at 12:45 AM, Matt Drees <matt.drees(a)gmail.com> wrote:
On Sun, Nov 29, 2009 at 6:21 PM, Peter Royle <
howardmoon(a)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:
private void addBean(final Class<?> klass, BeanManagerImpl beanManager,
AfterBeanDiscovery event)
{
Bean newBean = createBean(beanManager.createInjectionTarget(klass),
beanManager.createAnnotatedType(klass));
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
(Also, beanManager.createInjectionTarget takes should take the created
AnnotatedType, not klass)
>
> Cheers,
>
> Pete.
>
>
>
> _______________________________________________
> weld-dev mailing list
> weld-dev(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/weld-dev
>