On Aug 20, 2007, at 3:16 PM, Story Henry wrote:
>
> Now I am wondering is if one needs to create one Resource per class
> that is made visible. If I were to create a read only web site,
> could I not have ResourceGroup that given a URI requested could
> decide whether the object existed or not in the database? In so(m)
> mer I could have something like this, assuming the database knew of
> the correct local URLs already:
>
> mapper.getObjectById(uri,clazz);
>
> This would require just the knowledge of which class to look for at
> which URI.
>
Yes, that would work. Depending on the constraints you could even
encode the class in the URI so you could write something like:
@UriTemplate("{class}/{id}")
public class ResourceMapper {
public ResourceMapper(@UriParam("class") String clazzName,
@UriParam("id") String id) {
Class clazz = mapNameToClass(clazzName);
mapper.getObjectById(id, clazz);
}
...
}
BTW, the constructor usage show above doesn't yet work in the trunk,
only in the "resourcefactory" branch but we'll hopefully have that
integrated soon.
> Is it possible to avoid going through all the intermediate object
> creations stages, such as when one is walking through a simple
> directory structure?
Yes, you can use an arbitrarily deep URI path in the UriTemplate. You
can also use the "limited" property of UriTemplate if you want a
template parameter to match multiple path segments, e.g. @UriTemplate
(value="widgets/{id}", limit=false):
request=widgets/foo => {id}=foo
request=widgets/foo/bar => {id}=foo/bar
I'm not sure if Jersey yet supports the "limited" property but if not
support will be coming.
Marc.
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.