You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by "Shackelford, John-Mason" <Sh...@ncs.com> on 2002/09/04 17:59:38 UTC

DynamicConfigurator question

I must be a little slow...

I use public Object createDynamicElement(String name) to instantiate an
object corresponding to a subelement. Ant calls this method and, using
introspection, it calls setters on the returned object where they correspond
to tag attributes in the build file.

Now that the subelement object has been populated, my class that implements
DynamicConfigurator needs to call a method on the subelement object.
Typically I would have an addXXX method and the subelements would be added
to a Vector, but since XXX corresponds to an element name unknown to me at
compile time, what do I do? 

I assume that the setDynamicAttribure method applies only to attributes of
the tag associated with the DynamicConfigurator, not its subelements. So its
not going to help. 

I am trying to build a top level controller that processes and issues
commands. The commands are specified as subelements. They are responsible
for configuring themselves based on the attributes specified and then
handing over a very succinct bit of info that the controller can then
execute.

<controller arg1="">
	<someCommand someArg1="" someArg2=""/>
	<someOtherCommand someOtherArg=""/>
<controller>	

I know I could achieve this by simply doing this and using
DynamicConfigurator with dynamic attributes for subelements, but this could
really make a mess since it would force one object to handle logic for lots
of commands. 

<controller arg1="">
	<command name="someCommand" someArg1="" someArg2=""/>
	<command name="someOtherCommand" someOtherArg=""/>
<controller>	

Though I suppose I could just use an abstract factory and have the
DynamicConfigurator subelement just delegate all the work to an assortment
of other classes that were mapped to the command name via a property file
(thanks again Erik and Dominique for that insight).

Okay, now I am wavering. Should I abandon my initial approach or am I
missing something that would make it easy to do? It does seem somewhat
friendlier to the end user to ask them to type: <myCommand arg=""/> instead
of <command name="myCommand" arg=""/> but perhaps it isn't doable.


Thanks for holding my hand,


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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DynamicConfigurator question

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Shackelford, John-Mason wrote:

> Now that the subelement object has been populated, my class that implements
> DynamicConfigurator needs to call a method on the subelement object.
> Typically I would have an addXXX method and the subelements would be added
> to a Vector, but since XXX corresponds to an element name unknown to me at
> compile time, what do I do? 

When using the createXXX methods, including the DynamicConfigurator one, 
you don't get a chance to call methods on the populated objects until 
execute().  This is just how it is, and how all core Ant tasks operate.

Design your implementation to account for this and all will be well.

> I assume that the setDynamicAttribure method applies only to attributes of
> the tag associated with the DynamicConfigurator, not its subelements. So its
> not going to help. 

Your subelements could also implement DynamicConfigurator, and their 
subelements, and so on.  So, yes, it would help if you need to do super 
nested dynamic stuff.

> <controller>	I know I could achieve this by simply doing this and using
> DynamicConfigurator with dynamic attributes for subelements, but this could
> really make a mess since it would force one object to handle logic for lots
> of commands. 

You got a better design?

You're really going way out of the norm here for implementing Ant tasks, 
so either your on the bleeding edge or your out in left field!  :)

> DynamicConfigurator subelement just delegate all the work to an assortment
> of other classes that were mapped to the command name via a property file
> (thanks again Erik and Dominique for that insight).

Again, this has to do with plain old Java patterns and design.  How you 
do it is up to you, and your hands are not really tied that much with 
Ant - its not the bottleneck here, I don't think.  You've got 
ultra-dynamic capability.

> Okay, now I am wavering. Should I abandon my initial approach or am I
> missing something that would make it easy to do? It does seem somewhat
> friendlier to the end user to ask them to type: <myCommand arg=""/> instead
> of <command name="myCommand" arg=""/> but perhaps it isn't doable.

I can't say.  It is doable what you're asking for, but it sounds like 
you got much more going on than I can see or have time to digest.  Its 
up to you to design it to work the way you want, but Ant gives you the 
capabilities.  I've not seen a case you've presented where Ant was 
preventing you from doing something you wanted.

	Erik



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>