X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fseqfetcher%2FASequenceFetcher.java;h=d4bcfe8277af119a8f7715cec9274fba1041f932;hb=797df64fa2a0a30773d0f48f5494d4155e5a8be3;hp=9c2bfd42bcbfe96a34e6764e0ce252a7b051334b;hpb=300c01c1363c3d0d0f92df3750a07314479ed7ca;p=jalview.git diff --git a/src/jalview/ws/seqfetcher/ASequenceFetcher.java b/src/jalview/ws/seqfetcher/ASequenceFetcher.java index 9c2bfd4..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(); @@ -206,44 +225,110 @@ 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; try { - Object proxyObj = dbSourceProxy.getConstructor( - null).newInstance(null); + 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"); } - DbSourceProxy proxy = (DbSourceProxy) proxyObj; - if (proxy != null) - { - if (FETCHABLEDBS == null) - { - FETCHABLEDBS = new Hashtable(); - } - FETCHABLEDBS.put(proxy.getDbSource(), proxy); - } - } - catch (IllegalArgumentException e) + proxy = (DbSourceProxy) proxyObj; + } 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); } -} \ No newline at end of file + /** + * 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; + } +}