On Feb 29, 2008, at 1:02 PM, Stephan Koops wrote:
>
> what could I do with the resource objects? - If I want to use them,
> I have to now to which class I have to cast them. If the resource
> class is no put under another resource class, I will get a
> ClassCastException.
>
You could implement a common interface on all your resources or use
the toString method to get a description to label a link with. The
possibilities are endless ;-).
> How does this ease the URI construction? What were requests to the
> list? (sorry I didn't get them)
> My request to this was to go to the parent of the actual URI
> reference.
Which parent exactly ? E.g.
@Path("foo")
public class FooResource {
@Path("bar/baz")
public BazResource getBaz() {...}
}
In BazResource ("foo/bar/baz") what is the parent URI "foo" or "foo/
bar". I think "foo" is the only useful answer. The proposal would give
you {"foo"=>FooResource, "foo/bar/baz"=>BazResource}.
> This is not really esay with this approach: I have to iterate the
> keys, check, if another key is avaiable in the iterator, and then I
> could add it to the path. This would be much easier be add a method
> UriBuilder.parent(), which could throw an IllegalStateException (or
> another), if this URI represents the (virtual) root directory of the
> host. I think we should not prohibit the parent resource at the root
> resource class, because it should be possible to reach another root
> resource class of the same runtime environment instance.
>
Agreed, the proposal is intended to be a generalized version of the
method you suggested. The parent would always be the n-1 resource key.
Perhaps I didn't understand what you were looking for.
Marc.
>
> Marc Hadley schrieb:
>> Issue 7[1]:
>>
>> "To help with URI construction it would be useful for a resource
>> class to be able to access the list of resources whose sub-resource
>> locators were used to find the resource class."
>>
>> This has come up several times on the users list recently, I
>> propose to add a new method to UriInfo as follows:
>>
>> /**
>> * Get a map of relative URI to resource class instance. Each key
>> represents
>> * a partial path that matched a resource class, a sub-resource
>> method or
>> * a sub-resource locator. Each value is the instance of the
>> resource class
>> * for the corresponding key. When iterating the map, the keys are
>> ordered
>> * according to request URI matching order, with the root resource
>> first.
>> * E.g.:
>> *
>> * <pre>@Path("foo")
>> *public class FooResource {
>> * @GET
>> * public String getFoo() {...}
>> *
>> * @Path("bar")
>> * @GET
>> * public String getFooBar() {...}
>> *
>> * @Path("baz")
>> * public BazResource getFooBaz() {...}
>> *}</pre>
>> *
>> * <p>A request <code>GET /foo</code> would return a map with a
>> single key:
>> * "foo" whose value is an instance of FooResource</p>
>> *
>> * <p>A request <code>GET /foo/bar</code> would return a map with
>> two keys
>> * in the following order: "foo" whose value is an instance of
>> * <code>FooResource</code> and "bar" whose value is an instance of
>> * <code>FooResource</code></p>
>> *
>> * <p>A request <code>GET /foo/baz</code> would return a map with
>> two keys
>> * in the following order: "foo" whose value is an instance of
>> * <code>FooResource</code> and "baz" whose value is an instance of
>> * <code>BazResource</code></p>
>> *
>> * @return a map of URI to resource class instance.
>> */
>> public Map<URI, Object> getResourceAncestry();
>>
>> Any objections, enhancements ?
>>
>> Marc.
>>
>> [1] https://jsr311.dev.java.net/issues/show_bug.cgi?id=7
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: dev-help_at_jsr311.dev.java.net
>
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.