<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial,helvetica,sans-serif;font-size:10pt">Hello<br><br>In OpenWebBeans, if InjectionTarget is set for non-contextual types, whenever we inject into non-contextual instances, we use this setting injection target instance. Otherwise, we use normal InjectionTarget that created by BeanManager<br><div><br>--Gurkan<br></div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> "Lincoln Baxter, III" <lincolnbaxter@gmail.com><br><b><span style="font-weight: bold;">To:</span></b> Weld Dev List <weld-dev@lists.jboss.org><br><b><span style="font-weight: bold;">Sent:</span></b> Thu, May 6, 2010 12:16:06 AM<br><b><span style="font-weight:
bold;">Subject:</span></b> [weld-dev] Potentially un-spec'd behavior for BeanManager.createAnnotatedType(...)<br></font><br><meta http-equiv="x-dns-prefetch-control" content="off">Hey Guys,<br><br>I'm working on an extension that @Observes ProcessAnnotatedType in order to modify the typing information for fields annotated with a specific Annotation.<br><br>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.<br>
<br>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.<br>
<br>So this doesn't seem right to me. Thoughts?<br><br>Example code below.<br>Thanks,<br>Lincoln<br><br>--------------------------------------------------------------------------------------------------------<br> public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event)<br>
{<br> AnnotatedTypeBuilder<T> builder = AnnotatedTypeBuilder.newInstance(event.getAnnotatedType());<br> builder.readAnnotationsFromUnderlyingType();<br> boolean modifiedType = false;<br><br> for (AnnotatedField<?> f : event.getAnnotatedType().getFields())<br>
{<br> if (f.isAnnotationPresent(InputField.class))<br> {<br> builder.overrideFieldType(f.getJavaMember(), Object.class);<br> modifiedType = true;<br> }<br> }<br><br>
if (modifiedType)<br> {<br> AnnotatedType<T> replacement = builder.create();<br> event.setAnnotatedType(replacement);<br> }<br> }<br><br><br>Then later... the AnnotatedType created in the method below not reflect changes
made to the type in the extension above.<br><br> public void injectNonContextualInstance(final Object instance)<br> {<br> if (instance != null)<br> {<br> CreationalContext<Object> creationalContext = manager.createCreationalContext(null);<br>
InjectionTarget<Object> injectionTarget = (InjectionTarget<Object>) manager.createInjectionTarget(beanManager.createAnnotatedType(instance.getClass()));<br> injectionTarget.inject(instance, creationalContext);<br>
}<br> }<br><br><br clear="all"><br>-- <br>Lincoln Baxter, III<br><a rel="nofollow" target="_blank" href="http://ocpsoft.com">http://ocpsoft.com</a><br><a rel="nofollow" target="_blank" href="http://scrumshark.com">http://scrumshark.com</a><br>"Keep it Simple"<br>
<meta http-equiv="x-dns-prefetch-control" content="on"></div></div>
</div><br></body></html>