<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi All,<div><br></div><div>In Seam Social, in order to support polymorphism I need the service beans to be qualified with the name of the service. For instance :</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3"><span style="color: #777777">@RelatedTo</span>("LinkedIn")</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3"><span style="color: #941965">public</span> <span style="color: #941965">class</span> LinkedInJackson <span style="color: #941965">extends</span> OAuthServiceBase <span style="color: #941965">implements</span> LinkedIn</font></div><div><br class="webkit-block-placeholder"></div><div>It allows users to inject a service bean like that&nbsp;</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3"><span style="color: #777777">@Inject @RelatedTo</span>("LinkedIn")</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">OAuthService&nbsp;service;</font></div></div><div><br class="webkit-block-placeholder"></div><div>As I want to ease user life I also need to support this kind of injection (same results as above)&nbsp;</div><div><br class="webkit-block-placeholder"></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span style="color: rgb(119, 119, 119); "><font class="Apple-style-span" face="Courier" size="3">@Inject</font></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">LinkedIn service;</font></div></div><div><br class="webkit-block-placeholder"></div><div>As LinkedIn interface has only one implementation, using a qualifier when I use its specific type is useless and could be confusing.</div><div><br></div><div>Until now I registered the second version of the bean (without a qualifier) thru a producer, but as each service bean will have both registration (with and without qualifier) I decided to simplify this bi-registration with an extension (it will also ease the writing of new service bean for third party developers).</div><div><br></div><div>My extension works in 2 steps :</div><div>First it collects in a Map all the annotated type which are OAuthService children and have a @RelatedTo qualifier :</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3"><span style="color: #941965">public</span> <span style="color: #941965">void</span> processServicesBeans(<span style="color: #777777">@Observes</span> ProcessManagedBean&lt;OAuthService&gt; pbean) {</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; Annotated annotated = pbean.getAnnotated();</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #941965">if</span> (annotated.isAnnotationPresent(<span style="color: #777777">RelatedTo</span>.<span style="color: #941965">class</span>)) {</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #777777">RelatedTo</span> related = annotated.getAnnotation(<span style="color: #777777">RelatedTo</span>.<span style="color: #941965">class</span>);</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String name = related.value();</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #102bc3">servicesBean</span>.put(name, pbean.getAnnotatedBeanClass());</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; }</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; }</font></div></div><div><br class="webkit-block-placeholder"></div><div>Then, after the bean discovery, it register a new version of each Qualified bean without the qualifier (thanks to solder !).</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3"><span style="color: #941965">public</span> <span style="color: #941965">void</span> afterBeanDiscovery(<span style="color: #777777">@Observes</span> AfterBeanDiscovery abd, BeanManager bm) {</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #941965">for</span> (String type : <span style="color: #102bc3">servicesBean</span>.keySet()) {</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AnnotatedType&lt;? <span style="color: #941965">extends</span> OAuthService&gt; annotatedType = <span style="color: #102bc3">servicesBean</span>.get(type);</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AnnotatedTypeBuilder annoBuilder = <span style="color: #941965">new</span> AnnotatedTypeBuilder().readFromType(annotatedType).removeFromClass(</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #777777">RelatedTo</span>.<span style="color: #941965">class</span>);</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AnnotatedType myAnnotatedType = annoBuilder.create();</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BeanBuilder beanBuilder = <span style="color: #941965">new</span> BeanBuilder(bm).readFromType(myAnnotatedType);</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; abd.addBean(beanBuilder.create());</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; }</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; }</font></div></div><div><br></div><div>This seems to work quite well except that my service Beans have a @Postconstruct method and at initialization Weld throws the following exception</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3"><span style="text-decoration: underline ; color: #081c8c">org.jboss.weld.exceptions.DefinitionException</span>: WELD-000805 Cannot have more than one post construct method annotated with @PostConstruct for public class org.jboss.seam.social.linkedin.LinkedInJackson</font></div></div><div><br class="webkit-block-placeholder"></div><div><br class="webkit-block-placeholder"></div><div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><div><div>If I remove the @Postconstuct in the AnnotatedTypeBuilder by changing its declaration by :</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">AnnotatedTypeBuilder annoBuilder = <span style="color: rgb(148, 25, 101); ">new</span> AnnotatedTypeBuilder().readFromType(annotatedType).removeFromClass(</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Courier" size="3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: rgb(119, 119, 119); ">RelatedTo</span>.<span style="color: rgb(148, 25, 101); ">class</span>).<b>removeFromAll(<span style="color: rgb(119, 119, 119); ">PostConstruct</span>.<span style="color: rgb(148, 25, 101); ">class</span>)</b>;</font></div></div><div><br></div><div>Initialization works, I have my 2 beans, but the one I registered without qualifier won't execute the @PostConstruct method (since I had to remove it). I guess I'm missing something in the CDI meta-meta-maze :-). Any help or suggestion would be nice.</div><div><br></div><div>Thanks,</div><div><br class="Apple-interchange-newline">Antoine SABOT-DURAND</div></div></div></div></div></div></div></div></div></body></html>