On Jul 8, 2008, at 3:44 PM, Jo Størset wrote:
>> Being able to root the same resource class in multiple places is
>> useful, e.g. a Customer resource could be available at:
>>
>> /customers/{id}
>> /orders/{id}/customer/{id}
>> /invoices/{id}/customer/{id}
>
>
> But you would want the same way of instantiating a particular
> customer for all these places (it's the same resource). And since
> the sub resource path parameter is the same for these three cases,
> why not put the @Path("{id}") on the customer object and let the
> framework instantiate it, instead of duplicating the same logic
> under all three parent resources?
>
You need the URI template on the sub resource locator method in order
to decide which sub-resource method to call.
E.g.
@Path("customers")
public class CustomersResource {
...
@Path("{id}")
Object locateCustomer(@PathParam("id") String customerId) {
...
}
}
locateCustomer can return instances of different classes based on some
internal logic. I don't see how a runtime could dispatch a request
for /customers/10 with the @Path on the sub-resource class. How would
it know which classes to consider as sub resources ?
Marc.
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.