Hi Sumit,
You raised an important point. In the past there was indeed two separate
methods, one returning a list of variants metadata and another returning an
actual representation based on the selected variant. In many cases, this
separation was a burden, especially when the representation heavy work
didn't occur at initialization time (like for a file where only the
getStream(), write() methods are expensive).
However, as you pointed out, the JsonRepresentation class and
DomRepresentation class are heavy to initialize, no matter how you work on
the problem. Note that the content negotiation is taking several aspects
into account, like the language, not just the media type.
So, here are the changes that I made:
- split Representation class into a new Variant class (containing all
metadata properties) and into a lighter Representation class. Variant is a
subclass of Resource and Representation a subclass of Variant. Zero impact
on existing code.
- changed getVariants() to return a List<Variant> instead of a
List<Representation>
- getRepresentation(Variant variant) : Representation
return the full representation for a variant. By default, it will
return 'variant' in case it is already a representation (instance of
Representation class)
I will post a first RC2 snapshot very soon. Please test the changes and let
me know if they suit your needs.
Best regards,
Jerome
> -----Message d'origine-----
> De : news [mailto:[EMAIL PROTECTED] De la part de Sumit Lohia
> Envoyé : jeudi 28 décembre 2006 20:00
> À : [email protected]
> Objet : handling multiple representations of a resource
>
> How can I provide multiple representations for a resource in
> an optimal way?
>
> I have a database-backed application that stores an address book.
> I wish the data to be exposed as both a JsonRepresentation and a
> DomRepresentation. Currently, I am creating both representations
> as part of the getVariants() call so that content negotiation can
> take place. However, to do this I need to construct both a
> DOM Document
> and a JSONObject in order to create the respective
> representations even
> when the client is only asking for 1 of these representations.
>
> Wouldn't it be better if the Resource could expose out what possible
> MediaTypes it supported and then the handler just ask for the
> representation
> the client requested?
>
> Thanks.
>
> Sumit
>