I meant to reply yesterday - but my battery ran out.
You need to use the attribute "loaderref" so that the
same classloader is used for both the typedef and the
taskdef. Otherwise, different classloaders will be used,
and so the the classes will not be compatible.

Example:
--------------------- build.xml ---------------
<project>
 <target name="compile">
   <mkdir dir="classes"/>
   <javac srcdir="src" destdir="classes"/>
 </target>

 <target name="works" depends="compile">
   <taskdef name="task" classname="my.Task"
            classpath="classes" loaderref="my.loaderref"/>
   <typedef name="type" classname="my.Type"
            loaderref="my.loaderref"/>
   <task>
     <type/>
   </task>
 </target>

 <target name="fails" depends="compile">
   <taskdef name="task" classname="my.Task"
            classpath="classes" />
   <typedef name="type" classname="my.Type"
            classpath="classes"/>
   <task>
     <type/>
   </task>
 </target>

</project>

-------------- Task.java ------------------

package my;

public class Task extends org.apache.tools.ant.Task {
   public void add(Type p) {
   }
}

---------------  Type.java --------------------

package my;

public class Type {
}

Peter

Eric Tchepannou wrote:

I have checked 
http://www.oracle.com/technology/pub/articles/bodewig_taskwriters.html
I think I should rather use addMyBaseType(MyBaseType t) instead of
addConfigured(...) ?
Could it be that this new syntax is now only valid with Ant 1.6 + ?

On 6/9/05, Eric Tchepannou <[EMAIL PROTECTED]> wrote:
Thanks for that Matt.
I have checked my code again and managed to have it working with the
createXXX() Method. The addConfigured(..) still fails... :(

On 6/8/05, Matt Benson <[EMAIL PROTECTED]> wrote:
Eric:
 Without consulting the code (much)... if you want
your custom task to recognize any of

<mytask>
 <mytypea />
</mytask>

<mytask>
 <mytypeb />
</mytask>

<mytask>
 <mytypec />
</mytask>

where mytypea|b|c all have one base class, you will
want to make each type available with a typedef and
then the code you have--addConfigured(BaseTypeClass
o)--should work. Beyond that I do wonder why you need
to cast your subtypes... OO would dictate that you
call  a designated method and they would simply behave
accordingly, but whatever floats your boat I suppose.

HTH,
Matt

--- Eric Tchepannou <[EMAIL PROTECTED]> wrote:

Hello,

I am developing an ant task extension but face
problems to have it
running from the buildfile. I get an error stating
that a certain
custom type of mine is not supported by my task.

I think I know where the problem might come from:
I have implemented multiple types that I have
defined as extension of
a base abstract class (that implements an interface)
and in my Task
extension I have defined an
addConfigured(BaseTypeClass o) and do the
casting in the method implementation.
Could this be the source of the problem?
Should I rather for each type subclass implement a
addConfigured(TypeSubclass o)?

...or do you think the the problem somewhere else?

My next step will be to test this, but as this might
be a time
consuming typing job, I thought I could count on
your previous
experiences.

Many thanks for your contributions.

--
Best Regards,
Eric Tchepannou


---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]




__________________________________
Discover Yahoo!
Use Yahoo! to plan a weekend, have fun online and more. Check it out!
http://discover.yahoo.com/

--
Best Regards,
Eric Tchepannou





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to