You should only have one of: addXXX or createXXX (or now addConfiguredXXX).
You have two for Descriptors. What is the exact problem you're having?
Erik
----- Original Message -----
From: "Leonardo Andersen Lopes" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, April 22, 2002 6:21 AM
Subject: Problems creating a task
> HiALL,
>
> I have a problem to create a task with nested elements.
> i don't have ideia whats happen.
>
> archive attached.
>
> thankz a lot!
>
> --
> ===========================
> Leonardo Andersen Lopes
> Florianopolis - SC - Brasil
> e-mail: [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> ===========================
>
>
----------------------------------------------------------------------------
----
> package br.com.perfiltecnologia.codegen;
>
> import org.apache.tools.ant.*;
> import org.apache.tools.ant.types.*;
> import org.apache.tools.ant.taskdefs.MatchingTask;
> import java.io.*;
> import java.util.*;
>
> public class TaskXML2Java extends MatchingTask {
> protected Elemento desc, templ;
>
> public Elemento createDescriptors() {
> if (desc == null)
> desc = new Elemento();
> return desc;
> }
>
> public void addDescriptors(Elemento de){
> desc = de;
> }
>
> public Elemento getDescriptors(){
> return desc;
> }
>
> public void execute() throws BuildException {
> if (desc.usedMatchingTask) {
> log("DEPRECATED - Use of the implicit FileSet is deprecated.
Use a nested fileset element instead.");
> }
>
> if (desc.file == null && desc.dir == null && desc.filesets.size()
== 0) {
> throw new BuildException("At least one of the file or dir
attributes, or a fileset element, must be set.");
> }
>
> if (desc.quiet && desc.failonerror) {
> throw new BuildException("quiet and failonerror cannot both be
set to true",
> location);
> }
>
>
> // delete the single file
> if (desc.file != null) {
> if (desc.file.exists()) {
> if (desc.file.isDirectory()) {
> log("Directory " + desc.file.getAbsolutePath() + "
cannot be removed using the file attribute. Use dir instead.");
> } else {
> log("Achado: " + desc.file.getAbsolutePath());
> }
> } else {
> log("Could not find file " + desc.file.getAbsolutePath() +
" to delete.",
> org.apache.tools.ant.Project.MSG_VERBOSE);
> }
> }
>
> // delete the files in the filesets
> for (int i=0; i<desc.filesets.size(); i++) {
> FileSet fs = (FileSet) desc.filesets.elementAt(i);
> try {
> DirectoryScanner ds = fs.getDirectoryScanner(project);
> String[] files = ds.getIncludedFiles();
> String[] dirs = ds.getIncludedDirectories();
> showFiles(fs.getDir(project), files, dirs);
> } catch (BuildException be) {
> // directory doesn't exist or is not readable
> if (desc.failonerror) {
> throw be;
> } else {
> log(be.getMessage(),
> desc.quiet ?
org.apache.tools.ant.Project.MSG_VERBOSE :
org.apache.tools.ant.Project.MSG_WARN);
> }
> }
> }
>
> // delete the files from the default fileset
> if (desc.usedMatchingTask && desc.dir != null) {
> try {
> DirectoryScanner ds = super.getDirectoryScanner(desc.dir);
> String[] files = ds.getIncludedFiles();
> String[] dirs = ds.getIncludedDirectories();
> showFiles(desc.dir, files, dirs);
> } catch (BuildException be) {
> // directory doesn't exist or is not readable
> if (desc.failonerror) {
> throw be;
> } else {
> log(be.getMessage(),
> desc.quiet ?
org.apache.tools.ant.Project.MSG_VERBOSE :
org.apache.tools.ant.Project.MSG_WARN);
> }
> }
> }
> }
>
> //************************************************************************
> // protected and private methods
> //************************************************************************
>
> /**
> * remove an array of files in a directory, and a list of
subdirectories
> * which will only be deleted if 'includeEmpty' is true
> * @param d directory to work from
> * @param files array of files to delete; can be of zero length
> * @param dirs array of directories to delete; can of zero length
> */
> protected void showFiles(File d, String[] files, String[] dirs) {
> if (files.length > 0) {
> log("Mostrando " + files.length + " files from " +
d.getAbsolutePath());
> for (int j=0; j<files.length; j++) {
> File f = new File(d, files[j]);
> log("Mostrando " + f.getAbsolutePath());
> }
> }
>
> if (dirs.length > 0 && desc.includeEmpty) {
> int dirCount = 0;
> for (int j=dirs.length-1; j>=0; j--) {
> File dir = new File(d, dirs[j]);
> String[] dirFiles = dir.list();
> if (dirFiles == null || dirFiles.length == 0) {
> log("Mostrando " + dir.getAbsolutePath(),
desc.verbosity);
> dirCount++;
> }
> }
>
> if (dirCount > 0) {
> log("Mostrado " + dirCount + " director" +
> (dirCount==1 ? "y" : "ies") +
> " from " + d.getAbsolutePath());
> }
> }
> }
> }
>
> class Elemento extends MatchingTask{
> protected File file = null;
> protected File dir = null;
> protected Vector filesets = new Vector();
> protected boolean usedMatchingTask = false;
> protected boolean includeEmpty = false; // by default, remove
matching empty dirs
>
> protected int verbosity = org.apache.tools.ant.Project.MSG_VERBOSE;
> protected boolean quiet = false;
> protected boolean failonerror = true;
>
> public Elemento(){
> }
>
> public void setFile(File file) {
> this.file = file;
> }
>
> public void setDir(File dir) {
> this.dir = dir;
> }
>
> public void setVerbose(boolean verbose) {
> if (verbose) {
> this.verbosity = org.apache.tools.ant.Project.MSG_INFO;
> } else {
> this.verbosity = org.apache.tools.ant.Project.MSG_VERBOSE;
> }
> }
>
> public void setQuiet(boolean quiet) {
> this.quiet = quiet;
> if (quiet) {
> this.failonerror = false;
> }
> }
>
> public void setFailOnError(boolean failonerror) {
> this.failonerror=failonerror;
> }
>
>
> public void setIncludeEmptyDirs(boolean includeEmpty) {
> this.includeEmpty = includeEmpty;
> }
>
> public void addFileSet(FileSet set) {
> filesets.addElement(set);
> }
>
> public PatternSet.NameEntry createInclude() {
> usedMatchingTask = true;
> return super.createInclude();
> }
>
> public PatternSet.NameEntry createExclude() {
> usedMatchingTask = true;
> return super.createExclude();
> }
>
> public PatternSet createPatternSet() {
> usedMatchingTask = true;
> return super.createPatternSet();
> }
>
> public void setIncludes(String includes) {
> usedMatchingTask = true;
> super.setIncludes(includes);
> }
>
> public void setExcludes(String excludes) {
> usedMatchingTask = true;
> super.setExcludes(excludes);
> }
>
> public void setDefaultexcludes(boolean useDefaultExcludes) {
> usedMatchingTask = true;
> super.setDefaultexcludes(useDefaultExcludes);
> }
>
> public void setIncludesfile(File includesfile) {
> usedMatchingTask = true;
> super.setIncludesfile(includesfile);
> }
>
> public void setExcludesfile(File excludesfile) {
> usedMatchingTask = true;
> super.setExcludesfile(excludesfile);
> }
>
> }
>
>
----------------------------------------------------------------------------
----
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>