JAL-3253 preliminary static fixes for JavaScript part 3 of 3
[jalview.git] / src / jalview / ws / jws1 / Discoverer.java
index ec8c89c..25fcc6b 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.ws.jws1;
 
+import jalview.bin.Jalview;
 import jalview.gui.JvOptionPane;
 import jalview.util.MessageManager;
 
@@ -36,7 +37,31 @@ import ext.vamsas.ServiceHandles;
 
 public class Discoverer implements Runnable
 {
-  ext.vamsas.IRegistry registry; // the root registry service.
+
+  public static Discoverer getInstance()
+  {
+    Jalview j = Jalview.getInstance();
+    return (j.discoverer == null ? j.discoverer = new Discoverer()
+            : j.discoverer);
+  }
+
+  private java.net.URL RootServiceURL = null;
+
+  private Vector<URL> ServiceURLList = null;
+
+  private boolean reallyDiscoverServices = true;
+
+  private Hashtable<String, Vector<ServiceHandle>> services = null;
+
+  public Hashtable<String, Vector<ServiceHandle>> getServices()
+  {
+    return services;
+  }
+
+  private Vector<ServiceHandle> serviceList = null;
+
+  // private ext.vamsas.IRegistry registry; // the root registry service.
+
 
   private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
           this);
@@ -110,19 +135,6 @@ public class Discoverer implements Runnable
     return server;
   }
 
-  static private java.net.URL RootServiceURL = null;
-
-  static public Vector<URL> ServiceURLList = null;
-
-  static private boolean reallyDiscoverServices = true;
-
-  public static java.util.Hashtable<String, Vector<ServiceHandle>> services = null;
-  // stored by
-  // abstractServiceType
-  // string
-
-  public static java.util.Vector<ServiceHandle> serviceList = null;
-
   static private Vector<URL> getDiscoveryURLS()
   {
     Vector<URL> urls = new Vector<>();
@@ -178,18 +190,19 @@ public class Discoverer implements Runnable
   {
     jalview.bin.Cache.log
             .debug("(Re)-Initialising the discovery URL list.");
+    Discoverer d = getInstance();
     try
     {
-      reallyDiscoverServices = jalview.bin.Cache
+      d.reallyDiscoverServices = jalview.bin.Cache
               .getDefault("DISCOVERY_START", false);
-      if (reallyDiscoverServices)
+      if (d.reallyDiscoverServices)
       {
-        ServiceURLList = getDiscoveryURLS();
+        d.ServiceURLList = getDiscoveryURLS();
       }
       else
       {
         jalview.bin.Cache.log.debug("Setting default services");
-        services = new Hashtable<>();
+        d.services = new Hashtable<>();
         // Muscle, Clustal and JPred.
         ServiceHandle[] defServices = { new ServiceHandle("MsaWS",
                 "Edgar, Robert C. (2004), MUSCLE: multiple sequence alignment "
@@ -217,16 +230,16 @@ public class Discoverer implements Runnable
                             + "\ndoi://10.1093/nar/gkv332",
                     "http://www.compbio.dundee.ac.uk/JalviewWS/services/jpred",
                     "JPred Secondary Structure Prediction") };
-        services = new Hashtable<>();
-        serviceList = new Vector<>();
-        buildServiceLists(defServices, serviceList, services);
+        d.services = new Hashtable<>();
+        d.serviceList = new Vector<>();
+        buildServiceLists(defServices, d.serviceList, d.services);
       }
 
     } catch (Exception e)
     {
       System.err.println(
               "jalview.rootRegistry is not a proper url!\nWas set to "
-                      + RootServiceURL + "\n" + e);
+                      + d.RootServiceURL + "\n" + e);
     }
 
   }
@@ -307,17 +320,18 @@ public class Discoverer implements Runnable
         cat.add(sh[i]);
         if (sh[i].getAbstractName().equals("Registry"))
         {
-          for (int s = 0, sUrls = ServiceURLList.size(); s < sUrls; s++)
+          Vector<URL> list = getInstance().ServiceURLList;
+          for (int s = 0, sUrls = list.size(); s < sUrls; s++)
           {
             java.net.URL disc_serv = null;
             try
             {
               disc_serv = new java.net.URL(sh[i].getEndpointURL());
-              if (!ServiceURLList.contains(disc_serv))
+              if (!list.contains(disc_serv))
               {
                 jalview.bin.Cache.log.debug(
                         "Adding new discovery service at " + disc_serv);
-                ServiceURLList.add(disc_serv);
+                list.add(disc_serv);
                 seenNewDiscovery = true;
               }
             } catch (Exception e)