added generic method for adding new database proxies by reflection on instance.
authorjprocter <Jim Procter>
Fri, 16 Nov 2007 15:07:18 +0000 (15:07 +0000)
committerjprocter <Jim Procter>
Fri, 16 Nov 2007 15:07:18 +0000 (15:07 +0000)
src/jalview/ws/seqfetcher/ASequenceFetcher.java

index 7b455bf..9c2bfd4 100644 (file)
@@ -201,4 +201,49 @@ public class ASequenceFetcher
     return dbs;\r
   }\r
 \r
+  /**\r
+   * constructs and instance of the proxy and registers it as a valid\r
+   * dbrefsource\r
+   * \r
+   * @param dbSourceProxy\r
+   *                reference for class implementing\r
+   *                jalview.ws.seqfetcher.DbSourceProxy\r
+   * @throws java.lang.IllegalArgumentException\r
+   *                 if class does not implement\r
+   *                 jalview.ws.seqfetcher.DbSourceProxy\r
+   */\r
+  protected void addDBRefSourceImpl(Class dbSourceProxy)\r
+          throws java.lang.IllegalArgumentException\r
+  {\r
+    try\r
+    {\r
+      Object proxyObj = dbSourceProxy.getConstructor(\r
+              null).newInstance(null);\r
+      if (!DbSourceProxy.class.isInstance(proxyObj))\r
+      {\r
+        throw new IllegalArgumentException(\r
+                dbSourceProxy.toString()\r
+                        + " does not implement the jalview.ws.seqfetcher.DbSourceProxy");\r
+      }\r
+      DbSourceProxy proxy = (DbSourceProxy) proxyObj; \r
+      if (proxy != null)\r
+      {\r
+        if (FETCHABLEDBS == null)\r
+        {\r
+          FETCHABLEDBS = new Hashtable();\r
+        }\r
+        FETCHABLEDBS.put(proxy.getDbSource(), proxy);\r
+      }\r
+    } \r
+    catch (IllegalArgumentException e)\r
+    {\r
+      throw e;\r
+    }\r
+    catch (Exception e)\r
+    {\r
+      // Serious problems if this happens.\r
+      throw new Error("DBRefSource Implementation Exception", e);\r
+    }\r
+  }\r
+\r
 }
\ No newline at end of file