Hi Paul,
This seems to be at odds with section 2.2 of the draft 311 spec ("A
new resource class instance is created for each request to that
resource"). I tried it however and it seems to work.
regards,
:aditya
> You need a singleton root resource that is responsible for controlling
> the life-cycle of the sub-resources and so on down the hierarchy.
>
> @UriTemplate("/")
> class Root {
>
> AddressBooks r;
>
> Root() {
> r = ...
> }
>
> @UriTemplate("books")
> AddressBooks getBooks() {
> return r;
> }
> }
>
> class AddressBooks {
> AddressBook[] r;
>
> AddressBook() {
> r = ...
> }
>
> @UriTemplate("{book}")
> AddressBook getBook(@UriParam("book") int book) {
> return r[i];
> }
> }
>
> So when the URI path '/books/1' is processed an instance of AddressBook
> will be returned to the Jersey runtime and an HTTP request will be
> dispatched to that instance.
>
> Thus it is possible to say get information from a file system or
> database and cache the resources in memory. Of course one needs to
> manage states changes correctly...
>
> Another way is for the Root resource to instantiate the address book
> info object and pass this as a construction parameter to the sub-resources.
>