From: "Lincoln Baxter, III" <lincolnbaxter@gmail.com>
To: Weld Dev List <weld-dev@lists.jboss.org>
Sent: Thu, May 6, 2010 12:16:06 AM
Subject: [weld-dev] Potentially un-spec'd behavior for BeanManager.createAnnotatedType(...)
Hey Guys,
I'm working on an extension that @Observes ProcessAnnotatedType in order to modify the typing information for fields annotated with a specific Annotation.
When I use BeanManager to later construct an instance of AnnotatedType for that modified class, however, I am not supplied with the modified AnnotatedType instance, I am given a brand new instance that does not include my extension's prior modifications.
If this is right, then there needs to be some way to retrieve the previously modified data from the BeanManager, otherwise, the information is effectively lost unless the BeanManager is creating a full contextual instance of the class, not merely providing injection.
So this doesn't seem right to me. Thoughts?
Example code below.
Thanks,
Lincoln
--------------------------------------------------------------------------------------------------------
public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event)
{
AnnotatedTypeBuilder<T> builder = AnnotatedTypeBuilder.newInstance(event.getAnnotatedType());
builder.readAnnotationsFromUnderlyingType();
boolean modifiedType = false;
for (AnnotatedField<?> f : event.getAnnotatedType().getFields())
{
if (f.isAnnotationPresent(InputField.class))
{
builder.overrideFieldType(f.getJavaMember(), Object.class);
modifiedType = true;
}
}
if (modifiedType)
{
AnnotatedType<T> replacement = builder.create();
event.setAnnotatedType(replacement);
}
}
Then later... the AnnotatedType created in the method below not reflect changes
made to the type in the extension above.
public void injectNonContextualInstance(final Object instance)
{
if (instance != null)
{
CreationalContext<Object> creationalContext = manager.createCreationalContext(null);
InjectionTarget<Object> injectionTarget = (InjectionTarget<Object>) manager.createInjectionTarget(beanManager.createAnnotatedType(instance.getClass()));
injectionTarget.inject(instance, creationalContext);
}
}
--
Lincoln Baxter, III
http://ocpsoft.comhttp://scrumshark.com"Keep it Simple"