+ /**
+ * the jalview .properties entry for JWS2 URLS
+ */
+ final static String JWS2HOSTURLS = "JWS2HOSTURLS";
+
+ public static void setServiceUrls(Vector<String> urls)
+ {
+ if (urls != null)
+ {
+ StringBuffer urlbuffer = new StringBuffer();
+ String sep = "";
+ for (String url : urls)
+ {
+ urlbuffer.append(sep);
+ urlbuffer.append(url);
+ sep = ",";
+ }
+ Cache.setProperty(JWS2HOSTURLS, urlbuffer.toString());
+ }
+ else
+ {
+ Cache.removeProperty(JWS2HOSTURLS);
+ }
+ }
+
+ private static Vector<String> testUrls=null;
+ public static Vector<String> getServiceUrls()
+ {
+ if (testUrls!=null)
+ {
+ // return test urls, if there are any, instead of touching cache
+ return testUrls;
+ }
+ String surls = Cache.getDefault(JWS2HOSTURLS,
+ "http://www.compbio.dundee.ac.uk/jabaws");
+ Vector<String> urls = new Vector<String>();
+ try
+ {
+ StringTokenizer st = new StringTokenizer(surls, ",");
+ while (st.hasMoreElements())
+ {
+ String url = null;
+ try
+ {
+ java.net.URL u = new java.net.URL(url = st.nextToken());
+ if (!urls.contains(url))
+ {
+ urls.add(url);
+ }
+ else
+ {
+ jalview.bin.Cache.log.info("Ignoring duplicate url in "
+ + JWS2HOSTURLS + " list");
+ }
+ } catch (Exception ex)
+ {
+ jalview.bin.Cache.log
+ .warn("Problem whilst trying to make a URL from '"
+ + ((url != null) ? url : "<null>") + "'");
+ jalview.bin.Cache.log
+ .warn("This was probably due to a malformed comma separated list"
+ + " in the "
+ + JWS2HOSTURLS
+ + " entry of $(HOME)/.jalview_properties)");
+ jalview.bin.Cache.log.debug("Exception was ", ex);
+ }
+ }
+ } catch (Exception ex)
+ {
+ jalview.bin.Cache.log.warn(
+ "Error parsing comma separated list of urls in "
+ + JWS2HOSTURLS + " preference.", ex);
+ }
+ if (urls.size() >= 0)
+ {
+ return urls;
+ }
+ return null;
+ }
+
+ public Vector<Jws2Instance> getServices()
+ {
+ return (services == null) ? new Vector<Jws2Instance>()
+ : new Vector<Jws2Instance>(services);
+ }
+
+ /**
+ * test the given URL with the JabaWS test code
+ *
+ * @param foo
+ * @return
+ */
+ public static boolean testServiceUrl(URL foo)
+ {
+ try
+ {
+ compbio.ws.client.WSTester.main(new String[]
+ { "-h=" + foo.toString() });
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ return false;
+ } catch (OutOfMemoryError e)
+ {
+ e.printStackTrace();
+ return false;
+ } catch (Error e)
+ {
+ e.printStackTrace();
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Start a fresh discovery thread and notify the given object when we're
+ * finished. Any known existing threads will be killed before this one is
+ * started.
+ *
+ * @param changeSupport2
+ * @return new thread
+ */
+ public Thread startDiscoverer(PropertyChangeListener changeSupport2)
+ {
+ if (isRunning())
+ {
+ setAborted(true);
+ }
+ addPropertyChangeListener(changeSupport2);
+ Thread thr = new Thread(this);
+ thr.start();
+ return thr;
+ }
+
+ Vector<String> invalidServiceUrls = null, urlsWithoutServices = null;
+
+ /**
+ * @return the invalidServiceUrls
+ */
+ public Vector<String> getInvalidServiceUrls()
+ {
+ return invalidServiceUrls;
+ }
+
+ /**
+ * @return the urlsWithoutServices
+ */
+ public Vector<String> getUrlsWithoutServices()
+ {
+ return urlsWithoutServices;
+ }
+
+ /**
+ * add an 'empty' JABA server to the list. Only servers not already in the
+ * 'bad URL' list will be added to this list.
+ *
+ * @param jwsservers
+ */
+ public synchronized void addUrlwithnoservices(String jwsservers)
+ {
+ if (urlsWithoutServices == null)
+ {
+ urlsWithoutServices = new Vector<String>();
+ }
+
+ if ((invalidServiceUrls == null || !invalidServiceUrls
+ .contains(jwsservers))
+ && !urlsWithoutServices.contains(jwsservers))
+ {
+ urlsWithoutServices.add(jwsservers);
+ }
+ }
+
+ /**
+ * add a bad URL to the list
+ *
+ * @param jwsservers
+ */
+ public synchronized void addInvalidServiceUrl(String jwsservers)
+ {
+ if (invalidServiceUrls == null)
+ {
+ invalidServiceUrls = new Vector<String>();
+ }
+ if (!invalidServiceUrls.contains(jwsservers))
+ {
+ invalidServiceUrls.add(jwsservers);
+ }
+ }
+
+ /**
+ *
+ * @return a human readable report of any problems with the service URLs used
+ * for discovery
+ */
+ public String getErrorMessages()
+ {
+ if (!isRunning() && !isAborted())
+ {
+ StringBuffer ermsg = new StringBuffer();
+ boolean list = false;
+ if (getInvalidServiceUrls() != null
+ && getInvalidServiceUrls().size() > 0)
+ {
+ ermsg.append("URLs that could not be contacted: \n");
+ for (String svcurl : getInvalidServiceUrls())
+ {
+ if (list)
+ {
+ ermsg.append(", ");
+ }
+ list = true;
+ ermsg.append(svcurl);
+ }
+ ermsg.append("\n\n");
+ }
+ list = false;
+ if (getUrlsWithoutServices() != null
+ && getUrlsWithoutServices().size() > 0)
+ {
+ ermsg.append("URLs without any JABA Services : \n");
+ for (String svcurl : getUrlsWithoutServices())
+ {
+ if (list)
+ {
+ ermsg.append(", ");
+ }
+ list = true;
+ ermsg.append(svcurl);
+ }
+ ermsg.append("\n");
+ }
+ if (ermsg.length() > 1)
+ {
+ return ermsg.toString();
+ }
+
+ }
+ return null;
+ }