You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Tony Thompson <to...@stone-ware.com> on 2003/05/09 21:09:20 UTC

Custom data type problem

I created my own custom data type that handles a data type that looks
something like this:

<mytype>
    <attribute>
        <value>Value 1</value>
        <value>Value 2</value>
    </attribute>
</mytype>

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

Re: Custom data type problem

Posted by peter reilly <pe...@corvil.com>.
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:
<project name="t" default="t">
  <target name="t">
    <mkdir dir="classes"/>
    <javac srcdir="src" destdir="classes"/>
    <taskdef name="myexec" classname="MyExec"
             classpath="classes"/>
    <myexec>
      <value>Hello world</value>
    </myexec>
  </target>
</project>

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:
>
> <mytype>
>     <attribute>
>         <value>Value 1</value>
>         <value>Value 2</value>
>     </attribute>
> </mytype>
>
> 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: user-help@ant.apache.org