1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ws.jws2; |
22 |
|
|
23 |
|
import jalview.bin.Cache; |
24 |
|
import jalview.gui.AlignFrame; |
25 |
|
import jalview.gui.Desktop; |
26 |
|
import jalview.gui.JvSwingUtils; |
27 |
|
import jalview.util.MessageManager; |
28 |
|
import jalview.ws.WSMenuEntryProviderI; |
29 |
|
import jalview.ws.jws2.jabaws2.Jws2Instance; |
30 |
|
import jalview.ws.params.ParamDatastoreI; |
31 |
|
|
32 |
|
import java.awt.Color; |
33 |
|
import java.awt.event.ActionEvent; |
34 |
|
import java.awt.event.ActionListener; |
35 |
|
import java.beans.PropertyChangeEvent; |
36 |
|
import java.beans.PropertyChangeListener; |
37 |
|
import java.beans.PropertyChangeSupport; |
38 |
|
import java.net.MalformedURLException; |
39 |
|
import java.net.URL; |
40 |
|
import java.util.ArrayList; |
41 |
|
import java.util.Arrays; |
42 |
|
import java.util.HashMap; |
43 |
|
import java.util.HashSet; |
44 |
|
import java.util.Hashtable; |
45 |
|
import java.util.List; |
46 |
|
import java.util.Map; |
47 |
|
import java.util.Set; |
48 |
|
import java.util.StringTokenizer; |
49 |
|
import java.util.Vector; |
50 |
|
|
51 |
|
import javax.swing.JMenu; |
52 |
|
import javax.swing.JMenuItem; |
53 |
|
|
54 |
|
import compbio.ws.client.Services; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@author |
61 |
|
|
62 |
|
|
|
|
| 54.5% |
Uncovered Elements: 231 (508) |
Complexity: 141 |
Complexity Density: 0.44 |
|
63 |
|
public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI |
64 |
|
{ |
65 |
|
public static final String COMPBIO_JABAWS = "http://www.compbio.dundee.ac.uk/jabaws"; |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
private final static String JWS2HOSTURLS = "JWS2HOSTURLS"; |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
private static Jws2Discoverer discoverer; |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
private static List<String> testUrls = null; |
81 |
|
|
82 |
|
|
83 |
|
private String preferredUrl; |
84 |
|
|
85 |
|
private PropertyChangeSupport changeSupport = new PropertyChangeSupport( |
86 |
|
this); |
87 |
|
|
88 |
|
private Vector<String> invalidServiceUrls = null; |
89 |
|
|
90 |
|
private Vector<String> urlsWithoutServices = null; |
91 |
|
|
92 |
|
private Vector<String> validServiceUrls = null; |
93 |
|
|
94 |
|
private volatile boolean running = false; |
95 |
|
|
96 |
|
private volatile boolean aborted = false; |
97 |
|
|
98 |
|
private Thread oldthread = null; |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
protected Vector<Jws2Instance> services; |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
108 |
1 |
private Jws2Discoverer()... |
109 |
|
{ |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
@param |
116 |
|
|
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
11 |
public void addPropertyChangeListener(... |
119 |
|
java.beans.PropertyChangeListener listener) |
120 |
|
{ |
121 |
11 |
changeSupport.addPropertyChangeListener(listener); |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@param |
128 |
|
|
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0 |
public void removePropertyChangeListener(... |
131 |
|
java.beans.PropertyChangeListener listener) |
132 |
|
{ |
133 |
0 |
changeSupport.removePropertyChangeListener(listener); |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
|
@return |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
139 |
64 |
public boolean isAborted()... |
140 |
|
{ |
141 |
64 |
return aborted; |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
@param |
146 |
|
|
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
148 |
2 |
public void setAborted(boolean aborted)... |
149 |
|
{ |
150 |
2 |
this.aborted = aborted; |
151 |
|
} |
152 |
|
|
|
|
| 86.7% |
Uncovered Elements: 13 (98) |
Complexity: 23 |
Complexity Density: 0.34 |
|
153 |
11 |
@Override... |
154 |
|
public void run() |
155 |
|
{ |
156 |
|
|
157 |
11 |
if (running && oldthread != null && oldthread.isAlive()) |
158 |
|
{ |
159 |
2 |
if (!aborted) |
160 |
|
{ |
161 |
0 |
return; |
162 |
|
} |
163 |
6 |
while (running) |
164 |
|
{ |
165 |
4 |
try |
166 |
|
{ |
167 |
4 |
Cache.log.debug( |
168 |
|
"Waiting around for old discovery thread to finish."); |
169 |
|
|
170 |
4 |
Thread.sleep(100); |
171 |
|
} catch (Exception e) |
172 |
|
{ |
173 |
|
} |
174 |
|
} |
175 |
2 |
aborted = false; |
176 |
2 |
Cache.log.debug("Old discovery thread has finished."); |
177 |
|
} |
178 |
11 |
running = true; |
179 |
|
|
180 |
|
|
181 |
11 |
final Set<String> ignoredServices = new HashSet<String>(); |
182 |
11 |
for (String ignored : Cache |
183 |
|
.getDefault("IGNORED_JABAWS_SERVICETYPES", "").split("\\|")) |
184 |
|
{ |
185 |
11 |
ignoredServices.add(ignored); |
186 |
|
} |
187 |
|
|
188 |
11 |
changeSupport.firePropertyChange("services", services, |
189 |
|
new Vector<Jws2Instance>()); |
190 |
11 |
oldthread = Thread.currentThread(); |
191 |
11 |
try |
192 |
|
{ |
193 |
11 |
Class foo = getClass().getClassLoader() |
194 |
|
.loadClass("compbio.ws.client.Jws2Client"); |
195 |
|
} catch (ClassNotFoundException e) |
196 |
|
{ |
197 |
0 |
System.err.println( |
198 |
|
"Not enabling JABA Webservices : client jar is not available." |
199 |
|
+ "\nPlease check that your webstart JNLP file is up to date!"); |
200 |
0 |
running = false; |
201 |
0 |
return; |
202 |
|
} |
203 |
|
|
204 |
11 |
if (services != null) |
205 |
|
{ |
206 |
10 |
services.removeAllElements(); |
207 |
|
} |
208 |
11 |
if (urlsWithoutServices != null) |
209 |
|
{ |
210 |
0 |
urlsWithoutServices.removeAllElements(); |
211 |
|
} |
212 |
11 |
if (invalidServiceUrls != null) |
213 |
|
{ |
214 |
0 |
invalidServiceUrls.removeAllElements(); |
215 |
|
} |
216 |
11 |
if (validServiceUrls != null) |
217 |
|
{ |
218 |
10 |
validServiceUrls.removeAllElements(); |
219 |
|
} |
220 |
11 |
ArrayList<String> svctypes = new ArrayList<String>(); |
221 |
|
|
222 |
11 |
List<JabaWsServerQuery> qrys = new ArrayList<JabaWsServerQuery>(); |
223 |
11 |
for (final String jwsserver : getServiceUrls()) |
224 |
|
{ |
225 |
11 |
JabaWsServerQuery squery = new JabaWsServerQuery(this, jwsserver); |
226 |
11 |
if (svctypes.size() == 0) |
227 |
|
{ |
228 |
|
|
229 |
|
|
230 |
11 |
for (Services sv : squery.JABAWS2SERVERS) |
231 |
|
{ |
232 |
121 |
if (!ignoredServices.contains(sv.toString())) |
233 |
|
{ |
234 |
121 |
svctypes.add(sv.toString()); |
235 |
|
} |
236 |
|
} |
237 |
|
|
238 |
|
} |
239 |
11 |
qrys.add(squery); |
240 |
11 |
new Thread(squery).start(); |
241 |
|
} |
242 |
11 |
boolean finished = true; |
243 |
11 |
do |
244 |
|
{ |
245 |
119 |
finished = true; |
246 |
119 |
try |
247 |
|
{ |
248 |
119 |
Thread.sleep(100); |
249 |
|
} catch (Exception e) |
250 |
|
{ |
251 |
|
} |
252 |
119 |
; |
253 |
119 |
for (JabaWsServerQuery squery : qrys) |
254 |
|
{ |
255 |
119 |
if (squery.isRunning()) |
256 |
|
{ |
257 |
110 |
finished = false; |
258 |
|
} |
259 |
|
} |
260 |
119 |
if (aborted) |
261 |
|
{ |
262 |
3 |
Cache.log.debug( |
263 |
|
"Aborting " + qrys.size() + " JABAWS discovery threads."); |
264 |
3 |
for (JabaWsServerQuery squery : qrys) |
265 |
|
{ |
266 |
3 |
squery.setQuit(true); |
267 |
|
} |
268 |
|
} |
269 |
119 |
} while (!aborted && !finished); |
270 |
11 |
if (!aborted) |
271 |
|
{ |
272 |
|
|
273 |
|
|
274 |
|
|
275 |
8 |
if (services != null && services.size() > 0) |
276 |
|
{ |
277 |
8 |
Jws2Instance[] svcs = new Jws2Instance[services.size()]; |
278 |
8 |
int[] spos = new int[services.size()]; |
279 |
8 |
int ipos = 0; |
280 |
8 |
List<String> svcUrls = getServiceUrls(); |
281 |
8 |
for (Jws2Instance svc : services) |
282 |
|
{ |
283 |
112 |
svcs[ipos] = svc; |
284 |
112 |
spos[ipos++] = 1000 * svcUrls.indexOf(svc.getHost()) + 1 |
285 |
|
+ svctypes.indexOf(svc.serviceType); |
286 |
|
} |
287 |
8 |
jalview.util.QuickSort.sort(spos, svcs); |
288 |
8 |
services = new Vector<Jws2Instance>(); |
289 |
8 |
for (Jws2Instance svc : svcs) |
290 |
|
{ |
291 |
112 |
if (!ignoredServices.contains(svc.serviceType)) |
292 |
|
{ |
293 |
112 |
services.add(svc); |
294 |
|
} |
295 |
|
} |
296 |
|
} |
297 |
|
} |
298 |
11 |
oldthread = null; |
299 |
11 |
running = false; |
300 |
11 |
changeSupport.firePropertyChange("services", new Vector<Jws2Instance>(), |
301 |
|
services); |
302 |
|
} |
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
@param |
308 |
|
@param |
309 |
|
@param |
310 |
|
|
|
|
| 94.1% |
Uncovered Elements: 1 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
311 |
132 |
synchronized void addService(String jwsservers, Jws2Instance service)... |
312 |
|
{ |
313 |
132 |
if (services == null) |
314 |
|
{ |
315 |
1 |
services = new Vector<Jws2Instance>(); |
316 |
|
} |
317 |
132 |
System.out.println( |
318 |
|
"Discovered service: " + jwsservers + " " + service.toString()); |
319 |
|
|
320 |
|
|
321 |
|
|
322 |
132 |
services.add(service); |
323 |
|
|
324 |
132 |
ParamDatastoreI pds = service.getParamStore(); |
325 |
132 |
if (pds != null) |
326 |
|
{ |
327 |
132 |
pds.getPresets(); |
328 |
|
} |
329 |
132 |
service.hasParameters(); |
330 |
132 |
if (validServiceUrls == null) |
331 |
|
{ |
332 |
1 |
validServiceUrls = new Vector<String>(); |
333 |
|
} |
334 |
132 |
validServiceUrls.add(jwsservers); |
335 |
|
} |
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
341 |
474 |
@Override... |
342 |
|
public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame) |
343 |
|
{ |
344 |
|
|
345 |
474 |
populateWSMenuEntry(wsmenu, alignFrame, null); |
346 |
|
} |
347 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
348 |
6636 |
private boolean isRecalculable(String action)... |
349 |
|
{ |
350 |
6636 |
return (action != null && action.equalsIgnoreCase("conservation")); |
351 |
|
} |
352 |
|
|
|
|
| 60% |
Uncovered Elements: 22 (55) |
Complexity: 11 |
Complexity Density: 0.28 |
|
353 |
474 |
private void populateWSMenuEntry(JMenu jws2al,... |
354 |
|
final AlignFrame alignFrame, String typeFilter) |
355 |
|
{ |
356 |
474 |
if (running || services == null || services.size() == 0) |
357 |
|
{ |
358 |
0 |
return; |
359 |
|
} |
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
474 |
JMenu atpoint; |
366 |
474 |
List<Jws2Instance> enumerableServices = new ArrayList<Jws2Instance>(); |
367 |
|
|
368 |
474 |
Map<String, Jws2Instance> preferredHosts = new HashMap<String, Jws2Instance>(); |
369 |
474 |
Map<String, List<Jws2Instance>> alternates = new HashMap<String, List<Jws2Instance>>(); |
370 |
474 |
for (Jws2Instance service : services.toArray(new Jws2Instance[0])) |
371 |
|
{ |
372 |
6636 |
if (!isRecalculable(service.action)) |
373 |
|
{ |
374 |
|
|
375 |
|
|
376 |
6162 |
enumerableServices.add(service); |
377 |
|
} |
378 |
|
else |
379 |
|
{ |
380 |
474 |
if (!preferredHosts.containsKey(service.serviceType)) |
381 |
|
{ |
382 |
474 |
Jws2Instance preferredInstance = getPreferredServiceFor( |
383 |
|
alignFrame, service.serviceType); |
384 |
474 |
if (preferredInstance != null) |
385 |
|
{ |
386 |
474 |
preferredHosts.put(service.serviceType, preferredInstance); |
387 |
|
} |
388 |
|
else |
389 |
|
{ |
390 |
0 |
preferredHosts.put(service.serviceType, service); |
391 |
|
} |
392 |
|
} |
393 |
474 |
List<Jws2Instance> ph = alternates.get(service.serviceType); |
394 |
474 |
if (preferredHosts.get(service.serviceType) != service) |
395 |
|
{ |
396 |
0 |
if (ph == null) |
397 |
|
{ |
398 |
0 |
ph = new ArrayList<Jws2Instance>(); |
399 |
|
} |
400 |
0 |
ph.add(service); |
401 |
0 |
alternates.put(service.serviceType, ph); |
402 |
|
} |
403 |
|
} |
404 |
|
|
405 |
|
} |
406 |
|
|
407 |
|
|
408 |
474 |
addEnumeratedServices(jws2al, alignFrame, enumerableServices); |
409 |
|
|
410 |
466 |
for (final Jws2Instance service : preferredHosts.values()) |
411 |
|
{ |
412 |
466 |
atpoint = JvSwingUtils.findOrCreateMenu(jws2al, service.action); |
413 |
466 |
JMenuItem hitm; |
414 |
466 |
if (atpoint.getItemCount() > 1) |
415 |
|
{ |
416 |
|
|
417 |
0 |
atpoint.addSeparator(); |
418 |
|
} |
419 |
466 |
atpoint.add(hitm = new JMenuItem(service.getHost())); |
420 |
466 |
hitm.setForeground(Color.blue); |
421 |
466 |
hitm.addActionListener(new ActionListener() |
422 |
|
{ |
423 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
424 |
0 |
@Override... |
425 |
|
public void actionPerformed(ActionEvent e) |
426 |
|
{ |
427 |
0 |
Desktop.showUrl(service.getHost()); |
428 |
|
} |
429 |
|
}); |
430 |
466 |
hitm.setToolTipText(JvSwingUtils.wrapTooltip(false, |
431 |
|
MessageManager.getString("label.open_jabaws_web_page"))); |
432 |
|
|
433 |
466 |
service.attachWSMenuEntry(atpoint, alignFrame); |
434 |
466 |
if (alternates.containsKey(service.serviceType)) |
435 |
|
{ |
436 |
0 |
atpoint.add(hitm = new JMenu( |
437 |
|
MessageManager.getString("label.switch_server"))); |
438 |
0 |
hitm.setToolTipText(JvSwingUtils.wrapTooltip(false, |
439 |
|
MessageManager.getString("label.choose_jabaws_server"))); |
440 |
0 |
for (final Jws2Instance sv : alternates.get(service.serviceType)) |
441 |
|
{ |
442 |
0 |
JMenuItem itm; |
443 |
0 |
hitm.add(itm = new JMenuItem(sv.getHost())); |
444 |
0 |
itm.setForeground(Color.blue); |
445 |
0 |
itm.addActionListener(new ActionListener() |
446 |
|
{ |
447 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
448 |
0 |
@Override... |
449 |
|
public void actionPerformed(ActionEvent arg0) |
450 |
|
{ |
451 |
0 |
new Thread(new Runnable() |
452 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
453 |
0 |
@Override... |
454 |
|
public void run() |
455 |
|
{ |
456 |
0 |
setPreferredServiceFor(alignFrame, sv.serviceType, |
457 |
|
sv.action, sv); |
458 |
0 |
changeSupport.firePropertyChange("services", |
459 |
|
new Vector<Jws2Instance>(), services); |
460 |
|
}; |
461 |
|
}).start(); |
462 |
|
|
463 |
|
} |
464 |
|
}); |
465 |
|
} |
466 |
|
} |
467 |
|
} |
468 |
|
} |
469 |
|
|
470 |
|
|
471 |
|
|
472 |
|
|
473 |
|
|
|
|
| 78.3% |
Uncovered Elements: 13 (60) |
Complexity: 12 |
Complexity Density: 0.29 |
|
474 |
474 |
private void addEnumeratedServices(final JMenu jws2al,... |
475 |
|
final AlignFrame alignFrame, |
476 |
|
List<Jws2Instance> enumerableServices) |
477 |
|
{ |
478 |
474 |
boolean byhost = Cache.getDefault("WSMENU_BYHOST", false), |
479 |
|
bytype = Cache.getDefault("WSMENU_BYTYPE", false); |
480 |
|
|
481 |
|
|
482 |
|
|
483 |
|
|
484 |
474 |
JMenu atpoint; |
485 |
|
|
486 |
474 |
List<String> hostLabels = new ArrayList<String>(); |
487 |
474 |
Hashtable<String, String> lasthostFor = new Hashtable<String, String>(); |
488 |
474 |
Hashtable<String, ArrayList<Jws2Instance>> hosts = new Hashtable<String, ArrayList<Jws2Instance>>(); |
489 |
474 |
ArrayList<String> hostlist = new ArrayList<String>(); |
490 |
474 |
for (Jws2Instance service : enumerableServices) |
491 |
|
{ |
492 |
6162 |
ArrayList<Jws2Instance> hostservices = hosts.get(service.getHost()); |
493 |
6162 |
if (hostservices == null) |
494 |
|
{ |
495 |
474 |
hosts.put(service.getHost(), |
496 |
|
hostservices = new ArrayList<Jws2Instance>()); |
497 |
474 |
hostlist.add(service.getHost()); |
498 |
|
} |
499 |
6162 |
hostservices.add(service); |
500 |
|
} |
501 |
|
|
502 |
474 |
for (String host : hostlist) |
503 |
|
{ |
504 |
474 |
Jws2Instance orderedsvcs[] = hosts.get(host) |
505 |
|
.toArray(new Jws2Instance[1]); |
506 |
474 |
String sortbytype[] = new String[orderedsvcs.length]; |
507 |
6636 |
for (int i = 0; i < sortbytype.length; i++) |
508 |
|
{ |
509 |
6162 |
sortbytype[i] = orderedsvcs[i].serviceType; |
510 |
|
} |
511 |
474 |
jalview.util.QuickSort.sort(sortbytype, orderedsvcs); |
512 |
474 |
for (final Jws2Instance service : orderedsvcs) |
513 |
|
{ |
514 |
6074 |
atpoint = JvSwingUtils.findOrCreateMenu(jws2al, service.action); |
515 |
6074 |
String type = service.serviceType; |
516 |
6074 |
if (byhost) |
517 |
|
{ |
518 |
0 |
atpoint = JvSwingUtils.findOrCreateMenu(atpoint, host); |
519 |
0 |
if (atpoint.getToolTipText() == null) |
520 |
|
{ |
521 |
0 |
atpoint.setToolTipText(MessageManager |
522 |
|
.formatMessage("label.services_at", new String[] |
523 |
|
{ host })); |
524 |
|
} |
525 |
|
} |
526 |
6074 |
if (bytype) |
527 |
|
{ |
528 |
0 |
atpoint = JvSwingUtils.findOrCreateMenu(atpoint, type); |
529 |
0 |
if (atpoint.getToolTipText() == null) |
530 |
|
{ |
531 |
0 |
atpoint.setToolTipText(service.getActionText()); |
532 |
|
} |
533 |
|
} |
534 |
6074 |
if (!byhost && !hostLabels.contains( |
535 |
|
host + service.serviceType + service.getActionText())) |
536 |
|
|
537 |
|
|
538 |
|
{ |
539 |
|
|
540 |
|
|
541 |
|
|
542 |
|
|
543 |
6074 |
JMenuItem hitm; |
544 |
6074 |
if (hostLabels.contains(host)) |
545 |
|
{ |
546 |
5600 |
atpoint.addSeparator(); |
547 |
|
} |
548 |
|
else |
549 |
|
{ |
550 |
474 |
hostLabels.add(host); |
551 |
|
} |
552 |
6074 |
if (lasthostFor.get(service.action) == null |
553 |
|
|| !lasthostFor.get(service.action).equals(host)) |
554 |
|
{ |
555 |
1414 |
atpoint.add(hitm = new JMenuItem(host)); |
556 |
1414 |
hitm.setForeground(Color.blue); |
557 |
1414 |
hitm.addActionListener(new ActionListener() |
558 |
|
{ |
559 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
560 |
0 |
@Override... |
561 |
|
public void actionPerformed(ActionEvent e) |
562 |
|
{ |
563 |
0 |
Desktop.showUrl(service.getHost()); |
564 |
|
} |
565 |
|
}); |
566 |
1414 |
hitm.setToolTipText( |
567 |
|
JvSwingUtils.wrapTooltip(true, MessageManager |
568 |
|
.getString("label.open_jabaws_web_page"))); |
569 |
1414 |
lasthostFor.put(service.action, host); |
570 |
|
} |
571 |
6074 |
hostLabels.add( |
572 |
|
host + service.serviceType + service.getActionText()); |
573 |
|
} |
574 |
|
|
575 |
6074 |
service.attachWSMenuEntry(atpoint, alignFrame); |
576 |
|
} |
577 |
|
} |
578 |
|
} |
579 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.42 |
|
580 |
0 |
public static void main(String[] args)... |
581 |
|
{ |
582 |
0 |
if (args.length > 0) |
583 |
|
{ |
584 |
0 |
testUrls = new ArrayList<String>(); |
585 |
0 |
for (String url : args) |
586 |
|
{ |
587 |
0 |
testUrls.add(url); |
588 |
|
} |
589 |
0 |
; |
590 |
|
} |
591 |
0 |
Thread runner = getDiscoverer() |
592 |
|
.startDiscoverer(new PropertyChangeListener() |
593 |
|
{ |
594 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
595 |
0 |
@Override... |
596 |
|
public void propertyChange(PropertyChangeEvent evt) |
597 |
|
{ |
598 |
0 |
if (getDiscoverer().services != null) |
599 |
|
{ |
600 |
0 |
System.out.println("Changesupport: There are now " |
601 |
|
+ getDiscoverer().services.size() + " services"); |
602 |
0 |
int i = 1; |
603 |
0 |
for (Jws2Instance instance : getDiscoverer().services) |
604 |
|
{ |
605 |
0 |
System.out.println("Service " + i++ + " " |
606 |
|
+ instance.getClass() + "@" + instance.getHost() |
607 |
|
+ ": " + instance.getActionText()); |
608 |
|
} |
609 |
|
|
610 |
|
} |
611 |
|
} |
612 |
|
}); |
613 |
0 |
while (runner.isAlive()) |
614 |
|
{ |
615 |
0 |
try |
616 |
|
{ |
617 |
0 |
Thread.sleep(50); |
618 |
|
} catch (InterruptedException e) |
619 |
|
{ |
620 |
|
} |
621 |
0 |
; |
622 |
|
} |
623 |
0 |
try |
624 |
|
{ |
625 |
0 |
Thread.sleep(50); |
626 |
|
} catch (InterruptedException x) |
627 |
|
{ |
628 |
|
} |
629 |
|
} |
630 |
|
|
631 |
|
|
632 |
|
|
633 |
|
|
634 |
|
@return |
635 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
636 |
1252 |
public static Jws2Discoverer getDiscoverer()... |
637 |
|
{ |
638 |
1252 |
if (discoverer == null) |
639 |
|
{ |
640 |
1 |
discoverer = new Jws2Discoverer(); |
641 |
|
} |
642 |
1252 |
return discoverer; |
643 |
|
} |
644 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
645 |
1110 |
public boolean hasServices()... |
646 |
|
{ |
647 |
1110 |
return !running && services != null && services.size() > 0; |
648 |
|
} |
649 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
650 |
1244 |
public boolean isRunning()... |
651 |
|
{ |
652 |
1244 |
return running; |
653 |
|
} |
654 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
655 |
0 |
public void setServiceUrls(List<String> wsUrls)... |
656 |
|
{ |
657 |
0 |
if (wsUrls != null && !wsUrls.isEmpty()) |
658 |
|
{ |
659 |
0 |
StringBuilder urls = new StringBuilder(128); |
660 |
0 |
String sep = ""; |
661 |
0 |
for (String url : wsUrls) |
662 |
|
{ |
663 |
0 |
urls.append(sep); |
664 |
0 |
urls.append(url); |
665 |
0 |
sep = ","; |
666 |
|
} |
667 |
0 |
Cache.setProperty(JWS2HOSTURLS, urls.toString()); |
668 |
|
} |
669 |
|
else |
670 |
|
{ |
671 |
0 |
Cache.removeProperty(JWS2HOSTURLS); |
672 |
|
} |
673 |
|
} |
674 |
|
|
675 |
|
|
676 |
|
|
677 |
|
|
678 |
|
|
679 |
|
@return |
680 |
|
|
|
|
| 61.3% |
Uncovered Elements: 12 (31) |
Complexity: 8 |
Complexity Density: 0.38 |
|
681 |
19 |
public List<String> getServiceUrls()... |
682 |
|
{ |
683 |
19 |
if (testUrls != null) |
684 |
|
{ |
685 |
|
|
686 |
0 |
return testUrls; |
687 |
|
} |
688 |
19 |
List<String> urls = new ArrayList<String>(); |
689 |
|
|
690 |
19 |
if (this.preferredUrl != null) |
691 |
|
{ |
692 |
0 |
urls.add(preferredUrl); |
693 |
|
} |
694 |
|
|
695 |
19 |
String surls = Cache.getDefault(JWS2HOSTURLS, COMPBIO_JABAWS); |
696 |
19 |
try |
697 |
|
{ |
698 |
19 |
StringTokenizer st = new StringTokenizer(surls, ","); |
699 |
38 |
while (st.hasMoreElements()) |
700 |
|
{ |
701 |
19 |
String url = null; |
702 |
19 |
try |
703 |
|
{ |
704 |
19 |
url = st.nextToken(); |
705 |
19 |
new URL(url); |
706 |
19 |
if (!urls.contains(url)) |
707 |
|
{ |
708 |
19 |
urls.add(url); |
709 |
|
} |
710 |
|
else |
711 |
|
{ |
712 |
0 |
Cache.log.warn("Ignoring duplicate url " + url + " in " |
713 |
|
+ JWS2HOSTURLS + " list"); |
714 |
|
} |
715 |
|
} catch (MalformedURLException ex) |
716 |
|
{ |
717 |
0 |
Cache.log.warn("Problem whilst trying to make a URL from '" |
718 |
0 |
+ ((url != null) ? url : "<null>") + "'"); |
719 |
0 |
Cache.log.warn( |
720 |
|
"This was probably due to a malformed comma separated list" |
721 |
|
+ " in the " + JWS2HOSTURLS |
722 |
|
+ " entry of $(HOME)/.jalview_properties)"); |
723 |
0 |
Cache.log.debug("Exception was ", ex); |
724 |
|
} |
725 |
|
} |
726 |
|
} catch (Exception ex) |
727 |
|
{ |
728 |
0 |
Cache.log.warn("Error parsing comma separated list of urls in " |
729 |
|
+ JWS2HOSTURLS + " preference.", ex); |
730 |
|
} |
731 |
19 |
return urls; |
732 |
|
} |
733 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
734 |
466 |
public Vector<Jws2Instance> getServices()... |
735 |
|
{ |
736 |
466 |
return (services == null) ? new Vector<Jws2Instance>() |
737 |
|
: new Vector<Jws2Instance>(services); |
738 |
|
} |
739 |
|
|
740 |
|
|
741 |
|
|
742 |
|
|
743 |
|
@param |
744 |
|
@return |
745 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.44 |
|
746 |
0 |
public static boolean testServiceUrl(URL foo)... |
747 |
|
{ |
748 |
0 |
try |
749 |
|
{ |
750 |
0 |
compbio.ws.client.WSTester |
751 |
|
.main(new String[] |
752 |
|
{ "-h=" + foo.toString() }); |
753 |
|
} catch (Exception e) |
754 |
|
{ |
755 |
0 |
e.printStackTrace(); |
756 |
0 |
return false; |
757 |
|
} catch (OutOfMemoryError e) |
758 |
|
{ |
759 |
0 |
e.printStackTrace(); |
760 |
0 |
return false; |
761 |
|
} catch (Error e) |
762 |
|
{ |
763 |
0 |
e.printStackTrace(); |
764 |
0 |
return false; |
765 |
|
} |
766 |
|
|
767 |
0 |
return true; |
768 |
|
} |
769 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
770 |
0 |
public boolean restart()... |
771 |
|
{ |
772 |
0 |
synchronized (this) |
773 |
|
{ |
774 |
0 |
if (running) |
775 |
|
{ |
776 |
0 |
aborted = true; |
777 |
|
} |
778 |
|
else |
779 |
|
{ |
780 |
0 |
running = true; |
781 |
|
} |
782 |
0 |
return aborted; |
783 |
|
} |
784 |
|
} |
785 |
|
|
786 |
|
|
787 |
|
|
788 |
|
|
789 |
|
|
790 |
|
|
791 |
|
@param |
792 |
|
@return |
793 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
794 |
11 |
public Thread startDiscoverer(PropertyChangeListener changeSupport2)... |
795 |
|
{ |
796 |
|
|
797 |
|
|
798 |
|
|
799 |
|
|
800 |
|
|
801 |
|
|
802 |
|
|
803 |
|
|
804 |
|
|
805 |
|
|
806 |
11 |
if (isRunning()) |
807 |
|
{ |
808 |
2 |
setAborted(true); |
809 |
|
} |
810 |
11 |
addPropertyChangeListener(changeSupport2); |
811 |
11 |
Thread thr = new Thread(this); |
812 |
11 |
thr.start(); |
813 |
11 |
return thr; |
814 |
|
} |
815 |
|
|
816 |
|
|
817 |
|
@return |
818 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
819 |
53 |
public Vector<String> getInvalidServiceUrls()... |
820 |
|
{ |
821 |
53 |
return invalidServiceUrls; |
822 |
|
} |
823 |
|
|
824 |
|
|
825 |
|
@return |
826 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
827 |
53 |
public Vector<String> getUrlsWithoutServices()... |
828 |
|
{ |
829 |
53 |
return urlsWithoutServices; |
830 |
|
} |
831 |
|
|
832 |
|
|
833 |
|
|
834 |
|
|
835 |
|
|
836 |
|
@param |
837 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 5 |
Complexity Density: 1.25 |
|
838 |
0 |
public synchronized void addUrlwithnoservices(String jwsservers)... |
839 |
|
{ |
840 |
0 |
if (urlsWithoutServices == null) |
841 |
|
{ |
842 |
0 |
urlsWithoutServices = new Vector<String>(); |
843 |
|
} |
844 |
|
|
845 |
0 |
if ((invalidServiceUrls == null |
846 |
|
|| !invalidServiceUrls.contains(jwsservers)) |
847 |
|
&& !urlsWithoutServices.contains(jwsservers)) |
848 |
|
{ |
849 |
0 |
urlsWithoutServices.add(jwsservers); |
850 |
|
} |
851 |
|
} |
852 |
|
|
853 |
|
|
854 |
|
|
855 |
|
|
856 |
|
@param |
857 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
858 |
0 |
public synchronized void addInvalidServiceUrl(String jwsservers)... |
859 |
|
{ |
860 |
0 |
if (invalidServiceUrls == null) |
861 |
|
{ |
862 |
0 |
invalidServiceUrls = new Vector<String>(); |
863 |
|
} |
864 |
0 |
if (!invalidServiceUrls.contains(jwsservers)) |
865 |
|
{ |
866 |
0 |
invalidServiceUrls.add(jwsservers); |
867 |
|
} |
868 |
|
} |
869 |
|
|
870 |
|
|
871 |
|
|
872 |
|
@return |
873 |
|
|
874 |
|
|
|
|
| 37.1% |
Uncovered Elements: 22 (35) |
Complexity: 10 |
Complexity Density: 0.43 |
|
875 |
131 |
public String getErrorMessages()... |
876 |
|
{ |
877 |
131 |
if (!isRunning() && !isAborted()) |
878 |
|
{ |
879 |
53 |
StringBuffer ermsg = new StringBuffer(); |
880 |
53 |
boolean list = false; |
881 |
53 |
if (getInvalidServiceUrls() != null |
882 |
|
&& getInvalidServiceUrls().size() > 0) |
883 |
|
{ |
884 |
0 |
ermsg.append(MessageManager.getString("warn.urls_not_contacted") |
885 |
|
+ ": \n"); |
886 |
0 |
for (String svcurl : getInvalidServiceUrls()) |
887 |
|
{ |
888 |
0 |
if (list) |
889 |
|
{ |
890 |
0 |
ermsg.append(", "); |
891 |
|
} |
892 |
0 |
list = true; |
893 |
0 |
ermsg.append(svcurl); |
894 |
|
} |
895 |
0 |
ermsg.append("\n\n"); |
896 |
|
} |
897 |
53 |
list = false; |
898 |
53 |
if (getUrlsWithoutServices() != null |
899 |
|
&& getUrlsWithoutServices().size() > 0) |
900 |
|
{ |
901 |
0 |
ermsg.append( |
902 |
|
MessageManager.getString("warn.urls_no_jaba") + ": \n"); |
903 |
0 |
for (String svcurl : getUrlsWithoutServices()) |
904 |
|
{ |
905 |
0 |
if (list) |
906 |
|
{ |
907 |
0 |
ermsg.append(", "); |
908 |
|
} |
909 |
0 |
list = true; |
910 |
0 |
ermsg.append(svcurl); |
911 |
|
} |
912 |
0 |
ermsg.append("\n"); |
913 |
|
} |
914 |
53 |
if (ermsg.length() > 1) |
915 |
|
{ |
916 |
0 |
return ermsg.toString(); |
917 |
|
} |
918 |
|
|
919 |
|
} |
920 |
131 |
return null; |
921 |
|
} |
922 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 7 |
Complexity Density: 1 |
|
923 |
0 |
public int getServerStatusFor(String url)... |
924 |
|
{ |
925 |
0 |
if (validServiceUrls != null && validServiceUrls.contains(url)) |
926 |
|
{ |
927 |
0 |
return 1; |
928 |
|
} |
929 |
0 |
if (urlsWithoutServices != null && urlsWithoutServices.contains(url)) |
930 |
|
{ |
931 |
0 |
return 0; |
932 |
|
} |
933 |
0 |
if (invalidServiceUrls != null && invalidServiceUrls.contains(url)) |
934 |
|
{ |
935 |
0 |
return -1; |
936 |
|
} |
937 |
0 |
return -2; |
938 |
|
} |
939 |
|
|
940 |
|
|
941 |
|
|
942 |
|
|
943 |
|
|
944 |
|
|
945 |
|
@param |
946 |
|
@return |
947 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
|
948 |
0 |
public Jws2Instance getPreferredServiceFor(String[] serviceURLs)... |
949 |
|
{ |
950 |
0 |
HashSet<String> urls = new HashSet<String>(); |
951 |
0 |
urls.addAll(Arrays.asList(serviceURLs)); |
952 |
0 |
Jws2Instance match = null; |
953 |
0 |
if (services != null) |
954 |
|
{ |
955 |
0 |
for (Jws2Instance svc : services) |
956 |
|
{ |
957 |
0 |
if (urls.contains(svc.getServiceTypeURI())) |
958 |
|
{ |
959 |
0 |
if (match == null) |
960 |
|
{ |
961 |
|
|
962 |
|
|
963 |
0 |
match = svc; |
964 |
|
} |
965 |
0 |
if (urls.contains(svc.getUri())) |
966 |
|
{ |
967 |
|
|
968 |
|
|
969 |
0 |
return svc; |
970 |
|
} |
971 |
|
} |
972 |
|
} |
973 |
|
} |
974 |
0 |
return match; |
975 |
|
} |
976 |
|
|
977 |
|
Map<String, Map<String, String>> preferredServiceMap = new HashMap<String, Map<String, String>>();; |
978 |
|
|
979 |
|
|
980 |
|
|
981 |
|
|
982 |
|
@param |
983 |
|
|
984 |
|
@param |
985 |
|
|
986 |
|
@return |
987 |
|
|
988 |
|
|
|
|
| 80% |
Uncovered Elements: 5 (25) |
Complexity: 8 |
Complexity Density: 0.53 |
|
989 |
474 |
public Jws2Instance getPreferredServiceFor(AlignFrame af,... |
990 |
|
String serviceType) |
991 |
|
{ |
992 |
474 |
String serviceurl = null; |
993 |
474 |
synchronized (preferredServiceMap) |
994 |
|
{ |
995 |
474 |
String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); |
996 |
474 |
Map<String, String> prefmap = preferredServiceMap.get(afid); |
997 |
474 |
if (afid.length() > 0 && prefmap == null) |
998 |
|
{ |
999 |
|
|
1000 |
474 |
prefmap = preferredServiceMap.get(""); |
1001 |
|
} |
1002 |
474 |
if (prefmap != null) |
1003 |
|
{ |
1004 |
0 |
serviceurl = prefmap.get(serviceType); |
1005 |
|
} |
1006 |
|
|
1007 |
|
} |
1008 |
474 |
Jws2Instance response = null; |
1009 |
474 |
for (Jws2Instance svc : services) |
1010 |
|
{ |
1011 |
4266 |
if (svc.serviceType.equals(serviceType)) |
1012 |
|
{ |
1013 |
474 |
if (serviceurl == null || serviceurl.equals(svc.getHost())) |
1014 |
|
{ |
1015 |
474 |
response = svc; |
1016 |
474 |
break; |
1017 |
|
} |
1018 |
|
} |
1019 |
|
} |
1020 |
474 |
return response; |
1021 |
|
} |
1022 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
1023 |
0 |
public void setPreferredServiceFor(AlignFrame af, String serviceType,... |
1024 |
|
String serviceAction, Jws2Instance selectedServer) |
1025 |
|
{ |
1026 |
0 |
String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); |
1027 |
0 |
if (preferredServiceMap == null) |
1028 |
|
{ |
1029 |
0 |
preferredServiceMap = new HashMap<String, Map<String, String>>(); |
1030 |
|
} |
1031 |
0 |
Map<String, String> prefmap = preferredServiceMap.get(afid); |
1032 |
0 |
if (prefmap == null) |
1033 |
|
{ |
1034 |
0 |
prefmap = new HashMap<String, String>(); |
1035 |
0 |
preferredServiceMap.put(afid, prefmap); |
1036 |
|
} |
1037 |
0 |
prefmap.put(serviceType, selectedServer.getHost()); |
1038 |
0 |
prefmap.put(serviceAction, selectedServer.getHost()); |
1039 |
|
} |
1040 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1041 |
0 |
public void setPreferredServiceFor(String serviceType,... |
1042 |
|
String serviceAction, Jws2Instance selectedServer) |
1043 |
|
{ |
1044 |
0 |
setPreferredServiceFor(null, serviceType, serviceAction, |
1045 |
|
selectedServer); |
1046 |
|
} |
1047 |
|
|
1048 |
|
|
1049 |
|
|
1050 |
|
|
1051 |
|
|
1052 |
|
|
1053 |
|
@param |
1054 |
|
@throws |
1055 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
1056 |
0 |
public void setPreferredUrl(String value) throws MalformedURLException... |
1057 |
|
{ |
1058 |
0 |
if (value != null && value.trim().length() > 0) |
1059 |
|
{ |
1060 |
0 |
new URL(value); |
1061 |
0 |
preferredUrl = value; |
1062 |
|
} |
1063 |
|
} |
1064 |
|
} |