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;
public class EnsemblInfo extends EnsemblRestClient
{
+ private static EnsemblInfo instance;
+
+ /**
+ * Some question as to whether it is necessary to do this for each applet. IN
+ * PRINCIPLE, applets could set different properties for the origin of Ensembl
+ * data. But I suggest this is unlikely. If we DO care about that possibility,
+ * then we need to set doICare to Platform.isJS();
+ *
+ */
+ private final static boolean doICare = false;// Platform.isJS();
+
+ /**
+ * On first request only, populate the lookup map by fetching the list of
+ * divisions known to EnsemblGenomes.
+ *
+ */
+ private static EnsemblInfo getInstance()
+ {
+
+ // BH 2019.05.08 need to isolate static fields in JavaScript
+
+ EnsemblInfo i = instance;
+ @SuppressWarnings("unused")
+ ThreadGroup g = null;
+
+ if (doICare)
+ {
+ g = Thread.currentThread().getThreadGroup();
+ /**
+ * @j2sNative i = g._jalviewEnsemblInstance;
+ *
+ */
+ }
+ if (i == null)
+ {
+ i = new EnsemblInfo();
+
+ if (doICare)
+ {
+ /**
+ * @j2sNative g._jalviewEnsemblInstance = i;
+ *
+ */
+ }
+ else
+ {
+ instance = i;
+ }
+ }
+ return i;
+ }
+
/*
* cached results of REST /info/divisions service, currently
* <pre>
* The values for EnsemblGenomes are retrieved by a REST call, that for
* Ensembl is added programmatically for convenience of lookup
*/
- private static Map<String, String> divisions;
+ private Map<String, String> divisions = new HashMap<>();
+
+ private EnsemblInfo()
+ {
+
+ /*
+ * 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
+ }
+ }
@Override
public String getDbName()
* @param division
* @return
*/
- public String getDomain(String division)
+ public static String getDomain(String division)
{
- 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
- }
+ return getInstance().divisions.get(division.toUpperCase());
}
/**
*
* @return
*/
- public Set<String> getDivisions() {
- if (divisions == null)
- {
- fetchDivisions();
- }
-
- return divisions.keySet();
+ public static Set<String> getDivisions()
+ {
+ return getInstance().divisions.keySet();
}
}