Stian Soiland wrote:
See http://restlet.tigris.org/issues/show_bug.cgi?id=303 for the
enhancement request.
Thanks for posting that RFE, I hadn't seen it...
In my code, I need each Resource to have a different set of converters,
so the ConverterService solution wouldn't really work for me. I also
found that having the representations coded in the resource wasn't
really ideal as I wanted it to be more flexible and I kept making
sub-classes just to add representations. So I created a
ResourceConverter interface and associate a Resource with a list of
converters (done by a custom Finder). This is probably similar to the
Map solution proposed, except I use a visitor pattern to allow the
converters to call on the Resource rather than inner classes.
The interface provides methods for getting the variants provided by the
converter and subsequently the representation for a chosen variant.
In its constructor the Resource calls on each converter to add its
variants to the Resource.
In Resource.getRepresentation each converter is called in turn until one
of them returns a representation.
I couldn't help but feel that something like this belonged in the API,
but wasn't sure if it was just some special need I had... Glad to see
an RFE!
Regards,
Michael.