JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / src / jalview / ws / seqfetcher / DbSourceProxyImpl.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.ws.seqfetcher;
22
23 import jalview.api.FeatureSettingsModelI;
24 import jalview.datamodel.AlignmentI;
25 import jalview.io.FormatAdapter;
26 import jalview.io.IdentifyFile;
27
28 /**
29  * common methods for implementations of the DbSourceProxy interface.
30  * 
31  * @author JimP
32  * 
33  */
34 public abstract class DbSourceProxyImpl implements DbSourceProxy
35 {
36
37   boolean queryInProgress = false;
38
39   protected StringBuffer results = null;
40
41   public DbSourceProxyImpl()
42   {
43   }
44
45   /*
46    * (non-Javadoc)
47    * 
48    * @see jalview.ws.DbSourceProxy#getRawRecords()
49    */
50   @Override
51   public StringBuffer getRawRecords()
52   {
53     return results;
54   }
55
56   /*
57    * (non-Javadoc)
58    * 
59    * @see jalview.ws.DbSourceProxy#queryInProgress()
60    */
61   @Override
62   public boolean queryInProgress()
63   {
64     return queryInProgress;
65   }
66
67   /**
68    * call to set the queryInProgress flag
69    * 
70    */
71   protected void startQuery()
72   {
73     queryInProgress = true;
74   }
75
76   /**
77    * call to clear the queryInProgress flag
78    * 
79    */
80   protected void stopQuery()
81   {
82     queryInProgress = false;
83   }
84
85   /**
86    * create an alignment from raw text file...
87    * 
88    * @param result
89    * @return null or a valid alignment
90    * @throws Exception
91    */
92   protected AlignmentI parseResult(String result) throws Exception
93   {
94     AlignmentI sequences = null;
95     String format = new IdentifyFile().identify(result, "Paste");
96     if (FormatAdapter.isValidFormat(format))
97     {
98       sequences = new FormatAdapter().readFile(result.toString(), "Paste",
99               format);
100     }
101     return sequences;
102   }
103
104   /**
105    * Returns the first accession id in the query (up to the first accession id
106    * separator), or the whole query if there is no separator or it is not found
107    */
108   @Override
109   public String getAccessionIdFromQuery(String query)
110   {
111     String sep = getAccessionSeparator();
112     if (sep == null)
113     {
114       return query;
115     }
116     int sepPos = query.indexOf(sep);
117     return sepPos == -1 ? query : query.substring(0, sepPos);
118   }
119
120   /**
121    * Default is only one accession id per query - override if more are allowed.
122    */
123   @Override
124   public int getMaximumQueryCount()
125   {
126     return 1;
127   }
128
129   /**
130    * Returns false - override to return true for DNA coding data sources
131    */
132   @Override
133   public boolean isDnaCoding()
134   {
135     return false;
136   }
137
138   /**
139    * Answers false - override as required in subclasses
140    */
141   @Override
142   public boolean isAlignmentSource()
143   {
144     return false;
145   }
146
147   @Override
148   public String getDescription()
149   {
150     return "";
151   }
152
153   @Override
154   public FeatureSettingsModelI getFeatureColourScheme()
155   {
156     return null;
157   }
158 }