X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fseqfetcher%2FASequenceFetcher.java;h=d3385f357c50e30184a351ba3c76920bdb9d82df;hb=a45774ee31d9f35d4eff46d54d7deab719afb092;hp=c4f7e9a7021ff38593e2cd5690fb6125bb28297a;hpb=ff966589beea8e5a0571ce881ffe0d2b4e6da1c2;p=jalview.git diff --git a/src/jalview/ws/seqfetcher/ASequenceFetcher.java b/src/jalview/ws/seqfetcher/ASequenceFetcher.java index c4f7e9a..d3385f3 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, 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(); @@ -206,20 +225,19 @@ public class ASequenceFetcher * dbrefsource * * @param dbSourceProxy - * reference for class implementing - * jalview.ws.seqfetcher.DbSourceProxy + * reference for class implementing + * jalview.ws.seqfetcher.DbSourceProxy * @throws java.lang.IllegalArgumentException - * if class does not implement - * jalview.ws.seqfetcher.DbSourceProxy + * if class does not implement jalview.ws.seqfetcher.DbSourceProxy */ protected void addDBRefSourceImpl(Class dbSourceProxy) throws java.lang.IllegalArgumentException { - DbSourceProxy proxy = null; + DbSourceProxy proxy = null; try { - Object proxyObj = dbSourceProxy.getConstructor( - null).newInstance(null); + Object proxyObj = dbSourceProxy.getConstructor(null) + .newInstance(null); if (!DbSourceProxy.class.isInstance(proxyObj)) { throw new IllegalArgumentException( @@ -227,20 +245,21 @@ public class ASequenceFetcher + " does not implement the jalview.ws.seqfetcher.DbSourceProxy"); } proxy = (DbSourceProxy) proxyObj; - } - catch (IllegalArgumentException e) + } catch (IllegalArgumentException e) { throw e; - } - catch (Exception 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 + * add the properly initialised DbSourceProxy object 'proxy' to the list of + * sequence fetchers + * * @param proxy */ protected void addDbRefSourceImpl(DbSourceProxy proxy) @@ -255,4 +274,61 @@ public class ASequenceFetcher } } -} \ No newline at end of file + /** + * 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; + } +}