ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kichline, Don (EM, PTL)" <Don.Kichl...@penske.com>
Subject RE: Tasks and TaskContainer
Date Fri, 23 Jan 2004 13:43:27 GMT
This makes absolutely no sense what so ever, however this is how I worked
around the ClassCastException:

I ended up using reflection.  I am in severe doubt of my sanity and skills
as a programmer.  Can someone please explain why this is occurring?

			for (Iterator i = commandCallList.iterator();
i.hasNext();) {
				unknown = (UnknownElement) i.next();
				unknown.maybeConfigure();

				realTask = unknown.getTask();

				if (realTask != null) {
					Class clazz = realTask.getClass();
					Class[] params = { AS400.class };
					Method method =
clazz.getMethod("setSystem", params);
					Object[] sys = { this.as400 };
					method.invoke(realTask, sys);
					
					((Task)realTask).perform();
				}



-----Original Message-----
From: Kichline, Don (EM, PTL) 
Sent: Friday, January 23, 2004 7:49 AM
To: 'Ant Users List'
Subject: RE: Tasks and TaskContainer


I did that, and it appears to have worked, somewhat....

Here is what I am getting now as an error message:

Buildfile: C:\web-applications\build.xml
about:
    [AS400] class name of the real task is 'some.package.ChildTask'
    [AS400] java.lang.ClassCastException
    [AS400] at some.package.ParentTask.execute(ParentTask.java:85)
    [AS400] at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:306)
    [AS400] at org.apache.tools.ant.Task.perform(Task.java:401)
    [AS400] at org.apache.tools.ant.Target.execute(Target.java:338)
    [AS400] at org.apache.tools.ant.Target.performTasks(Target.java:365)
    [AS400] at org.apache.tools.ant.Project.executeTarget(Project.java:1237)
    [AS400] at
org.apache.tools.ant.Project.executeTargets(Project.java:1094)
    [AS400] at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunn
er.java:379)
    [AS400] at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRun
ner.java:166)
BUILD SUCCESSFUL
Total time: 331 milliseconds

It looks like a ChildTask, it smells like a child task, but whenever I cast
it to a child task, I get ClassCastException....  



-----Original Message-----
From: Peter Reilly [mailto:peter.reilly@corvil.com]
Sent: Friday, January 23, 2004 7:33 AM
To: Ant Users List
Subject: Re: Tasks and TaskContainer


The unknownelement needs to be configured - see ant.taskdefs.Antlib for 
an example
or the attached example container.

Peter
Kichline, Don (EM, PTL) wrote:

>I am attempting to write a set of tasks for ant.  I am using ant 1.6
against
>either the sun jdk 1.4.2 or the ibm jdk 1.3.1.  In either case the results
>are the same.
>
>In my TaskContainer, I have a public void addTask (Task task ) method.  The
>task that is passed in is of type UnknownElement.  Looking at
>UnknownElement, there is a method called getTask to retrieve the real
>wrappered task.
>
>When ever I call this method, the real task is null.
>
>Any ideas of what I may be doing incorrectly?
>
>I have been looking at example code of other projects, ant-contrib, etc... 
>
>Thanks,
>
>Don Kichline
>
>
>Here is a sample of my code:
>
>public class ParentTask extends Task implements TaskContainer {
>	private List childList = new ArrayList();
>
>	public void addTask(Task task) {
>		childList.add(task);
>	}
>
>	public void execute() throws BuildException {
>		try {
>			UnknownElement task = null;
>			ChildTask child = null;
>			for (Iterator i = .iterator(); i.hasNext();) {
>				task = (UnknownElement)i.next();
>				child = (ChildTask)task.getTask();
>**********			child.someMethod(...);    <===  NullPointer
>Exception Here
>			}
>		}
>		catch ( Throwable th ) {
>			th.printStackTrace();
>		}
>		super.execute();
>	}
>}
>
>
>public class ChildTask extends Task {
>	private String command = null;
>
>	public void addText(String command) {
>		this.command = command;
>	}
>
>	public void execute() throws BuildException {
>		try {
>			//	Do Something
>		} catch (Throwable th) {
>			throw new BuildException(th);
>		}
>
>		super.execute();
>	}
>
>	public void someMethod(...) {
>		//	Set something
>	}
>}
>
><project name="test" default="about" basedir=".">
>	<taskdef name="parent" 
>			 classname="some.package.ParentTask"
>			 classpath="bin"/>
>			 
>	<taskdef name="child" 
>			 classname="some.package.ChildTask"
>			 classpath="bin"/>
>			 
>	<target name="about">
>		<parent>
>			<child>TEST</child>
>		</parent>
>	</target>			 
></project>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
>
>  
>


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

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


Mime
View raw message