2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.ws.ebi;
23 import javax.xml.namespace.*;
24 import javax.xml.rpc.*;
26 import org.apache.axis.client.Call;
27 import org.apache.axis.client.Service;
28 import org.apache.axis.encoding.*;
36 public class EBIFetchClient
39 String format = "default";
43 * Creates a new EBIFetchClient object.
45 public EBIFetchClient()
49 call = (Call)new Service().createCall();
50 call.setTargetEndpointAddress(new java.net.URL(
51 "http://www.ebi.ac.uk/ws/services/Dbfetch"));
61 * @return DOCUMENT ME!
63 public String[] getSupportedDBs()
67 call.setOperationName(new QName("urn:Dbfetch", "getSupportedDBs"));
68 call.setReturnType(XMLType.SOAP_ARRAY);
70 return (String[]) call.invoke(new Object[]
82 * @return DOCUMENT ME!
84 public String[] getSupportedFormats()
88 call.setOperationName(new QName("urn:Dbfetch", "getSupportedFormats"));
89 call.setReturnType(XMLType.SOAP_ARRAY);
91 return (String[]) call.invoke(new Object[]
103 * @return DOCUMENT ME!
105 public String[] getSupportedStyles()
109 call.setOperationName(new QName("urn:Dbfetch", "getSupportedStyles"));
110 call.setReturnType(XMLType.SOAP_ARRAY);
112 return (String[]) call.invoke(new Object[]
122 public File fetchDataAsFile(String ids, String f, String s)
124 String[] data = fetchData(ids, f, s);
128 outFile = File.createTempFile("jalview", ".xml");
129 outFile.deleteOnExit();
130 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
132 while (index < data.length)
134 out.println(data[index]);
145 * Single DB multiple record retrieval
147 * @param ids db:query1;query2;query3
151 * @return Raw string array result of query set
153 public String[] fetchData(String ids, String f, String s)
156 // ids of the form uniprot:25KD_SARPE;ADHR_DROPS;
157 StringTokenizer queries = new StringTokenizer(ids, ";");
159 StringBuffer querystring = null;
160 while (queries.hasMoreTokens())
162 String query = queries.nextToken();
164 if ( (p = query.indexOf(':')) > -1)
166 db = query.substring(0, p);
167 query = query.substring(p + 1);
169 if (querystring == null)
171 querystring = new StringBuffer(query);
175 querystring.append("," + query);
180 System.err.println("Invalid Query string : '" + ids +
181 "'\nShould be of form 'dbname:q1;q2;q3;q4'");
183 return fetchBatch(querystring.toString(), db, f, s);
186 public String[] fetchBatch(String ids, String db, String f, String s)
188 // max 50 ids can be added at one time
191 //call.setOperationName(new QName("urn:Dbfetch", "fetchData"));
192 call.setOperationName(new QName("urn:Dbfetch", "fetchBatch"));
193 call.addParameter("ids", XMLType.XSD_STRING, ParameterMode.IN);
194 call.addParameter("db", XMLType.XSD_STRING, ParameterMode.IN);
195 call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN);
196 call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN);
197 call.setReturnType(XMLType.SOAP_ARRAY);
211 return (String[]) call.invoke(new Object[]
212 {ids.toLowerCase(), db.toLowerCase(),
215 catch (OutOfMemoryError er)
217 System.out.println("OUT OF MEMORY DOWNLOADING QUERY FROM " + db + ":\n" +
224 if (ex.getMessage().startsWith(
225 "uk.ac.ebi.jdbfetch.exceptions.DbfNoEntryFoundException"))
229 System.err.println("Unexpected exception when retrieving from " + db +
230 "\nQuery was : '" + ids + "'");
231 ex.printStackTrace(System.err);