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