dev@jersey.java.net

Re: removal of _at_SubResource

From: Peter Liu <Peter.Liu_at_Sun.COM>
Date: Wed, 11 Jul 2007 10:39:16 -0700

Hi Paul,

Thanks for the explanation. BTW, has this been implemented in the trunk so
we can try it out?

Peter

Paul Sandoz wrote:
> Peter Liu wrote:
>> Hi,
>>
>> In the upcoming 0.2 release, @SubResource annotation will be removed.
>> What is the replacement for it and could you provide some code snippet
>> that demonstrate the new approach?
>>
>
> Sure.
>
> Before:
>
> @UriTemplate("/a")
> @SubResources(MySubResource.class)
> class MyResource {
> }
>
> @UriTemplate("b")
> class MySubResource {
> }
>
>
> After:
>
> @UriTemplate("a")
> class MyResource {
>
> // sub-locator method
> @UriTemplate("b")
> public getMySubResource(...) {
> // Life-cycle is per-request
> return new MySubResource(...);
> }
> }
>
> class MySubResource {
> public MySubResource(...) { ... }
> }
>
>
> Points of note:
>
> - Removed the requirement that root resource classes have a URI template
> that starts with a '/'. Now any resource class annotated with a URI
> template is a root resource class and the URI template is relative to
> the base URI of deployment.
>
> - MySubResource can still be root resource class but when used as part
> of a sub-locator method the URI template on the class will be ignored.
>
> - Injection currently does not work on objects returned by sub-locator
> methods (i.e. the same as it is today). The EG is having discussions
> on life-cycle and injection. Until these discussions reach a
> satisfactory conclusion we cannot do anything about this issue.
>
> Paul.
>