1 | package org.greenstone.admin.guiext;
|
---|
2 |
|
---|
3 | import java.lang.reflect.Method;
|
---|
4 | import javax.swing.JTextArea;
|
---|
5 |
|
---|
6 | import org.w3c.dom.Element;
|
---|
7 |
|
---|
8 | public class Callback implements Runnable
|
---|
9 | {
|
---|
10 | String _param = null;
|
---|
11 | CommandStep _parent = null;
|
---|
12 |
|
---|
13 | public Callback(Element callbackElement, CommandStep parent)
|
---|
14 | {
|
---|
15 | _parent = parent;
|
---|
16 |
|
---|
17 | if(callbackElement != null){
|
---|
18 | _param = ExtXMLHelper.getValueFromSingleElement(callbackElement, true);
|
---|
19 | }
|
---|
20 | else{
|
---|
21 | System.err.println("This <" + ExtXMLHelper.CALLBACK + "> element is null");
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | public void run()
|
---|
26 | {
|
---|
27 | JTextArea messageArea = _parent.getMessageArea();
|
---|
28 |
|
---|
29 | Object extObj = _parent.getParent().getParent().getExtObject();
|
---|
30 | Class[] params = new Class[]{String.class};
|
---|
31 |
|
---|
32 | Method callbackMethod = null;
|
---|
33 | try{
|
---|
34 | callbackMethod = extObj.getClass().getDeclaredMethod("doCallback", params);
|
---|
35 | }
|
---|
36 | catch(Exception ex){
|
---|
37 | System.err.println("Specified class does not have a doCallback(String) method");
|
---|
38 | _parent.threadError();
|
---|
39 | return;
|
---|
40 | }
|
---|
41 |
|
---|
42 | messageArea.append("\nCalling the callback method with \"" + _param +"\" as an argument");
|
---|
43 | Boolean success = null;
|
---|
44 | try{
|
---|
45 | success = (Boolean)callbackMethod.invoke(extObj, (Object)_param);
|
---|
46 | }
|
---|
47 | catch(Exception ex){
|
---|
48 | System.err.println("Error while attempting to invoke specified method -> ");
|
---|
49 | ex.printStackTrace();
|
---|
50 | _parent.threadError();
|
---|
51 | return;
|
---|
52 | }
|
---|
53 |
|
---|
54 | if(!success){
|
---|
55 | System.err.println("Call to doCallback method with the value \"" + _param + "\" returned unsuccessfully");
|
---|
56 | _parent.threadError();
|
---|
57 | return;
|
---|
58 | }
|
---|
59 |
|
---|
60 | _parent.startNextThread();
|
---|
61 | }
|
---|
62 |
|
---|
63 | public String getParam()
|
---|
64 | {
|
---|
65 | return _param;
|
---|
66 | }
|
---|
67 |
|
---|
68 | public CommandStep getParent()
|
---|
69 | {
|
---|
70 | return _parent;
|
---|
71 | }
|
---|
72 | } |
---|