users@jersey.java.net

[Jersey] Re: Generic Resources

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Fri, 30 Nov 2012 13:57:23 -0500

     First question, what determines the concrete type of T?

Gili

On 30/11/2012 12:54 PM, Artem Grebenkin wrote:
> Hi folks,
>
> I have some unusual use case and would be very appreciated for any
> help. In my particular case a generic resource, where I could set a
> @Path, mapping and extend it, would be very very helpful. Something
> like this:
> @Path("/t")/*path set*/
>
> @Consumes({MediaType.APPLICATION_JSON})
>
> @Produces({MediaType.APPLICATION_JSON})
>
> public class BookResource<T> {
>
>
> GenericDAO<Integer, T> tStore;
>
> public GenericDAO<Integer, T> getBook() {
>
> returntStore;
>
> }
>
>
> @Inject
>
> public void setTStore(GenericDAO<Integer, T> tStore) {
>
> this.tStore = tStore;
>
> }
>
> @GET
>
> @Path("{id}")
>
> public T findById(@PathParam("id") long id) {
>
> return tStore.getById(id);
>
> }
>
> @GET
>
> @Path("{number:(/number/[^/]+?)?}{offset:(/offset/[^/]+?)?}")
>
> public List<T> findAll(@PathParam("number") long number,
> @PathParam("offset") long offset) {
>
> //_at_TODO If any of params is null give 0 forward
>
> return tStore.getAll(number, offset);
>
> }
>
> @POST
>
> public int create(T instance) {
>
> tStore.create(instance);
>
> }
>
> @PUT
>
> @Path("{id}")
>
> public int update(T instance) {
>
> tStore.update(instance);
>
> }
>
>
> @DELETE
>
> @Path("{id}")
>
> public int remove(@PathParam("id") long id) {
>
> tStore.delete(id);
>
> }
>
> }
>
>
> Do I have any chance to implement this?
>
> Thanks,
> Artem.