users@jersey.java.net

Re: [Jersey] Nested hierarchies of arbitrary depth

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Thu, 25 Jun 2009 10:18:56 -0400

On Jun 25, 2009, at 9:45 AM, Christopher Piggott wrote:

> What is the best way in jersey to handle hierarchies of arbitrary
> depth?

Sounds like a "sub-resource locator" is what you are looking for, see:

https://jsr311.dev.java.net/nonav/releases/1.0/spec/
spec3.html#x3-310003.4.1

> For example:
>
> I have a widget
> a widget can have subwidgets
> subwidgets can also have subwidgets
> subwidgets can have components (but they are the bottom of the tree)
>
> So I might want to find:
> /widget/1212/subwidget/17/component/3414
>
> or
>
> /widget/12321/subwidget/235235/subwidget/234525/subwidget/234525/
> component/315
>
> My intuition says that I would do this with a @Path that somehow
> delegated to a new instance of the subresource (and so on) as it went
> along, recursively. I just can't quite see how to put it together.
>
Something along these lines:

@Path("widget/{widgetid}")
public class WidgetResource {

   @GET
   ...

   @Path("subwidget/{subwidgetid}")
   SubWidgetResource getSubWidget(@PathParam("subwidgetid") String id)
     return new SubWidgetResource(id);
   }
}

public class SubWidgetResource {

   @GET
   ...

   @Path("subwidget/{subwidgetid}")
   SubWidgetResource getSubWidget(@PathParam("subwidgetid") String id)
     return new SubWidgetResource(id);
   }
}

Essentially getSubWidget returns a new instance of a resource class to
handle the relative path "subwidget/{subwidgetid}" and that can
recurse as deep as required.

HTH
Marc.


> --Chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>