On Feb 24, 2009, at 7:18 PM, James Strachan wrote:
>
>> Next steps:
>>
>> 1) investigate the move of WadlResource and creation of further
>> classes into
>> the API so that they can be
>> extended. My initial thoughts on this is i want to be
>> conservative in
>> terms of implicit views, implicit produces
>> and produces media types. i.e. the developer should override
>> or replace
>> as appropriate.
>> Currently the patch for WadlResourceResource and
>> WadlPartialResource are
>> really specific to implicit
>> views because there are not actual resource methods present.
>> James, do
>> you have any opinions on this?
>
> I wonder if Jersey should ship with a default implementation of
> WadlResource and WadlResourceResource (or whatever the 2 classes are
> called - one for the application and one for sub resources) but by
> default they are not mapped to anything (or maybe they are just mapped
> to /application.wadl but then derived classes can map them to new URIs
> with new @Produces/_at_ImplicitProduces?.
>
> Then users can just derive from them and map them to a URI if they
> wish?
>
> e.g.
>
> @Path("api")
> @ImplicitProduces("text/html;qs=5")
> @Produces({"application/vnd.sun.wadl+xml", "application/xml",
> "application/json"})
> public class MyWadlResource extends WadlResource {
> ...
> // not much code or inner knowledge of Jersey's impl required here
> apart from the factory method to create nested resources...
>
> protected WadlResourceResource createChildResource(String uri) {
> return new MyWadlResourceResource(...);
> }
> }
>
> Then the derived class is mostly about adding your own @Path /
> @Produces and optional @ImplicitProduces and helper methods if you
> need any? I'm keen for there to be as little ninja-Jersey hacking
> required for folks to add the API stuff to their apps
>
OK. I see what you are getting at now.
For efficiency purposes it be recommended that @Singleton be used (or
the same for whatever IoC framework is being used). This is because
one obtains a new instance of Application (since instances are
mutable) and we also need to place the base URI into the Application
instance (unfortunately it is not always possible to derive the base
URI at initialization, especially so for Servlet). So we can also
provide this functionality for the developer as well.
Note that the way things are defined now the WadlResource and other
classes do not depend on any Jersey implementation classes so it will
all be nicely isolated.
Paul.