ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karl Jay Garcia" <karl_gar...@hotmail.com>
Subject sharing dbConnection object between 2 custom tasks
Date Mon, 12 Jun 2006 18:16:31 GMT
I was wondering if you can help me with my question, very much the same as 
from this thread:

http://www.ant-tasks.com/msg/11730.html

I wasn't sure how one would create the custom datatype that shares a 
dbConnection.  I have not found any info on the web that describes this 
fully.

For instance you say dataref attribute but i wasn't sure how to write that 
in a custom datatype, and have it shared.

------Bertrand Fontaine wrote:

>>I have a set of Tasks all requiring access to the very same class
>>instance (a db connection in practice). How can I implement that with
>>ANT?
>>
>>So far, I have tried to implement this behaviour via a TaskContainer
>>but I can't get back the TaskContainer instance from a Task, and hence
>>the reference to the object I would like to share via the
>>TaskContainer, as far as the TaskContainer and the Tasks are loaded in
>>separate class loaders.
>>
>>Thank you,
>>
>>Bertrand Fontaine
>>
>>
>>
>Hi Bertrand,
>
>what I would do would be the following :
>- create a custom ant datatype encapsulating the object(s) that you want
>to share between tasks,
>- use <typedef/> to declare your datatype (or put all your typedefs and
>taskdefs into an antlib descriptor)
>-  then you can declare one or several instance(s) of your custom
>datatype(s) with the id attribute set; in your custom tasks, add a an
>attribute which would be a reference to your custom datatype
>
>something like this :
>
><typedef name="mydata" class="com.foo.mydata"/>
><taskdef name="mytask" class="com.foo.mytask"/>
><taskdef name="mytask2" class="com.foo.mytask2"/>
><mydata property1="some.value" property2="some.othervalue" id="myid"/>
><mytask dataref="myid"/>
><mytask2 dataref="myid"/>
>
>in the source code of ant, this type of mechanisms is used a lot; for
>instance the javac task can accept a reference to the path datatype in
>the attribute classpathref, ...
>I have the impression that there are no explanations about custom
>datatypes in the ant manual, this should exist.
>Most of what has been written about custom tasks also is true of custom
>datatypes, the only difference is that an execute() method is not needed
>for a datatype.
>Your custom datatypes may extend org.apache.tools.ant.types.DataType Source 
>code of org.apache.tools.ant.types.DataType
>which probably makes coding more easy. It is probably also not an
>absolute requirement.
>
>Hopes this helps,
>
>Antoine
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message