Hi again,
I've just played with the annotations idea. I have to confess that used in this
restricted way (only on methods), I'm starting to
like it.
Here is how a sample resource would look like with the refactored API. Note
that both extension names and full MIME type would be
supported. Extensions can be updated via the MetadataService.
import java.io.InputStream;
import org.restlet.ext.atom.Feed;
import org.restlet.resource.Accepts;
import org.restlet.resource.Removes;
import org.restlet.resource.Representation;
import org.restlet.resource.Represents;
import org.restlet.resource.ServerResource;
import org.restlet.resource.Stores;
public class TestResource extends ServerResource {
@Represents("atom")
public Feed getAsAtom() throws Exception {
// ...
return null;
}
@Represents("application/custom+xml")
public Representation getAsXml() throws Exception {
// ...
return null;
}
@Accepts
public void post(Representation entity) throws Exception {
// ...
}
@Stores("atom")
public void putAtom(Feed feed) throws Exception {
// ...
}
@Stores("application/custom+xml")
public void putXml(InputStream stream) throws Exception {
// ...
}
@Removes
public void delete() throws Exception {
// ...
}
}
What is nice is that we would keep the higher-level terminology that we have in
Restlet 1.1 (accept, store, etc.) but make it
available in a more flexible and declarative way.
The new ServerResource would only have lower-level methods, but with a more
flexible signature than in Restlet 1.1:
* void handle()
* Representation handleGet()
* Representation handleGet(Variant)
* Representation handleHead()
* Representation handlePost(Representation)
* Representation handlePut(Representation)
* Representation handleDelete()
I think we are getting somewhere this time. Looking forward to your feed-back.
Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ <http://www.restlet.org/>
http://www.restlet.org
Noelios Technologies ~ Co-founder ~ <http://www.noelios.com>
http://www.noelios.com
_____
De : Jerome Louvel
Envoye : vendredi 30 janvier 2009 12:29
A : discuss
Objet : Resource API refactoring (Was: media type adaptor)
Hi Tim,
While I'm still not convinced of the advantages of annotations used this way,
you did put some doubts in my mind :)
Also, instead of small enhancements in Restlet 1.2 on this front, waiting for a
redesign planned in Restlet 2.0, I think we should
aim at a full redesign right now.
I've reverted my previous changes to the Resource class in SVN trunk to keep
all options open, and I have started some specs on the
wiki:
"Resource API refactoring"
http://wiki.restlet.org/developers/172-restlet/226-restlet.html
You will find a collection of requirements, an analysis and a high-level design
start. Did I miss any important requirement? Does
anyone has design propositions?
Now is time for comment!
Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ <http://www.restlet.org/>
http://www.restlet.org
Noelios Technologies ~ Co-founder ~ <http://www.noelios.com>
http://www.noelios.com
_____
De : [email protected] [mailto:[email protected]] De la part de Tim Peierls
Envoye : mardi 27 janvier 2009 00:25
A : [email protected]
Objet : Re: media type adaptor
I have looked at JAX-RS (and I know that it makes heavy use of annotations),
but this was not about JAX-RS. My comment was
specifically about the proposed use of a method-naming convention to convey
meta-information in Restlet where it seems to me that an
annotation-based approach would be better.
Don't get me wrong: I very much like the simplicity of Restlet as it is, and I
am not pushing for greater use of annotations in
general. It's just that this particular feature seems like a mistake as it
stands.
--tim
On Mon, Jan 26, 2009 at 3:50 PM, Stephan Koops <[email protected]> wrote:
Hi Tim,
I didn't follow the ful discussion, but did you take a look to JAX-RS?
best regards
Stephan
Tim Peierls schrieb:
>
> So, if we are back using runtime annotations, there is no
> particular type safety in play:
>
> Representation representXml();
>
> would be as good (and even more compact) as:
>
> @Variant("xml")
> Representation toXml();
>
> or if you want to be more explicit about the mediatype:
>
> @Variant("text/xml")
> Representation toXml();
>
>
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447
<http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1055994>
&dsMessageId=1055994
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1074698