+ /**\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 jalview.ws.seqfetcher.DbSourceProxy\r
+ */\r
+ protected void addDBRefSourceImpl(Class dbSourceProxy)\r
+ throws java.lang.IllegalArgumentException\r
+ {\r
+ DbSourceProxy proxy = null;\r
+ try\r
+ {\r
+ Object proxyObj = dbSourceProxy.getConstructor(null)\r
+ .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
+ proxy = (DbSourceProxy) proxyObj;\r
+ } catch (IllegalArgumentException e)\r
+ {\r
+ throw e;\r
+ } catch (Exception e)\r
+ {\r
+ // Serious problems if this happens.\r
+ throw new Error("DBRefSource Implementation Exception", e);\r
+ }\r
+ addDbRefSourceImpl(proxy);\r
+ }\r
+\r
+ /**\r
+ * add the properly initialised DbSourceProxy object 'proxy' to the list of\r
+ * sequence fetchers\r
+ * \r
+ * @param proxy\r
+ */\r
+ protected void addDbRefSourceImpl(DbSourceProxy proxy)\r
+ {\r
+ if (proxy != null)\r
+ {\r
+ if (FETCHABLEDBS == null)\r
+ {\r
+ FETCHABLEDBS = new Hashtable<String, Map<String,DbSourceProxy>>();\r
+ }\r
+ Map<String,DbSourceProxy> slist = FETCHABLEDBS.get(proxy.getDbSource());\r
+ if (slist == null)\r
+ {\r
+ FETCHABLEDBS.put(proxy.getDbSource(),\r
+ slist = new Hashtable<String,DbSourceProxy>());\r
+ }\r
+ slist.put(proxy.getDbName(),proxy);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * test if the database handler for dbName contains the given dbProperty\r
+ * when a dbName resolves to a set of proxies - this method will return the result of the test for the first instance.\r
+ * TODO implement additional method to query all sources for a db to find one with a particular property\r
+ * @param dbName\r
+ * @param dbProperty\r
+ * @return true if proxy has the given property\r
+ */\r
+ public boolean hasDbSourceProperty(String dbName, String dbProperty)\r
+ {\r
+ // TODO: decide if invalidDbName exception is thrown here.\r
+\r
+ List<DbSourceProxy> proxies = getSourceProxy(dbName);\r
+ if (proxies != null)\r
+ {\r
+ for (DbSourceProxy proxy : proxies)\r
+ {\r
+ if (proxy.getDbSourceProperties() != null)\r
+ {\r
+ return proxy.getDbSourceProperties().containsKey(dbProperty);\r
+ }\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * select sources which are implemented by instances of the given class\r
+ * \r
+ * @param class that implements DbSourceProxy\r
+ * @return null or vector of source names for fetchers\r
+ */\r
+ public String[] getDbInstances(Class class1)\r
+ {\r
+ if (!jalview.ws.seqfetcher.DbSourceProxy.class.isAssignableFrom(class1))\r
+ {\r
+ throw new Error(\r
+ "Implmentation Error - getDbInstances must be given a class that implements jalview.ws.seqfetcher.DbSourceProxy (was given '"\r
+ + class1 + "')");\r
+ }\r
+ if (FETCHABLEDBS == null)\r
+ {\r
+ return null;\r
+ }\r
+ String[] sources = null;\r
+ Vector src = new Vector();\r
+ Enumeration dbs = FETCHABLEDBS.keys();\r
+ while (dbs.hasMoreElements())\r
+ {\r
+ String dbn = (String) dbs.nextElement();\r
+ for (DbSourceProxy dbp : FETCHABLEDBS.get(dbn).values())\r
+ {\r
+ if (class1.isAssignableFrom(dbp.getClass()))\r
+ {\r
+ src.addElement(dbn);\r
+ }\r
+ }\r
+ }\r
+ if (src.size() > 0)\r
+ {\r
+ src.copyInto(sources = new String[src.size()]);\r
+ }\r
+ return sources;\r
+ }\r
+ public DbSourceProxy[] getDbSourceProxyInstances(\r
+ Class class1)\r
+ {\r
+ ArrayList<DbSourceProxy> prlist=new ArrayList<DbSourceProxy>();\r
+ for (String fetchable:getSupportedDb())\r
+ for (DbSourceProxy pr:getSourceProxy(fetchable))\r
+ {\r
+ if (class1.isInstance(pr)) {prlist.add(pr);}\r
+ }\r
+ if (prlist.size()==0)\r
+ {\r
+ return null;\r
+ }\r
+ return prlist.toArray(new DbSourceProxy[0]);\r
+ }\r
+\r
+}\r