2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
22 import java
.lang
.reflect
.Method
;
25 * Invoke a method of a class in an own thread. Provide a method to end
28 public class MethodThread
extends Thread
31 /** The method that should be executed **/
32 private Method mTestMethod
= null;
33 /** The object that implements the method **/
34 private Object mInvokeClass
= null;
35 /** A PrintWriter for debug Output **/
36 private PrintWriter mLog
= null;
37 /** An Error String **/
38 private String mErrMessage
= null;
39 /** Did an Exception happen? **/
40 private boolean mExceptionHappened
= false;
41 private Object
[] mParameter
= null;
45 * @param testMethod The method that will be invoked.
46 * @param invokeClass The class where the method is invoked.
47 * @param log The logging mechanism.
49 public MethodThread(Method testMethod
, Object invokeClass
, PrintWriter log
)
51 mTestMethod
= testMethod
;
52 mInvokeClass
= invokeClass
;
56 public MethodThread(Method testMethod
, Object invokeClass
, Object
[] parameter
, PrintWriter log
)
58 mTestMethod
= testMethod
;
59 mInvokeClass
= invokeClass
;
60 mParameter
= parameter
;
71 mTestMethod
.invoke(mInvokeClass
, mParameter
);
73 catch (IllegalAccessException e
)
75 e
.printStackTrace(mLog
);
76 mErrMessage
= e
.getMessage();
77 mExceptionHappened
= true;
79 catch (java
.lang
.reflect
.InvocationTargetException e
)
81 Throwable t
= e
.getTargetException();
82 if (!(t
instanceof ComplexTestCase
.AssureException
))
84 t
.printStackTrace(mLog
);
85 mErrMessage
= t
.getMessage();
86 if (mErrMessage
== null)
88 mErrMessage
= t
.toString();
90 mExceptionHappened
= true;
97 * Get the error message
98 * @return The error message.
100 public String
getErrorMessage()
106 * Is there an error message?
107 * @return True, if an error did happen.
109 public boolean hasErrorMessage()
111 return mExceptionHappened
;
115 * Stop the running method.
118 public void destroy()
124 * Stop the running method.
126 public void stopRunning()
132 catch (SecurityException e
)
134 e
.printStackTrace(mLog
);
135 mErrMessage
= e
.getMessage();
136 mExceptionHappened
= true;