<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jan 28, 2016 at 4:43 PM, Martin Kouba <span dir="ltr">&lt;<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">By the way, Tomas tested the original way using BeanManager.getInjectableReference() and it works fine. For the purpose of this use case a custom IP with InjectionPoint as a requested type, @Default as a qualifier and &quot;this&quot; as a declaring bean should be enough (no need for InjectionPointGenerator).<br></blockquote><div><br></div><div>Okay, so you mean this code:</div><div><br></div><div><div>InjectionPoint injectionPoint = (InjectionPoint) beanManager.getInjectableReference(</div><div>     resolve(beanManager, InjectionPointGenerator.class).getInjectionPoints().iterator().next(),</div><div>     creationalContext</div></div><div>);</div><div><br></div><div>To what does that has to be changed exactly?<br></div><div><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
We&#39;re going to add a test in the Weld test suite.</blockquote><div><br></div><div>Great! That test will be for this method?</div><div><br></div><div><span style="font-size:12.8px">Bean&lt;InjectionPoint&gt; bean = (Bean&lt;InjectionPoint&gt;) manager.resolve(manager.getBea</span><span style="font-size:12.8px">ns(InjectionPoint.class));</span><br style="font-size:12.8px"><span style="font-size:12.8px">InjectionPoint ip = (InjectionPoint) manager.getReference(bean, InjectionPoint.class, manager.createCreationalContex</span><span style="font-size:12.8px">t(bean));</span><br></div><div><span style="font-size:12.8px"><br></span></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> I don&#39;t think we should add this into TCK as it&#39;s rather corner case not clearly defined in the spec.<br></blockquote><div><br></div><div>Would that be something that&#39;s beneficial to add to the 2.0 spec?</div><div><br></div><div>Kind regards,</div><div>Arjan Tijms</div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Martin<br>
<br>
[1]<br>
<a href="https://issues.jboss.org/browse/WELD-1823" rel="noreferrer" target="_blank">https://issues.jboss.org/browse/WELD-1823</a><br>
<br>
Dne 27.1.2016 v 15:20 Tomas Remes napsal(a):<div class=""><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Hi Arjan,<br>
<br>
Ok I am going to check this. Wrt TCK I am not sure it&#39;s suitable to some spec assertion so I wouldn&#39;t add it to TCK but we can definitely include this to Weld internal testsuite.<br>
<br>
Thank&#39;s<br>
<br>
Tom<br>
<br>
----- Original Message -----<br>
From: &quot;arjan tijms&quot; &lt;<a href="mailto:arjan.tijms@gmail.com" target="_blank">arjan.tijms@gmail.com</a>&gt;<br>
To: &quot;Jozef Hartinger&quot; &lt;<a href="mailto:jharting@redhat.com" target="_blank">jharting@redhat.com</a>&gt;<br>
Cc: <a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
Sent: Wednesday, January 27, 2016 2:42:00 PM<br>
Subject: Re: [cdi-dev] Getting injection point from Bean#create<br>
<br>
Hi<br>
<br>
On Thu, Nov 20, 2014 at 9:42 PM, Jozef Hartinger &lt; <a href="mailto:jharting@redhat.com" target="_blank">jharting@redhat.com</a> &gt; wrote:<br>
<br>
<br>
The simplest thing you can do is:<br>
<br>
Bean&lt;InjectionPoint&gt; bean = (Bean&lt;InjectionPoint&gt;) manager.resolve(manager.getBeans(InjectionPoint.class));<br>
InjectionPoint ip = (InjectionPoint) manager.getReference(bean, InjectionPoint.class, manager.createCreationalContext(bean));<br>
<br>
I just tried this again, and unfortunately it now fails on Weld.<br>
<br>
I quickly tried a series of Weld versions and this is the result:<br>
<br>
Weld<br>
2.2.6 works<br>
2.2.8 works<br>
2.2.9 fails<br>
2.2.13 fails<br>
2.2.14 fails<br>
2.2.16 fails<br>
2.3.0 fails<br>
2.3.2 fails<br>
<br>
So apparently it broke between 2.2.8 and 2.2.9.<br>
<br>
Would it be possible to add a TCK test for this? This would be really helpful as we&#39;d like to use this for the JSF 2.3 RI.<br>
<br>
Kind regards,<br>
Arjan Tijms<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
On 11/19/2014 05:06 PM, arjan tijms wrote:<br>
<br>
<br>
<br>
Hi,<br>
<br>
In a producer method it&#39;s trivial to get access to an InjectionPoint<br>
instance representing the point where the value produced by the<br>
producer will be injected.<br>
<br>
When registering a Bean manually from an extension using<br>
AfterBeanDiscovery#addBean, this is not immediately obvious.<br>
<br>
After some fumbling with the CDI APIs I came up with the following<br>
code that seems to work on both Weld and OWB (didn&#39;t test CanDI yet).<br>
<br>
It uses a small &quot;dummy&quot; class, which is used to grab an InjectionPoint off:<br>
<br>
In a Bean:<br>
<br>
public Object create(CreationalContext&lt;Object&gt; creationalContext) {<br>
<br>
InjectionPoint injectionPoint = (InjectionPoint)<br>
beanManager.getInjectableReference(<br>
resolve(beanManager,<br>
InjectionPointGenerator.class).getInjectionPoints().iterator().next(),<br>
creationalContext<br>
);<br>
<br>
With InjectionPointGenerator being the following class:<br>
<br>
public class InjectionPointGenerator {<br>
@Inject<br>
private InjectionPoint injectionPoint;<br>
}<br>
<br>
And resolve being the following method:<br>
<br>
public static &lt;T&gt; Bean&lt;T&gt; resolve(BeanManager beanManager, Class&lt;T&gt; beanClass) {<br>
Set&lt;Bean&lt;?&gt;&gt; beans = beanManager.getBeans(beanClass);<br>
<br>
for (Bean&lt;?&gt; bean : beans) {<br>
if (bean.getBeanClass() == beanClass) {<br>
return (Bean&lt;T&gt;)<br>
beanManager.resolve(Collections.&lt;Bean&lt;?&gt;&gt;singleton(bean));<br>
}<br>
}<br>
<br>
return (Bean&lt;T&gt;) beanManager.resolve(beans);<br>
}<br>
<br>
As mentioned, while this seems to work, I wonder if it&#39;s the best approach.<br>
<br>
Kind regards,<br>
Arjan<br>
_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 ( <a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a> ). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.<br>
<br>
<br>
<br>
_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.<br>
<br>
<br>
_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.<br>
<br>
</blockquote>
<br></div></div><span class=""><font color="#888888">
-- <br>
Martin Kouba<br>
Software Engineer<br>
Red Hat, Czech Republic<br>
</font></span></blockquote></div><br></div></div>