ant-user mailing list archives

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

> 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
interface.

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="com.ncs.es.emsbe.tasks.pvcs.Get"/>
<typedef name="command" classname="com.ncs.es.emsbe.tasks.pvcs.Command"/>

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


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)
getProject().getDataTypeDefinitions().get(name);
        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
executed.");

        return obj;
    }


John-Mason Shackelford

Software Developer
NCS Pearson - Measurement Services
2510 North Dodge St.
Iowa City, IA 52245
319-354-9200x6214
shacjo@ncs.com

**************************************************************************** 
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:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message