ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesse Glick <Jesse.Gl...@netbeans.com>
Subject Re: developing Tasks, createElement, addElement ?
Date Mon, 26 Feb 2001 15:54:37 GMT
> At 09:02  23/2/01 -0500, Fernando Padilla wrote:
> >Some use the createElementName() methods, while others use
> >addElementName( Element ) methods.  And I am wondering what are the pros
> >and cons.

Peter Donald wrote:
> org.apache.tools.ant.IntrospectionHelper is where it is done. Which to use
> is a matter of preference. Part of it is backwards compatability and
> avoiding massive refactoring. createFoo() style basically is to make it
> easier to auotmatically do things at sub-objects lifecycle start.

While we're on the subject, something I just recently noticed: addFoo() does
*not* initialize the object before adding it. I.e. for code like this:

<mytask>
  <element foo="bar">
    <subelement/>
  </element>
</mytask>

If you write Element MyTask.createElement(), you are probably expecting it to
be an uninitialized new Element(); you held some reference to it and
Element.setFoo("bar") and Element.createSubelement() are called later. Fine.

If you write it as void MyTask.addElement(Element el), what you are probably
not expecting is that el will still be uninitialized! Again its properties and
subelements are created later. This can be quite inconvenient. Say you are
constructing some commandline and each <element/> gives a parameter or two.
You have to keep a Vector of Element's and analyze them later, in execute(). I
would have expected that the Element el would be all set to go when addElement
is called.

According to develop.html, I guess this is the documented behavior. But it
seems counterintuitive enough to merit a stronger warning in the docs. I'm not
clear on whether changing the behavior would break existing tasks or not.

-Jesse

-- 
Jesse Glick   <mailto:Jesse.Glick@netbeans.com>
NetBeans, Open APIs  <http://www.netbeans.org/>
tel (+4202) 3300-9161 Sun Micro x49161 Praha CR

Mime
View raw message