refactor abstract sequence fetching and DBSource machinery to their own package
[jalview.git] / src / jalview / ws / seqfetcher / DbSourceProxyImpl.java
1 package jalview.ws.seqfetcher;\r
2 \r
3 import jalview.datamodel.Alignment;\r
4 import jalview.datamodel.DBRefSource;\r
5 import jalview.io.FormatAdapter;\r
6 import jalview.io.IdentifyFile;\r
7 \r
8 import java.util.Hashtable;\r
9 \r
10 /**\r
11  * common methods for implementations of the DbSourceProxy interface.\r
12  * \r
13  * @author JimP\r
14  *\r
15  */\r
16 public abstract class DbSourceProxyImpl implements DbSourceProxy\r
17 {\r
18   public DbSourceProxyImpl()\r
19   {\r
20     // default constructor - do nothing probably.\r
21   }\r
22   private Hashtable props=null;\r
23   /* (non-Javadoc)\r
24    * @see jalview.ws.DbSourceProxy#getDbSourceProperties()\r
25    */\r
26   public Hashtable getDbSourceProperties()\r
27   {\r
28     return props;\r
29   }\r
30   protected void addDbSourceProperty(Object propname)\r
31   {\r
32     addDbSourceProperty(propname, propname);\r
33   }\r
34 \r
35   protected void addDbSourceProperty(Object propname, Object propvalue)\r
36   {\r
37     if (props==null)\r
38     {\r
39       props = new Hashtable();\r
40     }\r
41     props.put(propname, propvalue);\r
42   }\r
43   boolean queryInProgress=false;\r
44   protected StringBuffer results = null;\r
45   /*\r
46    * (non-Javadoc)\r
47    * \r
48    * @see jalview.ws.DbSourceProxy#getRawRecords()\r
49    */\r
50   public StringBuffer getRawRecords()\r
51   {\r
52     return results;\r
53   }\r
54 \r
55   /* (non-Javadoc)\r
56    * @see jalview.ws.DbSourceProxy#queryInProgress()\r
57    */\r
58   public boolean queryInProgress()\r
59   {\r
60     return queryInProgress;\r
61   }\r
62   /**\r
63    * call to set the queryInProgress flag\r
64    *\r
65    */\r
66   protected void startQuery()\r
67   {\r
68     queryInProgress=true;\r
69   }\r
70   /**\r
71    * call to clear the queryInProgress flag\r
72    *\r
73    */\r
74   protected void stopQuery()\r
75   {\r
76     queryInProgress=false;\r
77   }\r
78 \r
79   /**\r
80    * create an alignment from raw text file...\r
81    * @param result\r
82    * @return null or a valid alignment\r
83    * @throws Exception\r
84    */\r
85   protected Alignment parseResult(String result) throws Exception {\r
86     Alignment sequences = null;\r
87     String format = new IdentifyFile().Identify(result, "Paste");\r
88     if (FormatAdapter.isValidFormat(format))\r
89     {\r
90       sequences = new FormatAdapter().readFile(result.toString(), "Paste",\r
91             format);\r
92     }\r
93     return sequences;\r
94   }\r
95   \r
96 }\r