Hi Kyrre,
> I've been trying to make a small test application
> using restlets. First of all I'd like to say good work
> on bringing a framework for developing REST
> applications to Java, that was sorely needed!
Thank you! There is still much to do so I'm happy to hear your support.
> Anyway. I've looked at the sample code, and there the
> domain classes are subclasses of Resource.
More precisely, subclasses of AbstractResource or directly implementing the
Resource interface. But I will probably merge Resource and AbstractResource
into a single Resource class in the upcoming beta 19.
> Looking at the Handler code in eg handleDelete, the
> Resource is found, and the delete() method is called
> on the resource.
FYI, the Handler class will be renamed to Finder in beta 19, but the logic
will stay just the same.
> If we use the domain class as a subclass of Resource,
> this would mean that the object will have to delete
> itself... Isn't that a bit strange? Is it better to
> make the Resource classes refer to the real domain
> objects, and thereby deleting the referred domain
> object?
Thanks for giving me an opportunity to discuss this important point. The
idea of having a Resource.delete() method was a deliberate design choice on
my behalf. I assumed that in most cases, the Resource instance would know
how to delete itself:
- by removing itself from a parent container or object, and doing some
cleanup work
- by being some sort of proxy and asking to the 'real' domain object (for
example an EJB Entity bean, a persistent db4o object, a database row) to
delete itself or by asking to its container to delete it.
I didn't want to constrain too much how resources should be designed and
managed, other APIs (EJB, JPA, JDBC) or products (db4o) are fully focused on
this, and the Restlet API should integrate equally well with all of them
IMO. Maybe I'm wrong-headed and we should introduce some sort of
ResourceContainer?
Also, if you look at the javax.ejb.EntityBean interface, it also has a
"ejbRemove()" method that you could compare to the delete() method in
Resource. Finally, nothing prevents you from changing the default
handleDelete() behavior in your Handler subclass. Instead of doing a
findTarget() + target.delete(), you could do a findTarget() +
getContainer().delete(target). Maybe we should support both options out of
the box, using a flag on Handler?
> How have others separated the domain objects and the
> Resources?
I'm interested by answers too!
> I'm desperatly seeking some documentation that goes a
> bit beyond setting up a server and plain Javadoc, as
> well as a more complete example with all CRUD methods
> implemented.
I have planned to add some docs on this point for 1.0 release. Meanwhile,
you can refer to this FAQ entry:
"How do I implement the traditional MVC pattern?"
http://www.restlet.org/faq#15
Best regards,
Jerome