update author list in license for (JAL-826)
[jalview.git] / src / jalview / ws / seqfetcher / DbSourceProxyImpl.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)\r
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle\r
4  * \r
5  * This file is part of Jalview.\r
6  * \r
7  * Jalview is free software: you can redistribute it and/or\r
8  * modify it under the terms of the GNU General Public License \r
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
10  * \r
11  * Jalview is distributed in the hope that it will be useful, but \r
12  * WITHOUT ANY WARRANTY; without even the implied warranty \r
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
14  * PURPOSE.  See the GNU General Public License for more details.\r
15  * \r
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.\r
17  */\r
18 package jalview.ws.seqfetcher;\r
19 \r
20 import jalview.datamodel.Alignment;\r
21 import jalview.datamodel.DBRefSource;\r
22 import jalview.io.FormatAdapter;\r
23 import jalview.io.IdentifyFile;\r
24 \r
25 import java.util.Hashtable;\r
26 \r
27 /**\r
28  * common methods for implementations of the DbSourceProxy interface.\r
29  * \r
30  * @author JimP\r
31  * \r
32  */\r
33 public abstract class DbSourceProxyImpl implements DbSourceProxy\r
34 {\r
35   public DbSourceProxyImpl()\r
36   {\r
37     // default constructor - do nothing probably.\r
38   }\r
39 \r
40   private Hashtable props = null;\r
41 \r
42   /*\r
43    * (non-Javadoc)\r
44    * \r
45    * @see jalview.ws.DbSourceProxy#getDbSourceProperties()\r
46    */\r
47   public Hashtable getDbSourceProperties()\r
48   {\r
49     if (props == null)\r
50     {\r
51       props = new Hashtable();\r
52     }\r
53     return props;\r
54   }\r
55 \r
56   protected void addDbSourceProperty(Object propname)\r
57   {\r
58     addDbSourceProperty(propname, propname);\r
59   }\r
60 \r
61   protected void addDbSourceProperty(Object propname, Object propvalue)\r
62   {\r
63     if (props == null)\r
64     {\r
65       props = new Hashtable();\r
66     }\r
67     props.put(propname, propvalue);\r
68   }\r
69 \r
70   boolean queryInProgress = false;\r
71 \r
72   protected StringBuffer results = null;\r
73 \r
74   /*\r
75    * (non-Javadoc)\r
76    * \r
77    * @see jalview.ws.DbSourceProxy#getRawRecords()\r
78    */\r
79   public StringBuffer getRawRecords()\r
80   {\r
81     return results;\r
82   }\r
83 \r
84   /*\r
85    * (non-Javadoc)\r
86    * \r
87    * @see jalview.ws.DbSourceProxy#queryInProgress()\r
88    */\r
89   public boolean queryInProgress()\r
90   {\r
91     return queryInProgress;\r
92   }\r
93 \r
94   /**\r
95    * call to set the queryInProgress flag\r
96    * \r
97    */\r
98   protected void startQuery()\r
99   {\r
100     queryInProgress = true;\r
101   }\r
102 \r
103   /**\r
104    * call to clear the queryInProgress flag\r
105    * \r
106    */\r
107   protected void stopQuery()\r
108   {\r
109     queryInProgress = false;\r
110   }\r
111 \r
112   /**\r
113    * create an alignment from raw text file...\r
114    * \r
115    * @param result\r
116    * @return null or a valid alignment\r
117    * @throws Exception\r
118    */\r
119   protected Alignment parseResult(String result) throws Exception\r
120   {\r
121     Alignment sequences = null;\r
122     String format = new IdentifyFile().Identify(result, "Paste");\r
123     if (FormatAdapter.isValidFormat(format))\r
124     {\r
125       sequences = new FormatAdapter().readFile(result.toString(), "Paste",\r
126               format);\r
127     }\r
128     return sequences;\r
129   }\r
130 \r
131   @Override\r
132   public boolean isA(Object dbsourceproperty)\r
133   {\r
134     assert(dbsourceproperty!=null);\r
135     return (props==null) ? false : props.containsKey(dbsourceproperty);\r
136   }\r
137   \r
138 \r
139 }\r