<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" &lt;lincolnbaxter@gmail.com&gt;<br><b><span style="font-weight: bold;">To:</span></b> Weld Dev List &lt;weld-dev@lists.jboss.org&gt;<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>&nbsp;&nbsp; public &lt;T&gt; void processAnnotatedType(@Observes final ProcessAnnotatedType&lt;T&gt; event)<br>
&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AnnotatedTypeBuilder&lt;T&gt; builder = AnnotatedTypeBuilder.newInstance(event.getAnnotatedType());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; builder.readAnnotationsFromUnderlyingType();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boolean modifiedType = false;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (AnnotatedField&lt;?&gt; f : event.getAnnotatedType().getFields())<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (f.isAnnotationPresent(InputField.class))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; builder.overrideFieldType(f.getJavaMember(), Object.class);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; modifiedType = true;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (modifiedType)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AnnotatedType&lt;T&gt; replacement = builder.create();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; event.setAnnotatedType(replacement);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; }<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>&nbsp;&nbsp; public void injectNonContextualInstance(final Object instance)<br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (instance != null)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CreationalContext&lt;Object&gt; creationalContext = manager.createCreationalContext(null);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InjectionTarget&lt;Object&gt; injectionTarget = (InjectionTarget&lt;Object&gt;) manager.createInjectionTarget(beanManager.createAnnotatedType(instance.getClass()));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; injectionTarget.inject(instance, creationalContext);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; }<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>