On 6/9/05, Peter Reilly <[EMAIL PROTECTED]> wrote:
> Antoine Levy-Lambert wrote:
>
> >>--- Urspr�ngliche Nachricht ---
> >>Von: Eric Tchepannou <[EMAIL PROTECTED]>
> >>An: [email protected]
> >>Betreff: Re: What is the difference between a nested element and a nested
> >>type?
> >>Datum: Thu, 9 Jun 2005 10:32:51 +0100
> >>
> >>Thanks a lot for that Antoine. That was very clear to me.
> >>I was able to check at
> >>http://www.oracle.com/technology/pub/articles/bodewig_taskwriters.html
> >>and I think the correct syntax (at least the one used there) to nest
> >>types is
> >>public void addSomething(BaseType t);
> >>
> >>
> >this one means :
> > - map <something/> to instantiating BaseType
> > - and creates the BaseType from the nested element <something/>
> >
> >
> >>I have been using
> >>public void add(BaseType);
> >>and experience problems with this syntax. I will later rewrite my code
> >>accordingly and see how it behaves.
> >>
> >>My guess is that public void add(BaseType) is obsolete. I use 1.6.2. I
> >>am just wondering why the Ant documentation keeps mentioning this...
> >>
> >>
> >>
> >No, it is not obsolete, but it will only work if you are mapping BaseType to
> >an XML tag name such as <basetype/> using the <typedef/> task before.
> >
> >
> And one can used types that derive from the base type as follows (continuing
> my previous example):
> ----- Derived.java ----
> package my;
>
> public class Derived extends Type {
> }
>
> ----- build.xml -----
> ...
> <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"/>
> <typedef name="derived" classname="my.Derived"
> loaderref="my.loaderref"/>
> <task>
> <type/>
> </task>
> <task>
> <derived/>
> </task>
> </target>
> ...
>
>
> However this may be not what you want to do. One
> can just use nested elements discoved by reflection as
> Antonie has shown above.
>
> ---- Reflect.java --
> package my;
>
> public class Reflect extends org.apache.tools.ant.Task {
> public void addBase(Type p) {
> }
> public void addDerived(Derived p) {
> }
> }
>
> ---- build.xml ---
> ..
> <target name="reflect" depends="compile">
> <taskdef name="reflect" classname="my.Reflect"
> classpath="classes" loaderref="my.loaderref"/>
> <reflect>
> <base/>
> <derived/>
> </reflect>
> </target>
> ..
>
> Peter
Hi Peter,
As my base class is an abstract class, I have no interest to use a <base />
My hope is to do the following:
---- Reflect.java --
package my;
public class Reflect extends org.apache.tools.ant.Task {
List types = new ArrayList();
public void add(BaseType bt) {
types.add(bt);
}
}
----BaseType.java------
package my;
public abstract BaseType implements IType {
...
}
----ConcreteType1|2.java------
package my;
public ConcreteType1|2 extends BaseType {
...
}
---- build.xml ---
<target name="reflect" depends="compile">
<taskdef name="reflect" classname="my.Reflect"
classpath="classes" loaderref="my.loaderref"/>
<typedef name="concete1|2" classname="my.ConcreteType1|2"
classpath="classes" loaderref="my.loaderref"/>
<reflect>
<concrete1/>
<concrete2/>
</reflect>
</target>
..
Does this make sense?
> >
> >
> >>Eric
> >>
> >>
> >>
> >Antoine
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Best Regards,
Eric Tchepannou
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]