ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Magesh Umasankar" <>
Subject DispatchTask
Date Wed, 02 Jun 2004 18:44:15 GMT

I'd like to introduce the concept of a DispatchTask to Ant.  This class may
be subclassed by tasks that perform multiple operations depending upon a
parameter.  Currently, the task-writer would be using if...else if...else
constructs.  Extending from this class would make it more elegant.  Use
cases include tasks that take in same set of parameters but perform
different operations based on needs.

Example usage would be:

<somecompoundtask param1="..." param2="..." mode="list"/>

In the above example, the custom task writer extends from DispatchTask
instead of Task and implements a method with the signature:

public void list() throws BuildException

instead of the traditional

public void execute() throws BuildException

..and the list() method would be invoked.

A scratch-pad implementation follows.


public abstract class DispatchTask extends Task {
    private String mode;
    public final void setMode(final String mode) {
        this.mode = mode;

    public void execute() throws BuildException {
        if (mode != null) {
            Method m = this.getClass().getMethod(mode, null);
            m.invoke(this, null);


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message