ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: Custom data type problem
Date Tue, 13 May 2003 08:24:11 GMT
Sorry, I still do not see the problem..

I tried your code and addText() has been called
before addConfiguredValue() is called.

:MyData2.java:
import org.apache.tools.ant.types.DataType;

public class MyData2 extends DataType {
    private String id;
    private String text;
    private MyValue2 value;

    public MyData2() {
    }
    public void addConfiguredValue( MyValue2 value ) {
        System.out.println(
            "MyData2: AddConfiguredValue: value is "
            + value.toString());
         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(
             "text is " + text + " Late resolve: "+value );
         return text;
     }
}

:MyValue2.java:
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Reference;
public class MyValue2 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 ((MyData2)id.getReferencedObject( getProject()
                                                    )).toString();
        }
        if( sb.length() == 0 ) {
            return null;
        }
        return sb.toString();
    }
}

:MyExec2.java:
import org.apache.tools.ant.Task;

 public class MyExec2 extends Task {
     public void addConfiguredValue(MyValue2 v) {
         System.out.println("v is " + v);
     }
 }

:build.xml:
<project name="t" default="t">
  <target name="t">
    <delete dir="classes" quiet="yes"/>
    <mkdir dir="classes"/>
    <javac srcdir="src" destdir="classes"/>
    <typedef name="mydata2" classname="MyData2"
             classpath="classes" loaderref="classes"/>
    <taskdef name="myexec2" classname="MyExec2"
             classpath="classes" loaderref="classes"/>


    <mydata2 id="data2">
      <value>value 1</value>
      <value>value 2</value>
    </mydata2>

    <myexec2>
      <value usedata="data2"/>
    </myexec2>
  </target>
</project>

:output is:
   [delete] Deleting directory /home/preilly/proj/learning/custom/classes
    [mkdir] Created dir: /home/preilly/proj/learning/custom/classes
    [javac] Compiling 6 source files to 
/home/preilly/proj/learning/custom/classes
  [mydata2] MyData2: AddConfiguredValue: value is value 1
  [mydata2] MyData2: AddConfiguredValue: value is value 2
  [mydata2] text is value 2 Late resolve: value 2
  [myexec2] text is value 2 Late resolve: value 2
  [myexec2] v is value 2


Peter.

On Monday 12 May 2003 17:44, Tony Thompson wrote:
> I am not having an issue with multiple values.  I was just saying that I
> couldn't do something like this:
>
> <data id="fred">Value 1.</data>
>
> because I need to be able to keep track of individual values, like
> this:
>
> <data id="fred">
>    <value>Value 1.</value>
>    <value>Value 2.</value>
>    <value>Value 3.</value>
> </data>
>
> I can keep track of the individual values without an issue.  The
> problem is when I addConfiguredValue() to "data", the addText() method
> of "value" hasn't executed yet so, addConfiguredValue() thinks the
> "value" is null.  The modified example that I sent demonstrates the
> issue.  If I hold on to "value" until later, addText() has been called
> and it works.
>
> Tony


Mime
View raw message