JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / jalview / javascript / JSFunctionExec.js
1 Clazz.declarePackage ("jalview.javascript");
2 Clazz.load (null, "jalview.javascript.JSFunctionExec", ["jalview.bin.JalviewLite", "java.lang.StringBuffer", "$.Thread", "java.net.MalformedURLException", "$.URL", "netscape.javascript.JSException", "$.JSObject"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.jvlite = null;
5 this.jsExecQueue = null;
6 this.executor = null;
7 Clazz.instantialize (this, arguments);
8 }, jalview.javascript, "JSFunctionExec", null, Runnable);
9 Clazz.makeConstructor (c$, 
10 function (applet) {
11 this.jvlite = applet;
12 this.jsExecQueue = this.jvlite.getJsExecQueue ();
13 this.jvlite.setExecutor (this);
14 }, "jalview.bin.JalviewLite");
15 Clazz.overrideMethod (c$, "finalize", 
16 function () {
17 this.jvlite = null;
18 this.executor = null;
19 if (this.jsExecQueue != null) {
20 this.jsExecQueue.clear ();
21 }this.jsExecQueue = null;
22 });
23 Clazz.defineMethod (c$, "stopQueue", 
24 function () {
25 if (this.jsExecQueue != null) {
26 var q = null;
27 {
28 q = this.jsExecQueue;
29 this.jsExecQueue = null;
30 }if (q != null) {
31 for (var jx, $jx = q.iterator (); $jx.hasNext () && ((jx = $jx.next ()) || true);) {
32 jx.jvlite = null;
33 }
34 q.removeAllElements ();
35 {
36 q.notifyAll ();
37 }}}this.jvlite = null;
38 this.executor = null;
39 });
40 Clazz.defineMethod (c$, "run", 
41 function () {
42 while (this.jsExecQueue != null) {
43 if (this.jsExecQueue.size () > 0) {
44 var r = this.jsExecQueue.elementAt (0);
45 this.jsExecQueue.removeElementAt (0);
46 try {
47 r.run ();
48 } catch (e$$) {
49 if (Clazz.exceptionOf (e$$, Exception)) {
50 var ex = e$$;
51 {
52 ex.printStackTrace ();
53 }
54 } else if (Clazz.exceptionOf (e$$, Error)) {
55 var ex = e$$;
56 {
57 ex.printStackTrace ();
58 }
59 } else {
60 throw e$$;
61 }
62 }
63 } else {
64 try {
65 {
66 this.jsExecQueue.wait (1000);
67 }} catch (ex) {
68 if (Clazz.exceptionOf (ex, Exception)) {
69 } else {
70 throw ex;
71 }
72 }
73 ;}}
74 });
75 Clazz.defineMethod (c$, "executeJavascriptFunction", 
76 function (_listener, objects) {
77 this.executeJavascriptFunction (false, _listener, objects);
78 }, "~S,~A");
79 Clazz.defineMethod (c$, "executeJavascriptFunction", 
80 function (async, _listener, $arguments) {
81 this.executeJavascriptFunction (async, _listener, $arguments, null);
82 }, "~B,~S,~A");
83 Clazz.defineMethod (c$, "executeJavascriptFunction", 
84 function (async, _listener, $arguments, dbgMsg) {
85 var objects =  new Array ($arguments != null ? $arguments.length : 0);
86 if ($arguments != null) {
87 System.arraycopy ($arguments, 0, objects, 0, $arguments.length);
88 }var jsex =  new Array (1);
89 var exec = ((Clazz.isClassDefined ("jalview.javascript.JSFunctionExec$1") ? 0 : jalview.javascript.JSFunctionExec.$JSFunctionExec$1$ ()), Clazz.innerTypeInstance (jalview.javascript.JSFunctionExec$1, this, Clazz.cloneFinals ("dbgMsg", dbgMsg, "_listener", _listener, "objects", objects, "jsex", jsex, "async", async)));
90 if (async) {
91 if (this.executor == null) {
92 this.executor =  new Thread ( new jalview.javascript.JSFunctionExec (this.jvlite));
93 this.executor.start ();
94 }{
95 this.jsExecQueue.addElement (exec);
96 this.jsExecQueue.notify ();
97 }} else {
98 exec.run ();
99 if (jsex[0] != null) {
100 throw (jsex[0]);
101 }}}, "~B,~S,~A,~S");
102 c$.$JSFunctionExec$1$ = function () {
103 Clazz.pu$h ();
104 c$ = Clazz.declareAnonymous (jalview.javascript, "JSFunctionExec$1", null, Runnable);
105 Clazz.defineMethod (c$, "run", 
106 function () {
107 try {
108 var scriptObject = null;
109 try {
110 scriptObject = netscape.javascript.JSObject.getWindow (this.b$["jalview.javascript.JSFunctionExec"].jvlite);
111 } catch (ex) {
112 if (Clazz.exceptionOf (ex, Exception)) {
113 } else {
114 throw ex;
115 }
116 }
117 ;if (scriptObject != null) {
118 if (jalview.bin.JalviewLite.debug && this.f$.dbgMsg != null) {
119 System.err.println (this.f$.dbgMsg);
120 }scriptObject.call (this.f$._listener, this.f$.objects);
121 }} catch (jex) {
122 if (Clazz.exceptionOf (jex, Exception)) {
123 if (!(Clazz.instanceOf (jex, java.net.MalformedURLException))) {
124 if (jalview.bin.JalviewLite.debug) {
125 System.err.println (jex);
126 }if (Clazz.instanceOf (jex, netscape.javascript.JSException) && this.b$["jalview.javascript.JSFunctionExec"].jvlite.jsfallbackEnabled) {
127 this.f$.jsex[0] = jex;
128 if (jalview.bin.JalviewLite.debug) {
129 System.err.println ("Falling back to javascript: url call");
130 }var sb =  new StringBuffer ("javascript:" + this.f$._listener + "(");
131 for (var i = 0; this.f$.objects != null && i < this.f$.objects.length; i++) {
132 if (i > 0) {
133 sb.append (",");
134 }sb.append ("\"");
135 if (this.f$.objects[i] != null && !(this.f$.objects[i].getClass ().getName ().indexOf ("jalview") == 0)) {
136 sb.append (this.f$.objects[i].toString ());
137 }sb.append ("\"");
138 }
139 sb.append (")");
140 if (jalview.bin.JalviewLite.debug) {
141 System.err.println (sb.toString ());
142 }var url = null;
143 try {
144 url =  new java.net.URL (sb.toString ());
145 this.b$["jalview.javascript.JSFunctionExec"].jvlite.getAppletContext ().showDocument (url);
146 jex = null;
147 } catch (uex) {
148 if (Clazz.exceptionOf (uex, Exception)) {
149 jex = uex;
150 } else {
151 throw uex;
152 }
153 }
154 }if (jex != null) {
155 if (this.f$.async) {
156 jex.printStackTrace ();
157 } else {
158 this.f$.jsex[0] = jex;
159 }};}} else {
160 throw jex;
161 }
162 }
163 });
164 c$ = Clazz.p0p ();
165 };
166 });