ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shackelford, John-Mason" <Sha...@ncs.com>
Subject RE: DynamicConfigurator question
Date Wed, 04 Sep 2002 17:17:18 GMT
Thanks again Dominique and Erik!

>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!  :)

One can only hope... ;)

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

We are talking past each other here. It is in the execute() that I want to
call a method on the element
I have created. But my problem is getting a reference to it. Usually one
would have a vector to iterate through via an addXXX method. But my problem
is that I don't know the XXX at compile time.

>So when createDynamicElement is called on your class, you store the created
>element yourself in a Vector.

Right! I am with you here and that is exactly what I need but the problem
here--now you can point out the error in my understanding--is that the
object added to the Vector has not been populated with attribute info yet.
Or has it? Ah wait I see my mistake (I think). I thought that because of the
reflection magic that somehow the reference I added to the Vector would not
be to the object that actually has its setters called, but obviously that
was very fuzzy-headed of me. So once I have instantiated the object in
createDynamicElement(String name), I add it to my Vector, then I return it,
ant calls its setters, but since I have a reference in my Vector I have
don't have to do any other gymnastics to get the subelement attribute values
in execute(): I simply iterate through the Vector as I normally would.

Am I understanding you Dominique?


John-Mason Shackelford

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



-----Original Message-----
From: Dominique Devienne [mailto:DDevienne@lgc.com] 
Sent: Wednesday, September 04, 2002 11:44 AM
To: 'Ant Developers List'
Subject: RE: DynamicConfigurator question


With DynaConf, you're on your own, and need to keep track of what you create
yourself. And yes, setDynamicAttribute is only called on the for the
element, not it's sub-element.

I used DynaConf to build a DOM DocumentFragment, so every DOM Node was
created using createDynamicElement, which returned a wrapper (to the DOM
Node) implementing DynaConf again, and so on recursively.

So when createDynamicElement is called on your class, you store the created
element yourself in a Vector.

Hope this helps. --DD

-----Original Message-----
From: Shackelford, John-Mason [mailto:ShacJo@ncs.com] 
Sent: Wednesday, September 04, 2002 11:00 AM
To: Ant Developers List
Subject: 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:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>

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


Mime
View raw message