ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Tchepannou <melli...@gmail.com>
Subject Re: What is the difference between a nested element and a nested type?
Date Thu, 09 Jun 2005 09:32:51 GMT
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);

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

Eric

On 6/9/05, Antoine Levy-Lambert <antoine@gmx.de> wrote:
> Hello Eric,
> 
> a type in ant's vocabulary is a class designed to hold data, as opposed to a
> task which is a task designed to execute something.
> 
> The expression "nested element" is XML, not ant specific.
> nested elements of tasks are always types.
> 
> So there is no contradiction between the concept of nested element (XML) and
> the concept of type.
> 
> This syntax :
> >     public MyConcreteType createConcreteType() {
> goes together with having a nested element
> <concretetype ...
> 
> The concretetype nested element in this case does not need to be declared by
> a typedef task invocation.
> 
> I would encourage you to use typedef and
> this syntax
> >     public void add(MyTypeBase c) {
> 
> if you do
> <typedef name="somedata" classname="com.company.MyTypeBase"/>
> 
> then nest
> <somedata ...
> in your build file in the task invocation, ant will call add(MyTypeBase c).
> Not sure though if the syntax public void add(MyTypeBase c) is supported by
> Ant 1.5
> 
> What works in Ant 1.5 is
> 
> public void addSomething(MyTypeBase c)
> 
> which will then instantiate MyTypeBase if you nest
> <something ..../>
> and does not require a typedef either.
> 
> Antoine
> 
> > --- Urspr√ľngliche Nachricht ---
> > Von: Eric Tchepannou <mellists@gmail.com>
> > An: user@ant.apache.org
> > Betreff: What is the difference between a nested element and a nested
> > type?
> > Datum: Thu, 9 Jun 2005 09:51:11 +0100
> >
> > Hi all,
> >
> > I was wondering if someone could enlighten me on this?
> > I tried to implement a custom type and use it in my build file but
> > everytime I get the error message that the nested "Element" is not
> > supported by the task.
> > Basically, I have something like this:
> >
> > public class MyTask extends Task {
> >     private List myTypes = new ArrayList();
> >
> >     public void add(MyTypeBase c) {
> >         myTypes.add(c);
> >     }
> >
> >     public void execute() {
> >      ...
> >     }
> > }
> >
> > I use it as follow in the buildfile:
> >
> > <target ...>
> >     <taskdef name="mytask".../>
> >     <typedef name="mytype" class="MyConcreteType" />
> >     <mytask>
> >         <mytype .../>
> >     </mytask>
> > </target>
> >
> > where MyConcreteType is a subclass of MyBaseType. This donot work. I
> > can only make it work if I write it as
> >
> > public class MyTask extends Task {
> >     private List myTypes = new ArrayList();
> >
> >     public MyConcreteType createConcreteType() {
> >         MyConcreteType c = new ...
> >         myTypes.add(c);
> >         return c;
> >     }
> >
> >     public void execute() {
> >      ...
> >     }
> > }
> >
> > As far as I understand the short tutorial in the manual, the second
> > implementation is the implementation of nested elements and the first
> > is the one of the nested types. I am a little bit confused about what
> > is an element, a type in the ant context.
> > The deal is that I would rather have a type and not an element,
> > because with an element, I would have to write for each concrete type
> > the corresponding createXXX() method.
> >
> > --
> > Best Regards,
> > Eric Tchepannou
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> 


-- 
Best Regards,
Eric Tchepannou

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


Mime
View raw message