Files
libreoffice/qadevOOo/runner/complexlib/MethodThread.java
Rüdiger Timm a8b087a6be INTEGRATION: CWS qadev22 (1.3.100); FILE MERGED
2005/03/10 16:22:03 sw 1.3.100.1: i44711
2005-03-29 10:52:49 +00:00

91 lines
2.4 KiB
Java

package complexlib;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import lib.StatusException;
/**
* Invoke a method of a class in an own thread. Provide a method to end
* the thread.
*/
public class MethodThread extends Thread {
/** The method that should be executed **/
private Method mTestMethod = null;
/** The object that implements the method **/
private Object mInvokeClass = null;
/** A PrintWriter for debug Output **/
private PrintWriter mLog = null;
/** An Error String **/
private String mErrMessage = null;
/** Did an Exception happen? **/
private boolean mExceptionHappened = false;
/**
* Constructor.
* @param testMethod The method that will be invoked.
* @param invokeClass The class where the method is invoked.
* @param log The logging mechanism.
*/
public MethodThread(Method testMethod, Object invokeClass, PrintWriter log) {
mTestMethod = testMethod;
mInvokeClass = invokeClass;
mLog = log;
}
/**
* Invoke the method.
*/
public void run() {
try {
mTestMethod.invoke(mInvokeClass, new Object[]{});
}
catch(IllegalAccessException e) {
e.printStackTrace(mLog);
mErrMessage = e.getMessage();
mExceptionHappened = true;
}
catch(java.lang.reflect.InvocationTargetException e) {
Throwable t = e.getTargetException();
if (!(t instanceof ComplexTestCase.AssureException)) {
t.printStackTrace(mLog);
mErrMessage = t.getMessage();
if (mErrMessage == null)
mErrMessage = t.toString();
mExceptionHappened = true;
}
}
}
/**
* Get the error message
* @return The error message.
*/
public String getErrorMessage() {
return mErrMessage;
}
/**
* Is there an error message?
* @return True, if an error did happen.
*/
public boolean hasErrorMessage() {
return mExceptionHappened;
}
/**
* Stop the running method.
*/
public void destroy() {
try {
interrupt();
}
catch(SecurityException e) {
e.printStackTrace(mLog);
mErrMessage = e.getMessage();
mExceptionHappened = true;
}
}
}