On Mon, Aug 8, 2011 at 2:38 PM, Paul Morris <[email protected]> wrote:
> Unfortunately, in the case I mentioned, I am implementing an abstract
> method that takes a Representation as the argument and since Form doesn’t
> extend Representation I can't use it as the argument.
Well, you couldn't even if it did! :-)
But I don't understand the point of such a generic abstract method if you're
using the @Post annotation. What other callers are there for this method
besides the internal Restlet machinery?
> I may just create the Form on the fly without Spring as in:
>
> @Post
> public Representation doPost(Representation entity) {
> Form form = new Form(entity);
> doSomethingWithForm(form);
> // etc.
> }
>
> I'm new to Spring and so I always seek to know how to construct an object
> via Spring rather than calling "new" in my code but I'm not sure how much
> value DI gives me in this case especially since it's just an object created
> locally, passed to another private method, and then trashed.
>
In this case, I don't think DI buys you anything -- "new Form(...)" is fine.
But if you *really* want to:
public interface RepToFormConverter {
Form convert(Representation rep);
}
public class SimpleRepToFormConverter implements RepToFormConverter {
public Form convert(Representation rep) {
return new Form(rep);
}
}
Now you can inject a RepToFormConverter into your resources without exposing
"new Form" to them. But this feels like massive over-kill.
--tim
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2812588