JAL-3253 jalview.bin.Instance handles all singleton instances -
[jalview.git] / src / jalview / fts / service / pdb / PDBFTSRestClient.java
index 0e20338..8e929e7 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.fts.service.pdb;
 
+import jalview.bin.Instance;
 import jalview.datamodel.SequenceI;
 import jalview.fts.api.FTSData;
 import jalview.fts.api.FTSDataColumnI;
@@ -56,12 +57,19 @@ import com.sun.jersey.api.client.config.DefaultClientConfig;
 public class PDBFTSRestClient extends FTSRestClient
 {
 
-  private static FTSRestClientI instance = null;
+  public static FTSRestClientI getInstance()
+  {
+    Instance j = Instance.getInstance();
+    return (j.pdbFTSRestClient == null
+            ? j.pdbFTSRestClient = new PDBFTSRestClient()
+            : j.pdbFTSRestClient);
+  }
 
   public static final String PDB_SEARCH_ENDPOINT = "https://www.ebi.ac.uk/pdbe/search/pdb/select?";
 
-  protected PDBFTSRestClient()
+  private PDBFTSRestClient()
   {
+    // singleton
   }
 
   /**
@@ -175,7 +183,7 @@ public class PDBFTSRestClient extends FTSRestClient
 
       // Get the JSON string from the response object or directly from the
       // client (JavaScript)
-      Map<String, Object> jsonObj = (status == 200
+      Map<String, Object> jsonObj = (Platform.isJS() && status == 200
               ? clientResponse.getEntity(Map.class)
               : null);
       String responseString = (jsonObj == null
@@ -459,15 +467,6 @@ public static String parseJsonExceptionString(String jsonErrorResponse)
     return "/fts/pdb_data_columns.txt";
   }
 
-  public static FTSRestClientI getInstance()
-  {
-    if (instance == null)
-    {
-      instance = new PDBFTSRestClient();
-    }
-    return instance;
-  }
-
   private Collection<FTSDataColumnI> allDefaultDisplayedStructureDataColumns;
 
   public Collection<FTSDataColumnI> getAllDefaultDisplayedStructureDataColumns()