ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shackelford, John-Mason" <>
Subject RE: polymorphic data types as nested elements
Date Wed, 21 Aug 2002 21:22:56 GMT

> I can't quite follow the details of what you're trying to 
> build exactly

I won't waste more of your time on this as I think I am on the right track. 

For the sake of providing an example (possibly a lousy one) to others
working on a similiar project I will summarize what I have been trying to
achieve and how I think I can get there using the DynamicConfigurator

I am rewriting the PVCS task. The top level task is a command processor that
does not know anything about the commands it executes other than that they
conform to the PCLICommand interface (abstractly implemented by
AbstractCommand which subclasses DataType). Specific commands, Get for
instance, subclass AbstractCommand. 

<typedef name="get" classname=""/>
<typedef name="command" classname=""/>

	<get destdir="/mydest">
		<project name="/first/project"/>
		<project name="/second/project"/>
	<command name="myCommand" extraArgs=" -a -b -c"/>

Since I don't want my PCLI class to know anything about the concrete command
classes, I use the DynamicConfigurator to instantiate the appropriate
command based on element name.

    public Object createDynamicElement(String name) throws BuildException {

        String dataTypeFQN = (String)
        Object obj;

        try {
            Class c = Class.forName(dataTypeFQN);
            obj = c.newInstance();
        } catch (Exception e) {
            throw new BuildException("Element " + name + " not supported.");

        //  make sure we have a command object
        if (!(obj instanceof PCLICommand))
            throw new BuildException(
                "Element " + name + " is not a PCLI command and cannot be

        return obj;

John-Mason Shackelford

Software Developer
NCS Pearson - Measurement Services
2510 North Dodge St.
Iowa City, IA 52245

This email may contain confidential material. 
If you were not an intended recipient, 
Please notify the sender and delete all copies. 
We may monitor email to and from our network. 

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

View raw message