2008/10/31 Stefan Bodewig <[EMAIL PROTECTED]>:
> On Fri, 31 Oct 2008, Gilles Scokart <[EMAIL PROTECTED]> wrote:
>
>> 2008/10/30 Stefan Bodewig <[EMAIL PROTECTED]>:
>>>    public void hello() {
>>>        TagBuilder.forProject(p)
>>>            .newTag("echo")
>>>            .withAttribute("message", "Hello, ${world}!")
>>>            .execute();
>>>    }
>>
>> Some alternatives  :
>>
>> public void hello() {
>>       EchoTask echo = TagBuilder.create(EchoTask.class , p);
>>       echo.setMessage("Hello, ${world}!");
>>       echo.execute();
>> }
>
> TagBuilder uses UnknownElement which means it can resolve task
> implementations, typedefs and so on.  Your example wouldn't resolve
> properties, BTW.

The idea was not to instanciate and execute the Task directly.
The idea was to produce a "builder" object with a more strongly typed API.

The echo object created can actually be a recorder object that fill an
UnknownElement.  The fact that this recorder can be declared as an
EchoTask is just a way to provide stronger typing.

This is the kind of technique is used by jmock or easymock.

(Note that's more complexe in my second example because there you have
to execute your project into a specific ClassLoader where all tasks
class are transformed into a recorder.)

>
> In current svn it reads
>
> EchoBuilder.echoMessage(p, "Hello, ${world}!");

This is obviously shorter :-)

-- 
Gilles Scokart

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to