X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fseqfetcher%2FASequenceFetcher.java;h=d4bcfe8277af119a8f7715cec9274fba1041f932;hb=98af16ccc5890b980f0c4f3acfb72d7128e3a6f0;hp=7b455bf7f2dbfac92a48012525e003b89a634e99;hpb=6b406c397d41a0f2d84b75f13e7ab478932bf57d;p=jalview.git diff --git a/src/jalview/ws/seqfetcher/ASequenceFetcher.java b/src/jalview/ws/seqfetcher/ASequenceFetcher.java index 7b455bf..d4bcfe8 100644 --- a/src/jalview/ws/seqfetcher/ASequenceFetcher.java +++ b/src/jalview/ws/seqfetcher/ASequenceFetcher.java @@ -1,3 +1,20 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + */ package jalview.ws.seqfetcher; import jalview.datamodel.AlignmentI; @@ -86,10 +103,10 @@ public class ASequenceFetcher "Don't know how to fetch from this database :" + db); DbSourceProxy fetcher = getSourceProxy(db); boolean doMultiple = fetcher.getAccessionSeparator() != null; // No - // separator - // - no - // Multiple - // Queries + // separator + // - no + // Multiple + // Queries Enumeration qs = query.elements(); while (qs.hasMoreElements()) { @@ -98,20 +115,22 @@ public class ASequenceFetcher { qsb.append((String) qs.nextElement()); if (qs.hasMoreElements() && doMultiple) // and not reached limit for - // multiple queries at one - // time for this source + // multiple queries at one + // time for this source { qsb.append(fetcher.getAccessionSeparator()); } } while (doMultiple && qs.hasMoreElements()); - - AlignmentI seqset=null; - try { + + AlignmentI seqset = null; + try + { // create a fetcher and go to it seqset = fetcher.getSequenceRecords(qsb.toString()); } catch (Exception ex) { - System.err.println("Failed to retrieve the following from "+db); + System.err.println("Failed to retrieve the following from " + + db); System.err.println(qsb); ex.printStackTrace(System.err); } @@ -176,7 +195,7 @@ public class ASequenceFetcher { ret = new SequenceI[rseqs.size()]; Enumeration sqs = rseqs.elements(); - int si=0; + int si = 0; while (sqs.hasMoreElements()) { SequenceI s = (SequenceI) sqs.nextElement(); @@ -201,4 +220,115 @@ public class ASequenceFetcher return dbs; } -} \ No newline at end of file + /** + * constructs and instance of the proxy and registers it as a valid + * dbrefsource + * + * @param dbSourceProxy + * reference for class implementing + * jalview.ws.seqfetcher.DbSourceProxy + * @throws java.lang.IllegalArgumentException + * if class does not implement jalview.ws.seqfetcher.DbSourceProxy + */ + protected void addDBRefSourceImpl(Class dbSourceProxy) + throws java.lang.IllegalArgumentException + { + DbSourceProxy proxy = null; + try + { + Object proxyObj = dbSourceProxy.getConstructor(null) + .newInstance(null); + if (!DbSourceProxy.class.isInstance(proxyObj)) + { + throw new IllegalArgumentException( + dbSourceProxy.toString() + + " does not implement the jalview.ws.seqfetcher.DbSourceProxy"); + } + proxy = (DbSourceProxy) proxyObj; + } catch (IllegalArgumentException e) + { + throw e; + } catch (Exception e) + { + // Serious problems if this happens. + throw new Error("DBRefSource Implementation Exception", e); + } + addDbRefSourceImpl(proxy); + } + + /** + * add the properly initialised DbSourceProxy object 'proxy' to the list of + * sequence fetchers + * + * @param proxy + */ + protected void addDbRefSourceImpl(DbSourceProxy proxy) + { + if (proxy != null) + { + if (FETCHABLEDBS == null) + { + FETCHABLEDBS = new Hashtable(); + } + FETCHABLEDBS.put(proxy.getDbSource(), proxy); + } + } + + /** + * test if the database handler for dbName contains the given dbProperty + * + * @param dbName + * @param dbProperty + * @return true if proxy has the given property + */ + public boolean hasDbSourceProperty(String dbName, String dbProperty) + { + // TODO: decide if invalidDbName exception is thrown here. + DbSourceProxy proxy = getSourceProxy(dbName); + if (proxy != null) + { + if (proxy.getDbSourceProperties() != null) + { + return proxy.getDbSourceProperties().containsKey(dbProperty); + } + } + return false; + } + + /** + * select sources which are implemented by instances of the given class + * + * @param class that implements DbSourceProxy + * @return null or vector of source names for fetchers + */ + public String[] getDbInstances(Class class1) + { + if (!jalview.ws.seqfetcher.DbSourceProxy.class.isAssignableFrom(class1)) + { + throw new Error( + "Implmentation Error - getDbInstances must be given a class that implements jalview.ws.seqfetcher.DbSourceProxy (was given '" + + class1 + "')"); + } + if (FETCHABLEDBS == null) + { + return null; + } + String[] sources = null; + Vector src = new Vector(); + Enumeration dbs = FETCHABLEDBS.keys(); + while (dbs.hasMoreElements()) + { + String dbn = (String) dbs.nextElement(); + DbSourceProxy dbp = (DbSourceProxy) FETCHABLEDBS.get(dbn); + if (class1.isAssignableFrom(dbp.getClass())) + { + src.addElement(dbn); + } + } + if (src.size() > 0) + { + src.copyInto(sources = new String[src.size()]); + } + return sources; + } +}