ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: Roles (was: antlib)
Date Thu, 01 May 2003 08:19:26 GMT
On Wednesday 30 April 2003 19:33, Jose Alberto Fernandez wrote:
> > From: peter reilly [mailto:peter.reilly@corvil.com]
> >
> > On Wednesday 30 April 2003 16:24, Stefan Bodewig wrote:
> > > On Tue, 29 Apr 2003, peter reilly <peter.reilly@corvil.com> wrote:
> > > >> it is, with an addXYZ(Condition) method marking it up - I'm not
> > > >> really fond of any of the proposed naming conventions so far.
> > > >
> > > > Whats wrong with add(Condition) ?
> > >
> > > Nothing so far.
> >
> > The only problem I can think of is that it clashes with
> > Collection.add(Object) and thus the problem is that
> > classes may implement it "by accident". I my
> > implementation (bugzilla 19446), I use the signature
> > nestedElement(Class), but I would be happy with anything.
>
> how about addConfigured(Class), we already use this prefix
> so it should not be too much clashes to worry about.

There is a difference between add[Name](Class) and addConfigured[Name](Class).

The first is invoked after the object has been created but before the
attributes and nested elements of the xml element have been processed.
The second is invoked after the attributes and nested elements have been
processed.

Both have their uses. Most of the tasks and datatypes use the
first form. Some use the second form for example : 
filters.ReplaceTokens#addConfiguredToken(Token).

add(Class) is easy to implement in IntrospectionHelper - only
#createElement needs to be modified when processing the element.
The second is a little more tricky, as #storeElement needs to be
modified and it has to use the same context as #createElement - it
cannot simply lookup the name and methods again as
they may have changed in processing other nested elements.

As an interesting side-note, addTask(Task) in TaskContainer is called
before the object is created(!).

In fact, the code in UnknownElement#handleChildren/IH#supportsNestedElement
means that one cannot use DynamicElementConfigurator or
my current implementation of add(Class) in a TaskContainer.

For example:
public class MyDynClass  extends Sequential implements DynamicConfigurator
{
    public void setDynamicAttribute(String name, String value)    {
        System.out.println("name is " + name);
    }

    public Object createDynamicElement(String name) {
        throw new BuildException(name + " is not handled");
    }
}

when used like:
  <taskdef name="mydynclass" classname="MyDynClass" classpath="classes"/>
  <mydynclass>
    <echo>Hello World</echo>
  </mydynclass>

causes the build exception "echo is not handled"

Peter


Mime
View raw message