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 final Method mTestMethod
;
33 /** The object that implements the method **/
34 private final Object mInvokeClass
;
35 /** A PrintWriter for debug Output **/
36 private final PrintWriter mLog
;
37 /** An Error String **/
38 private String mErrMessage
= null;
39 /** Did an Exception happen? **/
40 private boolean mExceptionHappened
= false;
41 private Object
[] mParameter
= null;
43 public MethodThread(Method testMethod
, Object invokeClass
, Object
[] parameter
, PrintWriter log
)
45 mTestMethod
= testMethod
;
46 mInvokeClass
= invokeClass
;
47 mParameter
= parameter
;
59 mTestMethod
.invoke(mInvokeClass
, mParameter
);
61 catch (IllegalAccessException e
)
63 e
.printStackTrace(mLog
);
64 mErrMessage
= e
.getMessage();
65 mExceptionHappened
= true;
67 catch (java
.lang
.reflect
.InvocationTargetException e
)
69 Throwable t
= e
.getTargetException();
70 if (!(t
instanceof ComplexTestCase
.AssureException
))
72 t
.printStackTrace(mLog
);
73 mErrMessage
= t
.getMessage();
74 if (mErrMessage
== null)
76 mErrMessage
= t
.toString();
78 mExceptionHappened
= true;
85 * Get the error message
86 * @return The error message.
88 public String
getErrorMessage()
94 * Is there an error message?
95 * @return True, if an error did happen.
97 public boolean hasErrorMessage()
99 return mExceptionHappened
;
103 * Stop the running method.
105 public void stopRunning()
111 catch (SecurityException e
)
113 e
.printStackTrace(mLog
);
114 mErrMessage
= e
.getMessage();
115 mExceptionHappened
= true;