Return-Path: Mailing-List: contact user-help@ant.apache.org; run by ezmlm Delivered-To: mailing list user@ant.apache.org Received: (qmail 59116 invoked from network); 12 May 2003 15:59:47 -0000 Received: from ip196.arborofficecenters.com (HELO mail.stone-ware.com) (216.136.78.196) by daedalus.apache.org with SMTP; 12 May 2003 15:59:47 -0000 Received: from StonewareDom-MTA by mail.stone-ware.com with Novell_GroupWise; Mon, 12 May 2003 10:59:47 -0500 Message-Id: X-Mailer: Novell GroupWise Internet Agent 6.0.1 Date: Mon, 12 May 2003 10:59:30 -0500 From: "Tony Thompson" To: , Subject: Re: Custom data type problem Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Spam-Rating: daedalus.apache.org 1.6.2 500/1000/N I modified your example to model the type of thing that I am doing that also demonstrates the issue that I am having. The problem is, I need to have more than one value declared as part of the "data" type: Value 1. Value 2. Value 3. Thank you for your continued help. Tony >>> peter.reilly@corvil.com 05/12/03 10:34AM >>> I would not use another class for the referenced type and the normal attribute in ant for reference is "refid", also the setid method is not needed as this is done by ant xml parsing and not as part of the introspection of the class. : MyValue.java : import org.apache.tools.ant.ProjectComponent; import org.apache.tools.ant.types.Reference; public class MyValue extends ProjectComponent { private String text; public void addText(String text) { this.text = text; } public void setRefId(Reference id) { this.text = id.getReferencedObject(getProject()).toString(); } public String toString() { return text; } } or using a DataType import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.DataType; public class MyValue extends DataType { private String text; public void addText(String text) { this.text = text; } public String toString() { if (isReference()) { return ref.getReferencedObject(getProject()).toString(); } return text; } } Build script: Hello Fred Peter. On Monday 12 May 2003 15:51, Tony Thompson wrote: > That works for me as well but, your example is not quite like the issue > I described. I was able to do some more work to figure out that if I > hold on to the "Value" object and get the text just before I need it, it > is there (see the toString() method in MyData). > > Here is the example: > > import org.apache.tools.ant.Task; > > public class MyExec extends Task { > public void addConfiguredValue(MyValue v) { > System.out.println("v is " + v); > } > } > > ************************************************************** > > import org.apache.tools.ant.types.DataType; > > public class MyData extends DataType { > private String id; > private String text; > private MyValue value; > > public MyData() { > } > > public void addConfiguredValue( MyValue value ) { > text = value.toString(); > this.value = value; > } > > public void setId( String id ) { > this.id = id; > } > > public String getId() { > return id; > } > > public String toString() { > System.out.println( "Late resolve: "+value ); > return text; > } > } > > ************************************************************* > > import org.apache.tools.ant.Task; > import org.apache.tools.ant.types.Reference; > > public class MyValue extends Task { > private StringBuffer sb = new StringBuffer(); > private Reference id; > > public void addText(String text) { > sb.append( text ); > } > > public void setUseData( Reference id ) { > this.id = id; > } > > public String toString() { > if( id != null ) { > return ((MyData)id.getReferencedObject( getProject() > )).toString(); > } > > if( sb.length() == 0 ) { > return null; > } > > return sb.toString(); > } > } > > ************************************************************* > > Here is what you would need in the script: > > > > > This is data text. > > > > > > > > >>> peter.reilly@corvil.com 05/12/03 03:10AM >>> > > I do not see this problem. > > :MyExec.java: > > import org.apache.tools.ant.Task; > > public class MyExec extends Task { > public void addConfiguredValue(MyValue v) { > System.out.println("v is " + v); > } > public static class MyValue { > private String text; > > public void addText(String text) { > this.text = text; > } > > public String toString() { > return text; > } > } > } > > :build.xml: > > > > > > classpath="classes"/> > > Hello world > > > > > This outputs: > v is Hello world > > Tested with ant 1.5.3-1 and 1.5.2 > > Peter > > On Friday 09 May 2003 20:09, Tony Thompson wrote: > > I created my own custom data type that handles a data type that > > looks > > > something like this: > > > > > > > > Value 1 > > Value 2 > > > > > > > > My "Value" class has the following methods: > > > > { > > ... > > public void addText( final String text ) { > > m_value.append( text ); > > } > > > > public String toString() { > > return m_value.toString(); > > } > > } > > > > My "Attribute" class has a method to add configured "Value" objects: > > > > public final void addConfiguredValue( final Value value ) { > > m_values.add( value.toString() ); > > } > > > > When I call value.toString() at this time, Value.addText() has not > > been > > > invoked yet so the string is empty. I thought that the > > addConfiguredXXX() methods were supposed to add already configured > > objects. What should I change to make this behave properly? > > > > I am using version 1.5.3. > > > > Thanks. > > Tony > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org > > For additional commands, e-mail: als.ant.Task; > import org.auser-help@ant.apache.org > > --------------------------------------------------------------------- > 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 --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org