On 06/12/11 10:11, Jeff Wang wrote:
Ok, I think I'm getting away from what I'm trying to accomplish, which
is to figure out the best way to annotate sub-resources. Currently, I
have foo, which is a sub-resource of bar. so I'd like to GET
/bar/1/foo for the list of Foos that bar 1 has. or POST /bar/1/foo to
create a new foo. or GET /bar/1/foo/3, to get foo 3.
Currently, I have created two separate service beans, have with a
class level @PATH annotation of "/bar" and "/bar/{barId}/foo"
respectively, and individual @PATH additions as required (for fooId
and barId as appropriate.
Right now, Bar, the POJO has a very simple JPA and XML mapping.
@XMLRootElement
@Entity
public class Bar {
@Column(name="fooId")
public Foo;
}
(getters, setters, and other fields removed.) How would a equivalent
mapping be expressed in a sub-resource locator? Would it be actually
easier to read?
Not sure if it answers your question, here is one example:
@Path("bar/{id}/foo")
public class BarResource {
@GET
public Foos getFoos(@PathParam("id") int id) {}
@POST
public void addFoo(Foo foo) {}
// optional: @GET
@Path("{fooid}")
public Foo getFoo (@PathParam("id") int id, @PathParam("fooid") int
foo_id) {}
}
Additionally you can have a "/bar" path on a Bar itself and register it
as another root resource, or push the above "{id}/foo" to the 3 existing
methods and a GET which will return Bar - that would cover /bar only
Cheers, Sergey
thanks
Jeff Wang
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com