I think this (or something like it) is worth including.&nbsp; I can attest that Seam&#39;s @Unwrap is handy, and I&#39;d like to see a webbeans analogue.<br>-Matt<br><br><br><br><div class="gmail_quote">On Fri, Nov 14, 2008 at 2:58 PM, Gavin King <span dir="ltr">&lt;<a href="mailto:gavin@hibernate.org">gavin@hibernate.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I&#39;ve been thinking about the problem of implementing re-usable<br>
components like our JMS endpoints. What I&#39;m trying to do is implement<br>
the requirements of JMS endpoints as a simple Web Bean. To do that<br>
today, I would need to create a class which implemented all the API<br>
types:<br>
<br>
 &nbsp; &nbsp;@ApplicationScoped<br>
 &nbsp; &nbsp;public class QueueEndpoint<br>
 &nbsp; &nbsp; &nbsp; &nbsp;implements Queue, QueueSession, QueueSender, QueueConnection { ... }<br>
<br>
and I would have to go and implement every one of the operations of<br>
each of those interfaces to delegate to the correct object. (A bunch<br>
of tedious code.)<br>
<br>
However, if we assume that the client proxy is smart enough, we could<br>
let the Web Bean manager automagically do that delegation for us. We<br>
would need a new annotation that could be applied to fields or<br>
methods, for example:<br>
<br>
 &nbsp; &nbsp;@ApplicationScoped<br>
 &nbsp; &nbsp;public class QueueEndpoint &nbsp;{<br>
 &nbsp; &nbsp; &nbsp; &nbsp;...<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;@Supports Queue getQueue() { ... }<br>
 &nbsp; &nbsp; &nbsp; &nbsp;@Supports QueueSession getQueueSession() { ... }<br>
 &nbsp; &nbsp; &nbsp; &nbsp;@Supports QueueSender getQueueSender() { ... }<br>
 &nbsp; &nbsp; &nbsp; &nbsp;@Supports QueueConnection getQueueConnection() { ... }<br>
<br>
 &nbsp; &nbsp;}<br>
<br>
We no longer need to write all those annoying delegation methods! The<br>
client proxy would just call the correct @Supports method when the<br>
QueueEndpoint type did not define the method that was &nbsp;invoked by the<br>
client, and delegate the method to the returned object.<br>
<br>
To make this really work, we would need to say:<br>
<br>
* the set of API types of the Web Bean includes all types of @Supports<br>
methods/fields<br>
* if a certain method name appears on more than one @Supports<br>
method/field type, it must also be implemented directly by the impl<br>
class<br>
* if a certain method name appears on more than one @Supports<br>
method/field type, or on both the impl class and a @Supports<br>
method/field type, it is always called on the impl class<br>
<br>
Therefore, close() would need to be implemented by QueueEndpoint:<br>
<br>
 &nbsp; &nbsp;@ApplicationScoped<br>
 &nbsp; &nbsp;public class QueueEndpoint &nbsp;{<br>
 &nbsp; &nbsp; &nbsp; &nbsp;...<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;@Supports Queue getQueue() { ... }<br>
 &nbsp; &nbsp; &nbsp; &nbsp;@Supports QueueSession getQueueSession() { ... }<br>
 &nbsp; &nbsp; &nbsp; &nbsp;@Supports QueueSender getQueueSender() { ... }<br>
 &nbsp; &nbsp; &nbsp; &nbsp;@Supports QueueConnection getQueueConnection() { ... }<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;void close() { throw new UnsupportedOperationException(); }<br>
<br>
 &nbsp; &nbsp;}<br>
<br>
You&#39;re probably thinking that we can do all this with @Producer<br>
methods, however, the semantics are not exactly the same, since the<br>
association b/w the producer object and produced object is lost as<br>
soon as the producer method returns. Furthermore, @Producer methods<br>
aren&#39;t really appropriate for 3rd-party reusable objects, since the<br>
XML configuration of a producer method is verbose.<br>
<br>
I don&#39;t believe that Web Beans 1.0 absolutely has to have this<br>
feature, but I know its useful, and I know that we will implement it<br>
in the RI, so I would prefer if it was portable. What do you guys<br>
think? Useful? Too much magic? Let me know...<br>
<br>
Seam already has an extremely primitive/braindead version of this<br>
feature, that I&#39;ve found *extremely* useful when writing reusable<br>
components:<br>
<br>
<a href="http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/concepts.html#d0e4283" target="_blank">http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/concepts.html#d0e4283</a><br>
<br>
(@Factory is more or less like @Produces, whereas @Unwrap is a really<br>
crappy version of @Supports.)<br>
<font color="#888888"><br>
--<br>
Gavin King<br>
<a href="mailto:gavin.king@gmail.com">gavin.king@gmail.com</a><br>
<a href="http://in.relation.to/Bloggers/Gavin" target="_blank">http://in.relation.to/Bloggers/Gavin</a><br>
<a href="http://hibernate.org" target="_blank">http://hibernate.org</a><br>
<a href="http://seamframework.org" target="_blank">http://seamframework.org</a><br>
</font></blockquote></div><br>