ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scabbage <guans...@gmail.com>
Subject Re: Question about simple nested text elements
Date Fri, 05 Feb 2010 23:40:33 GMT

Sorry, the code i posted above has some typos. Here's the correct one:


import java.util.ArrayList;
import java.util.List;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.DataType;

public class MyTask extends Task {
    private List<String> things = new ArrayList<String>();

    public void execute() {
        for (String t : things)
            System.out.println (t);   
    }
    public void  addThings(Things things) {
        for (Thing t : things.getThings())            
            this.things.add(t.getName());
    }
    public class Things extends DataType {
        private List<Thing> things = new ArrayList<Thing>();

        public List<Thing> getThings() {            
              return things;
        }        
        public void addThing (Thing f) {            
            things.add(f);        
        }    
    }    
    public class Thing extends DataType {
        private String name;        
        public void addText(String name) {
            Project p = getProject();            
            this.name = p.replaceProperties(name);
        }        

        public String getName() {
            return name;        
        }
    }

}

Thanks.

David


scabbage wrote:
> 
> I'm trying to create my own customized task in Ant 1.7.1. I would like to
> use my task this way:
> 
> <mytask a="blah" b="foo">
>    <things>
>       <thing>xxx</thing>
>       <thing>yyy</thing>
>       <thing>zzz</thing>
>    </things>
> </mytask>
> 
> My class looks like:
> 
> public class MyTask extends Task {
>    private String a;
>    private String b;
>    private List<String> things = new ArrayList<String>();
> 
>    // setting and gettings for a and b ...
> 
>    public void execute() {
>       // loop through things
>    }
> 
> }
> 
> Now can anyone tell me how I should write the setter for "things"? The Ant
> doc is very vague about simple nested text elements.
> 
> Thanks.
> 
> David
> 

-- 
View this message in context: http://old.nabble.com/Question-about-simple-nested-text-elements-tp27460186p27475534.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message