You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jeroen Breedveld <je...@x-hive.com> on 2003/05/08 15:35:12 UTC

Question about TaskContainer implementation

Hi all,

I've created an implementation of the TaskContainer interface for my
company's database with the purpose of running several tasks in one
(database) session.
The problem is that when I use this taskcontainer the embedded task are
not performed although I'm sure the perform() method is called on these
tasks (see output).
Can anyone tell me what I am doing wrong?

Also when I use the log method from a taskcontainer the name of the task
doesn't appear in the output (see the output) but instead "null". What's
causing this?

Best regards,

Jeroen Breedveld

--

X-Hive Corporation
e-mail: jeroenb@x-hive.com
phone: +31 10 2818080
http://www.x-hive.com 

=======
OUTPUT:

C:\cvs\xhive-ant\bin>ant -f tests.xml test-session
Buildfile: tests.xml

init:
Overriding previous definition of reference to test.federation
Overriding previous definition of reference to test.database
Overriding previous definition of reference to test.database2

test-session:
     [null] executing task
     [null] executing task

BUILD SUCCESSFUL
Total time: 2 seconds

=====
CODE:

package com.xhive.anttasks.types;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.TaskContainer;
import org.apache.tools.ant.types.Reference;

import java.util.Enumeration;
import java.util.Vector;

public class Session extends Task implements TaskContainer {

  private Vector nestedTasks = new Vector();
  private Database database = null;

  public void addTask(Task nestedTask) throws BuildException {
    nestedTasks.addElement(nestedTask);
  }

  public void setDatabaseRef(Reference reference) {
    database = (Database) reference.getReferencedObject(getProject());
  }

  public void execute() throws BuildException {
    for (Enumeration enumeration = nestedTasks.elements();
enumeration.hasMoreElements();) {
      log("executing task");
      ((Task) enumeration.nextElement()).perform();
    }
  }
}

========
BUILD.XML

  <target name="test-session" depends="init">
    <session databaseref="test.database">
      <createdatabase name="${database}"
               dbapassword="${password}"/>
      <createdatabase name="${database2}"
               dbapassword="${password}"/>
    </session>
  </target>