Blame | Last modification | View Log | RSS feed
/*** AntShield - A project release tool for ant.*/package com.erggroup.mass.ant;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.Project;import org.apache.tools.ant.types.FileList;import org.apache.tools.ant.types.FileSet;import org.apache.tools.ant.types.DirSet;import java.util.ArrayList;import java.util.Iterator;import java.util.TreeSet;/*** Implements the AntShield task's nested field tag.*/public class FieldElement{private AntShield parent = null;private Project project = null;private String name = null;private String prompt = null;private String defaultValue = null;private String value = null;private ArrayList options = new ArrayList();private ArrayList filelist = new ArrayList();private TreeSet fileset = new TreeSet();private TreeSet dirset = new TreeSet();/*** Constructor.* @param a*/public FieldElement(AntShield a, Project p){parent = a;project = p;}/*** Set the name property.* @param s*/public void setName(String s){name = s;}/*** Set the prompt property.* @param s*/public void setPrompt(String s){prompt = s;}/*** Set the defaultValue property.* @param s*/public void setDefaultValue(String s){defaultValue = project.replaceProperties( s );}/*** Set the value property - internal use only.* @param s*/public void setValue(String s){value = s;}/*** Create, store and return an option nested tag.* @return*/public OptionElement createOption(){OptionElement option = new OptionElement(this);options.add(option);return option;}/*** Adds a fileset nested tag.* @return*/public void addConfiguredFilelist(FileList list){String[] files = list.getFiles(project);for (int i = 0; i < files.length; i++){filelist.add(new String(files[i]));}}/*** Adds a fileset nested tag.* @return*/public void addConfiguredFileset(FileSet set){String[] files = set.getDirectoryScanner(project).getIncludedFiles();for (int i = 0; i < files.length; i++){fileset.add(new String(files[i]));}}/*** Adds a dirset nested tag.* @return*/public void addConfiguredDirset(DirSet set){String[] dirs = set.getDirectoryScanner(project).getIncludedDirectories();for (int i = 0; i < dirs.length; i++){dirset.add(new String(dirs[i]));}}/*** Return this field's name.* @return*/public String getName(){return name;}/*** Return this field's prompt.* @return*/public String getPrompt(){return prompt;}/*** Return this field's default value.* @return*/public String getDefaultValue(){return defaultValue;}/*** Return this field's value.* @return*/public String getValue(){return value;}/*** Return this field's nested options.* @return*/public TreeSet getOptions(){TreeSet optionset = new TreeSet();Iterator i;//add optionsi = options.iterator();while (i.hasNext()){OptionElement o = (OptionElement)i.next();optionset.add(o.getValue());}//add filelistsi = filelist.iterator();while (i.hasNext()){optionset.add(i.next());}//add filesetsi = fileset.iterator();while (i.hasNext()){optionset.add(i.next());}//add dirsetsi = dirset.iterator();while (i.hasNext()){optionset.add(i.next());}return optionset;}/*** Get the task name from the parent.* @return*/public String getTaskName(){return parent.getTaskName();}/*** Check the parameters of this field, and all nested options and paths.*/public void check(){if ((name == null) || (name.length() == 0) || (prompt == null) || (prompt.length() == 0)){throw new BuildException("<" + parent.getTaskName() + "> Invalid field specification");}Iterator i = options.iterator();while (i.hasNext()){OptionElement o = (OptionElement)i.next();o.check();}}}