1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.javascript; |
22 |
|
|
23 |
|
import jalview.bin.JalviewLite; |
24 |
|
|
25 |
|
import java.net.URL; |
26 |
|
import java.util.Vector; |
27 |
|
|
28 |
|
import netscape.javascript.JSObject; |
29 |
|
|
|
|
| 0% |
Uncovered Elements: 132 (132) |
Complexity: 38 |
Complexity Density: 0.46 |
|
30 |
|
public class JSFunctionExec implements Runnable |
31 |
|
{ |
32 |
|
public JalviewLite jvlite; |
33 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
34 |
0 |
public JSFunctionExec(JalviewLite applet)... |
35 |
|
{ |
36 |
0 |
jvlite = applet; |
37 |
|
|
38 |
0 |
jsExecQueue = jvlite.getJsExecQueue(); |
39 |
0 |
jvlite.setExecutor(this); |
40 |
|
} |
41 |
|
|
42 |
|
private Vector jsExecQueue; |
43 |
|
|
44 |
|
private Thread executor = null; |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
46 |
0 |
public void stopQueue()... |
47 |
|
{ |
48 |
0 |
if (jsExecQueue != null) |
49 |
|
{ |
50 |
0 |
Vector<JSFunctionExec> q = null; |
51 |
0 |
synchronized (jsExecQueue) |
52 |
|
{ |
53 |
0 |
q = jsExecQueue; |
54 |
0 |
jsExecQueue = null; |
55 |
|
} |
56 |
0 |
if (q != null) |
57 |
|
{ |
58 |
0 |
for (JSFunctionExec jx : q) |
59 |
|
{ |
60 |
0 |
jx.jvlite = null; |
61 |
|
|
62 |
|
} |
63 |
0 |
q.removeAllElements(); |
64 |
0 |
synchronized (q) |
65 |
|
{ |
66 |
0 |
q.notifyAll(); |
67 |
|
} |
68 |
|
} |
69 |
|
} |
70 |
0 |
jvlite = null; |
71 |
0 |
executor = null; |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 6 |
Complexity Density: 0.5 |
|
74 |
0 |
@Override... |
75 |
|
public void run() |
76 |
|
{ |
77 |
0 |
while (jsExecQueue != null) |
78 |
|
{ |
79 |
0 |
if (jsExecQueue.size() > 0) |
80 |
|
{ |
81 |
0 |
Runnable r = (Runnable) jsExecQueue.elementAt(0); |
82 |
0 |
jsExecQueue.removeElementAt(0); |
83 |
0 |
try |
84 |
|
{ |
85 |
0 |
r.run(); |
86 |
|
} catch (Exception ex) |
87 |
|
{ |
88 |
0 |
ex.printStackTrace(); |
89 |
|
} catch (Error ex) |
90 |
|
{ |
91 |
0 |
ex.printStackTrace(); |
92 |
|
} |
93 |
|
} |
94 |
|
else |
95 |
|
{ |
96 |
0 |
try |
97 |
|
{ |
98 |
0 |
synchronized (jsExecQueue) |
99 |
|
{ |
100 |
0 |
jsExecQueue.wait(1000); |
101 |
|
} |
102 |
|
} catch (Exception ex) |
103 |
|
{ |
104 |
|
} |
105 |
0 |
; |
106 |
|
} |
107 |
|
} |
108 |
|
|
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
@param |
115 |
|
@param |
116 |
|
@throws |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
0 |
public void executeJavascriptFunction(final String _listener,... |
119 |
|
final Object[] objects) throws Exception |
120 |
|
{ |
121 |
0 |
executeJavascriptFunction(false, _listener, objects); |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@param |
128 |
|
|
129 |
|
@param |
130 |
|
|
131 |
|
@param |
132 |
|
|
133 |
|
@throws |
134 |
|
|
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0 |
public void executeJavascriptFunction(final boolean async,... |
137 |
|
final String _listener, Object[] arguments) throws Exception |
138 |
|
{ |
139 |
|
|
140 |
0 |
executeJavascriptFunction(async, _listener, arguments, null); |
141 |
|
|
142 |
|
} |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 6 |
Complexity Density: 0.4 |
|
144 |
0 |
public void executeJavascriptFunction(final boolean async,... |
145 |
|
final String _listener, Object[] arguments, final String dbgMsg) |
146 |
|
throws Exception |
147 |
|
{ |
148 |
0 |
final Object[] objects = new Object[arguments != null ? arguments.length |
149 |
|
: 0]; |
150 |
0 |
if (arguments != null) |
151 |
|
{ |
152 |
0 |
System.arraycopy(arguments, 0, objects, 0, arguments.length); |
153 |
|
} |
154 |
0 |
final Exception[] jsex = new Exception[1]; |
155 |
0 |
Runnable exec = new Runnable() |
156 |
|
{ |
|
|
| 0% |
Uncovered Elements: 62 (62) |
Complexity: 20 |
Complexity Density: 0.53 |
|
157 |
0 |
@Override... |
158 |
|
public void run() |
159 |
|
{ |
160 |
0 |
try |
161 |
|
{ |
162 |
0 |
JSObject scriptObject = null; |
163 |
0 |
try |
164 |
|
{ |
165 |
0 |
scriptObject = JSObject.getWindow(jvlite); |
166 |
|
} catch (Exception ex) |
167 |
|
{ |
168 |
|
} |
169 |
0 |
; |
170 |
0 |
if (scriptObject != null) |
171 |
|
{ |
172 |
0 |
if (jvlite.debug && dbgMsg != null) |
173 |
|
{ |
174 |
0 |
jalview.bin.Console.errPrintln(dbgMsg); |
175 |
|
} |
176 |
0 |
scriptObject.call(_listener, objects); |
177 |
|
} |
178 |
|
} catch (Exception jex) |
179 |
|
{ |
180 |
|
|
181 |
0 |
if (!(jex instanceof java.net.MalformedURLException)) |
182 |
|
{ |
183 |
0 |
if (jvlite.debug) |
184 |
|
{ |
185 |
0 |
jalview.bin.Console.errPrintln(jex); |
186 |
|
} |
187 |
0 |
if (jex instanceof netscape.javascript.JSException |
188 |
|
&& jvlite.jsfallbackEnabled) |
189 |
|
{ |
190 |
0 |
jsex[0] = jex; |
191 |
0 |
if (jvlite.debug) |
192 |
|
{ |
193 |
0 |
jalview.bin.Console |
194 |
|
.errPrintln("Falling back to javascript: url call"); |
195 |
|
} |
196 |
0 |
StringBuffer sb = new StringBuffer( |
197 |
|
"javascript:" + _listener + "("); |
198 |
0 |
for (int i = 0; objects != null && i < objects.length; i++) |
199 |
|
{ |
200 |
0 |
if (i > 0) |
201 |
|
{ |
202 |
0 |
sb.append(","); |
203 |
|
} |
204 |
0 |
sb.append("\""); |
205 |
|
|
206 |
|
|
207 |
0 |
if (objects[i] != null && !(objects[i].getClass().getName() |
208 |
|
.indexOf("jalview") == 0)) |
209 |
|
{ |
210 |
0 |
sb.append(objects[i].toString()); |
211 |
|
} |
212 |
0 |
sb.append("\""); |
213 |
|
} |
214 |
0 |
sb.append(")"); |
215 |
0 |
if (jvlite.debug) |
216 |
|
{ |
217 |
0 |
jalview.bin.Console.errPrintln(sb.toString()); |
218 |
|
} |
219 |
|
|
220 |
0 |
URL url = null; |
221 |
0 |
try |
222 |
|
{ |
223 |
0 |
url = new URL(sb.toString()); |
224 |
0 |
jvlite.getAppletContext().showDocument(url); |
225 |
0 |
jex = null; |
226 |
|
} catch (Exception uex) |
227 |
|
{ |
228 |
0 |
jex = uex; |
229 |
|
} |
230 |
|
} |
231 |
0 |
if (jex != null) |
232 |
|
{ |
233 |
0 |
if (async) |
234 |
|
{ |
235 |
0 |
jex.printStackTrace(); |
236 |
|
} |
237 |
|
else |
238 |
|
{ |
239 |
0 |
jsex[0] = jex; |
240 |
|
} |
241 |
|
} |
242 |
0 |
; |
243 |
|
} |
244 |
|
|
245 |
|
} |
246 |
|
} |
247 |
|
}; |
248 |
0 |
if (async) |
249 |
|
{ |
250 |
0 |
if (executor == null) |
251 |
|
{ |
252 |
0 |
executor = new Thread(new JSFunctionExec(jvlite)); |
253 |
0 |
executor.start(); |
254 |
|
} |
255 |
0 |
synchronized (jsExecQueue) |
256 |
|
{ |
257 |
0 |
jsExecQueue.addElement(exec); |
258 |
0 |
jsExecQueue.notify(); |
259 |
|
} |
260 |
|
} |
261 |
|
else |
262 |
|
{ |
263 |
|
|
264 |
0 |
exec.run(); |
265 |
0 |
if (jsex[0] != null) |
266 |
|
{ |
267 |
0 |
throw (jsex[0]); |
268 |
|
} |
269 |
|
} |
270 |
|
} |
271 |
|
|
272 |
|
} |