Files
libreoffice/qadevOOo/runner/complexlib/MethodThread.java
Release Engineers 4cb14dd109 CWS-TOOLING: integrate CWS cmcfixes58
2009-05-04 13:51:10 +0200 cmc  r271450 : #i101533# latest sw warnings
2009-05-04 00:02:46 +0200 cmc  r271436 : #i101517# silence new warnings
2009-05-03 23:13:53 +0200 cmc  r271435 : #i101305# add that one back in
2009-05-02 16:30:42 +0200 cmc  r271431 : #i101493# get it to build, and remove some warnings
2009-05-02 16:12:37 +0200 cmc  r271430 : CWS-TOOLING: rebase CWS cmcfixes58 to trunk@271427 (milestone: DEV300:m47)
2009-04-23 13:19:33 +0200 cmc  r271163 : #i101305# remove annoying import foo is unused warnings
2009-04-21 17:10:34 +0200 cmc  r271048 : #i101246# remove AVMEDIA_MANAGER_SERVICE_NAME defines again
2009-04-21 17:07:41 +0200 cmc  r271047 : #i86323# remove xml2cmp unused methods
2009-05-07 06:54:56 +00:00

99 lines
2.6 KiB
Java

package complexlib;
import java.io.PrintWriter;
import java.lang.reflect.Method;
/**
* 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;
private Object[] mParameter = null;
/**
* 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;
}
public MethodThread(Method testMethod, Object invokeClass, Object[] parameter, PrintWriter log) {
mTestMethod = testMethod;
mInvokeClass = invokeClass;
mParameter = parameter;
mLog = log;
}
/**
* Invoke the method.
*/
public void run() {
try {
mTestMethod.invoke(mInvokeClass, mParameter);
}
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;
}
}
}