Return-Path: Mailing-List: contact user-help@ant.apache.org; run by ezmlm Delivered-To: mailing list user@ant.apache.org Received: (qmail 84041 invoked from network); 26 Feb 2003 18:00:32 -0000 Received: from junior.lgc.com (134.132.72.99) by daedalus.apache.org with SMTP; 26 Feb 2003 18:00:32 -0000 Received: from lgchvw01.lgc.com (lgchvw01.lgc.com [134.132.93.107]) by junior.lgc.com (8.11.3/8.11.3) with SMTP id h1QHxUB20052 for ; Wed, 26 Feb 2003 11:59:30 -0600 (CST) Received: from 134.132.93.152 by lgchvw01.lgc.com (InterScan E-Mail VirusWall NT); Wed, 26 Feb 2003 12:00:35 -0600 Received: by lgchexchbh.ad.lgc.com with Internet Mail Service (5.5.2653.19) id <1C73VHCM>; Wed, 26 Feb 2003 12:00:34 -0600 Message-ID: From: Dominique Devienne To: "'Ant Users List'" Subject: RE: question Date: Wed, 26 Feb 2003 12:00:33 -0600 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Stefan talked about adding a condition at one point, but I'm not sure if it's in 1.5+ or 1.6, and whether it supports a type attribute to enforce the reference being of a given type. --DD -----Original Message----- From: Steve Cohen [mailto:SCohen@sportvision.com] Sent: Wednesday, February 26, 2003 11:57 AM To: Ant Users List Subject: RE: question Ah, so you're talking about writing a task in java. I take it that there is no way to accomplish this using the collection of tasks and types that are included in the ant distribution? -----Original Message----- From: Dominique Devienne [mailto:DDevienne@lgc.com] Sent: Wednesday, February 26, 2003 11:40 AM To: 'Ant Users List' Subject: RE: question Here's the pattern I've been using myself... --DD public class MyTask extends Task { private MyAttr _myAttr; public void setMyAttrRef(String attrRef) { _myAttr = (MyAttr)assertReferenceType(getProject(), attrRef, MyAttr.class, ""); } private static Object assertReferenceType(Project prj, String ref, Class cls, String name) { Object o = prj.getReference(ref); if (o == null) { throw new BuildException("Reference " + ref + " not found!"); } if (!cls.isAssignableFrom(o.getClass())) { throw new BuildException(ref + " not a " + name + " reference!"); } return o; } } PS: Usually, MyAttr would extend DataType. -----Original Message----- From: Erik Hatcher [mailto:jakarta-ant@ehatchersolutions.com] Sent: Wednesday, February 26, 2003 11:26 AM To: Ant Users List Subject: Re: question On Wednesday, February 26, 2003, at 12:16 PM, Steve Cohen wrote: > So is there really no way to write a generic task that does something > with a fileset if it is defined but nothing if it is not? Or can I > get around this by introducing a "default" empty definition of the > reference? Do references work like properties - first one to define > it keeps it? Or are they handled differently? You could always write your task to take a String argument that represents the refid, and then look it up internally and deal with its potential non-existence yourself. I'm not sure, without digging a bit, whether using a Reference type or not would do the trick, but it might. Erik --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org