+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)\r
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle\r
+ * \r
+ * This file is part of Jalview.\r
+ * \r
+ * Jalview is free software: you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License \r
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
+ * \r
+ * Jalview is distributed in the hope that it will be useful, but \r
+ * WITHOUT ANY WARRANTY; without even the implied warranty \r
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
+ * PURPOSE. See the GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
package jalview.ws.seqfetcher;\r
\r
import jalview.datamodel.AlignmentI;\r
"Don't know how to fetch from this database :" + db);\r
DbSourceProxy fetcher = getSourceProxy(db);\r
boolean doMultiple = fetcher.getAccessionSeparator() != null; // No\r
- // separator\r
- // - no\r
- // Multiple\r
- // Queries\r
+ // separator\r
+ // - no\r
+ // Multiple\r
+ // Queries\r
Enumeration qs = query.elements();\r
while (qs.hasMoreElements())\r
{\r
{\r
qsb.append((String) qs.nextElement());\r
if (qs.hasMoreElements() && doMultiple) // and not reached limit for\r
- // multiple queries at one\r
- // time for this source\r
+ // multiple queries at one\r
+ // time for this source\r
{\r
qsb.append(fetcher.getAccessionSeparator());\r
}\r
} while (doMultiple && qs.hasMoreElements());\r
- \r
- AlignmentI seqset=null;\r
- try {\r
+\r
+ AlignmentI seqset = null;\r
+ try\r
+ {\r
// create a fetcher and go to it\r
seqset = fetcher.getSequenceRecords(qsb.toString());\r
} catch (Exception ex)\r
{\r
- System.err.println("Failed to retrieve the following from "+db);\r
+ System.err.println("Failed to retrieve the following from "\r
+ + db);\r
System.err.println(qsb);\r
ex.printStackTrace(System.err);\r
}\r
{\r
ret = new SequenceI[rseqs.size()];\r
Enumeration sqs = rseqs.elements();\r
- int si=0;\r
+ int si = 0;\r
while (sqs.hasMoreElements())\r
{\r
SequenceI s = (SequenceI) sqs.nextElement();\r
return dbs;\r
}\r
\r
-}
\ No newline at end of file
+ /**\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();\r
+ }\r
+ FETCHABLEDBS.put(proxy.getDbSource(), proxy);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * test if the database handler for dbName contains the given dbProperty\r
+ * \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
+ DbSourceProxy proxy = getSourceProxy(dbName);\r
+ if (proxy != null)\r
+ {\r
+ if (proxy.getDbSourceProperties() != null)\r
+ {\r
+ return proxy.getDbSourceProperties().containsKey(dbProperty);\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
+ DbSourceProxy dbp = (DbSourceProxy) FETCHABLEDBS.get(dbn);\r
+ if (class1.isAssignableFrom(dbp.getClass()))\r
+ {\r
+ src.addElement(dbn);\r
+ }\r
+ }\r
+ if (src.size() > 0)\r
+ {\r
+ src.copyInto(sources = new String[src.size()]);\r
+ }\r
+ return sources;\r
+ }\r
+}\r