On Sat, Sep 11, 2010 at 11:47 AM, Jerome Louvel
<jerome.lou...@noelios.com>wrote:

> Good news, is that we are planning to simplify this binding in version 2.1
> but associating the template files with representation beans based on the
> bean qualified class name. The converter service would allow the developer
> to indicate where the template lives, for example in the classpath next to
> the bean class or in a separate directory.
>

That sounds great. I'm impatient, though, and I want to implement my own
version of this in 2.0.x, with some additional design constraints:

I want to write resource interfaces like this:

public interface CalendarResource {
    @Get("html|atom|json") Calendar getCalendar();
    @Post("form|atom|json:html|atom|json") Event addEvent(Event event);
}

where Calendar is a domain-level interface with some associated mechanisms
for converting a Calendar instance into a
(Freemarker) TemplateRepresentation (looking up the template file based on
the class name, as Jerome describes), Feed, or JacksonRepresentation; and
Event is a domain-level interface with some associated mechanisms for
converting from a Form, Entry, or JacksonRepresentation to an Event instance
and from an Event instance to a TemplateRepresentation, Entry, or
JacksonRepresentation.

I want to implement CalendarResource on the server side with:

public class CalendarServerResource extends ServerResource implements
CalendarResource {
    public Calendar getCalendar() {
        Calendar calendar = lookupCalendar(getRequest()); // actual domain
logic in here
        return calendar;
    }

    public Event addEvent(Event event) {
        Calendar calendar = lookupCalendar(getRequest());
        Event event = addNewEventToCalendar(calendar, event); // actual
domain logic in here
        return event;
    }
}

And I'd like to be able to make and use client proxies like this:

    CalendarResource calendarResource = ClientResource.create(uri,
CalendarResource.class);
    Calendar calendar = calendarResource.getCalendar();
    // ...
    event = calendarResource.addEvent(event);

I have these questions:

Can I create my own ConverterHelpers for Freemarker, Atom, and Jackson that
have access to the conversion mechanisms mentioned above, and add them to
the Engine on the server side (and, where supported, on the client side)
using this code:

    List<ConverterHelper> converters =
Engine.getInstance().getRegisteredConverters();
    converters.add(new MyFreemarkerConverter());
    converters.add(new MyAtomConverter());
    converters.add(new MyJsonConverter());

Can I make my converters outscore the ones that come with the Freemarker,
Atom, and Jackson extensions by returning scores of greater than 1.0?

Is there (or will there be) a better way to replace or overrule the
converter logic that comes packaged with the extensions with my own logic?

Am I asking for too much? Should I give up and just use Representations in
all my annotated signatures, and put the conversion logic in those methods,
like this?

public interface CalendarResource {
    @Get("html") Representation asHtml();
    @Get("atom") Representation asAtom();
    @Get("json") Representation asJson();
    @Post("form:html") Representation addEventForm(Representation
eventForm);
    @Post("atom") Representation addEventEntry(Representation eventEntry);
    @Post("json") Representation addEventJson(Representation eventJson);
}

public class CalendarServerResource extends ServerResource implements
CalendarResource {
    public Representation asHtml() {
        return new TemplateRepresentation(..., lookupCalendar(getRequest()),
...);
    }
    public Representation asAtom() { return new Feed(...); }
    public Representation asJson() { return new JacksonRepresentation(...);
}
    public Representation addEventForm(Representation eventForm) { ... }
    public Representation addEventEntry(Representation eventEntry) { ... }
    public Representation addEventJson(Representation eventJson) { ... }
}

That's a lot of verbosity that would have to be repeated for each one of my
resource classes.

--tim

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2672134

Reply via email to