JAL-3253 preliminary static fixes for JavaScript part 3 of 3
[jalview.git] / src / jalview / ws / rest / RestClient.java
index 08f137d..f271e62 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.ws.rest;
 
 import jalview.bin.Cache;
+import jalview.bin.Jalview;
 import jalview.datamodel.AlignmentView;
 import jalview.gui.AlignFrame;
 import jalview.gui.AlignViewport;
@@ -51,12 +52,9 @@ import javax.swing.event.MenuListener;
 public class RestClient extends WSClient
         implements WSClientI, WSMenuEntryProviderI
 {
-  RestServiceDescription service;
+  public static final String RSBS_SERVICES = "RSBS_SERVICES";
 
-  public RestClient(RestServiceDescription rsd)
-  {
-    service = rsd;
-  }
+  RestServiceDescription service;
 
   /**
    * parent alignframe for this job
@@ -68,6 +66,10 @@ public class RestClient extends WSClient
    */
   AlignViewport av;
 
+  boolean headless = false;
+
+  protected Vector<String> services = null;
+
   /**
    * get the alignFrame for the associated input data if it exists.
    * 
@@ -78,13 +80,28 @@ public class RestClient extends WSClient
     return jalview.gui.Desktop.getAlignFrameFor(av);
   }
 
+  RestClient getInstance()
+  {
+    Jalview j = Jalview.getInstance();
+    return (j.restClient == null ? j.restClient = new RestClient()
+            : j.restClient);
+  }
+
+  private RestClient()
+  {
+
+  }
+
+  public RestClient(RestServiceDescription rsd)
+  {
+    service = rsd;
+  }
+
   public RestClient(RestServiceDescription service2, AlignFrame alignFrame)
   {
     this(service2, alignFrame, false);
   }
 
-  boolean headless = false;
-
   public RestClient(RestServiceDescription service2, AlignFrame alignFrame,
           boolean nogui)
   {
@@ -344,8 +361,8 @@ public class RestClient extends WSClient
     String action = "Analysis",
             description = "Sequence Harmony and Multi-Relief (Brandt et al. 2010)",
             name = MessageManager.getString("label.multiharmony");
-    Hashtable<String, InputType> iparams = new Hashtable<String, InputType>();
-    jalview.ws.rest.params.JobConstant toolp;
+    Hashtable<String, InputType> iparams = new Hashtable<>();
+    // jalview.ws.rest.params.JobConstant toolp;
     // toolp = new jalview.ws.rest.JobConstant("tool","jalview");
     // iparams.put(toolp.token, toolp);
     // toolp = new jalview.ws.rest.params.JobConstant("mbjob[method]","shmr");
@@ -399,15 +416,13 @@ public class RestClient extends WSClient
     return true;
   }
 
-  protected static Vector<String> services = null;
-
-  public static final String RSBS_SERVICES = "RSBS_SERVICES";
-
   public static RestClient[] getRestClients()
   {
-    if (services == null)
+    RestClient c = Jalview.getInstance().restClient;
+
+    if (c.services == null)
     {
-      services = new Vector<String>();
+      c.services = new Vector<>();
       try
       {
         for (RestServiceDescription descr : RestServiceDescription
@@ -415,7 +430,7 @@ public class RestClient extends WSClient
                         jalview.bin.Cache.getDefault(RSBS_SERVICES,
                                 makeShmmrRestClient().service.toString())))
         {
-          services.add(descr.toString());
+          c.services.add(descr.toString());
         }
       } catch (Exception ex)
       {
@@ -425,9 +440,9 @@ public class RestClient extends WSClient
       }
 
     }
-    RestClient[] lst = new RestClient[services.size()];
+    RestClient[] lst = new RestClient[c.services.size()];
     int i = 0;
-    for (String svc : services)
+    for (String svc : c.services)
     {
       lst[i++] = new RestClient(new RestServiceDescription(svc));
     }
@@ -446,7 +461,7 @@ public class RestClient extends WSClient
 
   public static Vector<String> getRsbsDescriptions()
   {
-    Vector<String> rsbsDescrs = new Vector<String>();
+    Vector<String> rsbsDescrs = new Vector<>();
     for (RestClient rsbs : getRestClients())
     {
       rsbsDescrs.add(rsbs.getRestDescription().toString());
@@ -459,9 +474,10 @@ public class RestClient extends WSClient
     if (rsbsUrls != null)
     {
       // TODO: consider validating services ?
-      services = new Vector<String>(rsbsUrls);
+      RestClient c = Jalview.getInstance().restClient;
+      c.services = new Vector<>(rsbsUrls);
       StringBuffer sprop = new StringBuffer();
-      for (String s : services)
+      for (String s : c.services)
       {
         sprop.append(s);
       }