JAL-3210 Barebones gradle/buildship/eclipse. See README
[jalview.git] / src / jalview / ext / ensembl / EnsemblInfo.java
index a59a64d..97a8e74 100644 (file)
@@ -1,10 +1,10 @@
 package jalview.ext.ensembl;
 
-import jalview.bin.ApplicationSingletonProvider;
-import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefSource;
+import jalview.util.JSONUtils;
 
+import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -16,48 +16,9 @@ import java.util.Set;
 
 import org.json.simple.parser.ParseException;
 
-public class EnsemblInfo extends EnsemblRestClient implements ApplicationSingletonI
+public class EnsemblInfo extends EnsemblRestClient
 {
 
-  /**
-   * On first request only, populate the lookup map by fetching the list of
-   * divisions known to EnsemblGenomes
-   * 
-   */
-  private static EnsemblInfo getInstance()
-  {
-    return (EnsemblInfo) ApplicationSingletonProvider.getInstance(EnsemblInfo.class);
-  }
-
-  private EnsemblInfo()
-  {
-    // use getInstance()
-
-    /*
-     * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL"
-     */
-    divisions.put(DBRefSource.ENSEMBL.toUpperCase(), ensemblDomain);
-    try
-    {
-      @SuppressWarnings("unchecked")
-      Iterator<Object> rvals = (Iterator<Object>) getJSON(
-              getDivisionsUrl(ensemblGenomesDomain), null, -1,
-              MODE_ITERATOR, null);
-      if (rvals == null)
-      {
-        return;
-      }
-      while (rvals.hasNext())
-      {
-        String division = rvals.next().toString();
-        divisions.put(division.toUpperCase(), ensemblGenomesDomain);
-      }
-    } catch (IOException | ParseException | NumberFormatException e)
-    {
-      // ignore
-    }
-  }
-
   /*
    * cached results of REST /info/divisions service, currently
    * <pre>
@@ -73,7 +34,7 @@ public class EnsemblInfo extends EnsemblRestClient implements ApplicationSinglet
    * The values for EnsemblGenomes are retrieved by a REST call, that for
    * Ensembl is added programmatically for convenience of lookup
    */
-  private Map<String, String> divisions = new HashMap<>();
+  private static Map<String, String> divisions;
 
   @Override
   public String getDbName()
@@ -107,9 +68,42 @@ public class EnsemblInfo extends EnsemblRestClient implements ApplicationSinglet
    * @param division
    * @return
    */
-  public static String getDomain(String division)
+  public String getDomain(String division)
   {
-    return getInstance().divisions.get(division.toUpperCase());
+    if (divisions == null)
+    {
+      fetchDivisions();
+    }
+    return divisions.get(division.toUpperCase());
+  }
+
+  /**
+   * On first request only, populate the lookup map by fetching the list of
+   * divisions known to EnsemblGenomes.
+   */
+  void fetchDivisions()
+  {
+    divisions = new HashMap<>();
+
+    /*
+     * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL"
+     */
+    divisions.put(DBRefSource.ENSEMBL.toUpperCase(), ensemblDomain);
+    try
+    {
+      @SuppressWarnings("unchecked")
+         Iterator<Object> rvals = (Iterator<Object>) getJSON(getDivisionsUrl(ensemblGenomesDomain), null, -1, MODE_ITERATOR, null);
+      if (rvals == null)
+         return;
+      while (rvals.hasNext())
+      {
+        String division = rvals.next().toString();
+        divisions.put(division.toUpperCase(), ensemblGenomesDomain);
+      }
+    } catch (IOException | ParseException | NumberFormatException e)
+    {
+      // ignore
+    }
   }
 
   /**
@@ -130,8 +124,12 @@ public class EnsemblInfo extends EnsemblRestClient implements ApplicationSinglet
    * 
    * @return
    */
-  public static Set<String> getDivisions()
-  {
-    return getInstance().divisions.keySet();
+  public Set<String> getDivisions() {
+    if (divisions == null)
+    {
+      fetchDivisions();
+    }
+
+    return divisions.keySet();
   }
 }