Return-Path: Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Delivered-To: mailing list dev@ant.apache.org Received: (qmail 26302 invoked from network); 21 May 2003 08:31:34 -0000 Received: from k100-37.bas1.dbn.dublin.eircom.net (HELO corvil.com.) (159.134.100.37) by daedalus.apache.org with SMTP; 21 May 2003 08:31:34 -0000 Received: from preilly.local.corvil.com (preilly.local.corvil.com [172.18.1.173]) by corvil.com. (8.12.5/8.12.5) with ESMTP id h4L8Vkpg076771 for ; Wed, 21 May 2003 09:31:46 +0100 (IST) (envelope-from peter.reilly@corvil.com) Content-Type: text/plain; charset="iso-8859-1" From: peter reilly Organization: corvil To: Ant Developers List Subject: Re: Free-form ANT Task Structure Date: Wed, 21 May 2003 09:36:33 +0100 User-Agent: KMail/1.4.3 References: <200305201717.51161.peter.reilly@corvil.com> In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200305210936.33340.peter.reilly@corvil.com> X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Here is a simple example task: import java.util.*; import org.apache.tools.ant.DynamicConfigurator; import org.apache.tools.ant.Task; public class Dy extends Task implements DynamicConfigurator { private String subName; private Map attributes =3D new HashMap(); private List elements =3D new ArrayList(); =20 public Object createDynamicElement(String name) { Dy dy =3D new Dy(); dy.setSubName(name); dy.setProject(getProject()); elements.add(dy); return dy; } private void setSubName(String subName) { this.subName =3D subName; } private String getSubName() { return subName; } =20 public void setDynamicAttribute(String name, String value) { attributes.put(name, value); } private void print(int level) { StringBuffer b =3D new StringBuffer(); for (int i =3D 0; i < level; ++i) { b.append(" "); } String indent =3D b.toString(); for (Iterator i =3D attributes.entrySet().iterator(); i.hasNext()= ;) { Map.Entry e =3D (Map.Entry) i.next(); log(indent + e.getKey() + " =3D " + e.getValue()); } for (Iterator i =3D elements.iterator(); i.hasNext();) { Dy dy =3D (Dy) i.next(); log(indent + "element " + dy.getSubName()); dy.print(level + 1); } } =20 public void execute() { log("Dy"); print(1); } } and the build.xml: generates: Compiling 1 source file to /home/preilly/proj/learning/dy/classes Dy element integration-test element test on-components =3D foo,bar element include name =3D **/XYZComp/*Test element configuration element xyz-comp id =3D foo element zyx-comp id =3D bar element arbitrary value =3D null Peter. On Tuesday 20 May 2003 17:38, Berin Loritsch wrote: > peter reilly wrote: > > To embed the config information, the easiest > > is to map the info to objects. > > > > Ant introspection is very powerfull and easy > > to use for normal java data object. > > The problem is that it only works when you know in advance > what the configuration elements are going to be. In this > example, that is not the case. > > > Alternatively one can use the DynamicConfigurator > > interface. This provides the name of the unknown element > > and the name/value of unknown attributes. > > That might be something worth pursuing. Now, can I have > a mixture of DyanimicConfigurator objects and mapped > objects in the *same* task? Yes. > > Or more importantly as a child of one of the mapped > objects? Yes - you may implement what you want. Ant's introspection looks add the addX and setX patterns before handing the element/attribute over to DynamicConfigurator. > > For example: > > > > > > > > > > > > > > The child of the element is completely > free-form, although the rest of the task elements would > map to real objects. > > Is there an Task already written that uses the DynamicConfigurator > where I can see how it works with it? > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org > For additional commands, e-mail: dev-help@ant.apache.org