You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Bertrand Delacretaz <bd...@apache.org> on 2013/07/01 11:13:44 UTC

FYI, working on @AdapterMethod

Hi,

Following up on Olaf Otto's excellent suggestions for simpler/cleaner
adapters at CQCon, I have created a prototype (in my whiteboard) that
handles @AdapterMethod annotations - you basically just need to
annotate a method like

  @AdapterMethod
  public Bar adaptToBar(Foo f) { ... }

in a service that implements the (empty) AdapterMethodsProvider
interface, to provide a Foo to Bar adapter.

See SLING-2938 for details, [1] has two examples of
AdapterMethodsProvider services.

Feedback is welcome.

-Bertrand

[1] https://svn.apache.org/repos/asf/sling/whiteboard/bdelacretaz/adapter-methods/extensions-adapter/src/test/java/org/apache/sling/adapter/internal/AdapterMethodManagerIT.java

Re: FYI, working on @AdapterMethod

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Tue, Jul 2, 2013 at 7:39 PM, Alexander Klimetschek
<ak...@adobe.com> wrote:
> Felix wrote:
>>> ...(3) Maybe we can find a better name for the AdapterMethodProvider interface -- something
>>> which is more in line with the AdapterFactory service name.
>>
> What about simply "AdapterProvider"?...

Good idea, I'll change to that!
-Bertrand

Re: FYI, working on @AdapterMethod

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 01.07.2013, at 12:13, Bertrand Delacretaz <bd...@apache.org> wrote:

>> ...(3) Maybe we can find a better name for the AdapterMethodProvider interface -- something
>> which is more in line with the AdapterFactory service name.
> 
> I don't have a better name for now, and the service is really a
> provider of adapter methods - it's not a Factory of anything.

What about simply "AdapterProvider"?

Nice idea btw.

Cheers,
Alex

Re: FYI, working on @AdapterMethod

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Felix,

Thanks for your comments!

On Mon, Jul 1, 2013 at 11:46 AM, Felix Meschberger <fm...@adobe.com> wrote:
> ...(1) I think the @AdapterMethod annotation should be just called @Adapter. Having an
> annotation on a method is called "...Method" is strange. And maybe it should be in a separate package.

Makes sense, noted.

> (2) The AdapterMethodProxyManagerImpl class should verify the methods as follows...

Yeah, good idea, allows for catching problems earlier.

> ...(3) Maybe we can find a better name for the AdapterMethodProvider interface -- something
> which is more in line with the AdapterFactory service name.

I don't have a better name for now, and the service is really a
provider of adapter methods - it's not a Factory of anything.

> I am also undecided whether
> we need a specific marker interface at all ? Maybe any service having annotated methods will do ?...

I thought about that but it's a bit expensive to check on a large
system with a few thousand services, and requiring the
AdapterMethodsProvider makes things more explicit and less surprising
than allowing any service type to provide adapter methods. Requiring
the AdapterMethodsProvider marker also helps for javadocs, webconsole
troubleshooting etc.

-Bertrand

Re: FYI, working on @AdapterMethod

Posted by Felix Meschberger <fm...@adobe.com>.
Hi Bertrand

Cool stuff. Let me add some comments:

(1) I think the @AdapterMethod annotation should be just called @Adapter. Having an annotation on a method is called "...Method" is strange. And maybe it should be in a separate package.
(2) The AdapterMethodProxyManagerImpl class should verify the methods as follows: Ensure non-void return type, ensure single argument, ensure no checked exceptions declared (@Adapter[Method] JavaDoc must define these requirements). Hence the proxy need not catch checked exceptions and re-throw them as RuntimeExceptions. In fact, no exceptions should be thrown at all -- rather a problem should just be logged and null returned.
(3) Maybe we can find a better name for the AdapterMethodProvider interface -- something which is more in line with the AdapterFactory service name. I am also undecided whether we need a specific marker interface at all ? Maybe any service having annotated methods will do ? Or is this too expensive to check ?

Regards
Felix

Am 01.07.2013 um 11:13 schrieb Bertrand Delacretaz:

> Hi,
> 
> Following up on Olaf Otto's excellent suggestions for simpler/cleaner
> adapters at CQCon, I have created a prototype (in my whiteboard) that
> handles @AdapterMethod annotations - you basically just need to
> annotate a method like
> 
>  @AdapterMethod
>  public Bar adaptToBar(Foo f) { ... }
> 
> in a service that implements the (empty) AdapterMethodsProvider
> interface, to provide a Foo to Bar adapter.
> 
> See SLING-2938 for details, [1] has two examples of
> AdapterMethodsProvider services.
> 
> Feedback is welcome.
> 
> -Bertrand
> 
> [1] https://svn.apache.org/repos/asf/sling/whiteboard/bdelacretaz/adapter-methods/extensions-adapter/src/test/java/org/apache/sling/adapter/internal/AdapterMethodManagerIT.java