dev@jsr311.java.net

Re: Lifecycle options

From: Dhanji R. Prasanna <dhanji_at_gmail.com>
Date: Tue, 10 Jul 2007 20:42:30 +1000

On 7/10/07, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
>
> Dhanji R. Prasanna wrote:
>
>
> What do you mean by 'canned cases'?


If you look below at the singleton example, Im saying we could provide that
out of the box. =)

Surely we have to specify some scoping rules for portable deployment?
> And since a developer will write a POJO for a particular scope
> presumably the scope and the POJO go together?


Here's a simple idea off the top of my head:

@URITemplate("/person/{id}")
@ProvidedBy(PersonFactory.class)
public class PersonResource {

//http methods and so on...
}


//this factory is semantically a singleton provider but JaxRs knows nothing
about scope nor forces a developer to learn a new IoC profile
public class PersonFactory implements ObjectProvider<PersonResource> {
      private final PersonResource res = new PersonResource(...);

      public PersonResource get() {
             return res;
      }
}


Now it is easy to conceive of:

@URITemplate("/person/{id}")
@ProvidedBy(SpringPersonFactory.class)
public class PersonResource {

//http methods and so on...
}

Or perhaps a general ResourceFactory that can be implemented to hook into
spring.

I'll post a more detailed example on why we should let spring (or
<insert_ioc_flavor_of_month>) create these objects in the 3rd party
containers thread.


Dhanji.