ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Hatcher" <jakarta-...@ehatchersolutions.com>
Subject Re: IntrospectionHelper request
Date Wed, 09 Jan 2002 12:17:49 GMT
Ta da!

DynamicConfigurator has been implemented.  Attached is a .zip file with all
the pieces (although sorry the directory structure didn't get embedded).
The test case, of course, passes.  I didn't really intend to implement it
fully, I was just investigating the possibilities, and it was easy enough to
go all the way with it.

The two pieces added to IntrospectionHelper are pretty small.  The change to
createElement could have been done a bit cleaner by refactoring the entire
method slightly, but I wanted to get the functionality reviewed cleanly
rather than the refactoring getting in the way of review.

Here's the details from the test case, so you won't have to open the .zip to
see how it works:

    <taskdef name="dyna"
             classname="org.apache.tools.ant.taskdefs.DynamicTask">
      <classpath refid="testclasses" />
    </taskdef>
    <dyna prop1="1" prop2="2">
      <sub prop3="3"/>
      <anything prop4="4"/>
    </dyna>

DynamicTask is simply:

public class DynamicTask extends Task implements DynamicConfigurator {

    public void execute() {
    }

    public void setDynamicAttribute(String name, String value) {
        project.setNewProperty(name, value);
    }

    public Object createDynamicElement(String name) {
        return new Sub();
    }

    public class Sub implements DynamicConfigurator {
        public void setDynamicAttribute(String name, String value) {
            project.setNewProperty(name, value);
        }

        public Object createDynamicElement(String name) {
            return null;
        }
    }
}

This isn't a representative task, but illustrates the pluggable capability
that has been added.

I envision that we could have an abstract helper class or two that implement
DynamicConfigurator and provide the 'return null' of createDynamicElement so
a task or sub-element wouldn't have to provide it, or have an implementation
of setDynamicAttribute that throws a BuildException stating that the
attribute is not supported.  But that is just icing.

Peter - thoughts?  What kind of potential beasts are we unleashing if we
accept this?

Personally I'm +1 on it, obviously!  :)  But I'm eager to hear the negatives
to this implementation as well.

Thanks,
    Erik


Mime
View raw message