2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\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
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
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
23 import org.apache.axis.AxisFault;
\r
24 import org.apache.axis.client.*;
\r
25 import org.apache.axis.encoding.XMLType;
\r
26 import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory;
\r
27 import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;
\r
29 import javax.activation.DataHandler;
\r
31 import javax.xml.namespace.QName;
\r
32 import javax.xml.rpc.ParameterMode;
\r
39 * @version $Revision$
\r
41 public class EBIFetchClient
\r
44 String format = "default";
\r
45 String style = "raw";
\r
48 * Creates a new EBIFetchClient object.
\r
50 public EBIFetchClient()
\r
54 call = (Call) new Service().createCall();
\r
55 call.setTargetEndpointAddress(new java.net.URL(
\r
56 "http://www.ebi.ac.uk/ws/services/Dbfetch"));
\r
58 catch (Exception ex)
\r
66 * @return DOCUMENT ME!
\r
68 public String[] getSupportedDBs()
\r
72 call.setOperationName(new QName("urn:Dbfetch", "getSupportedDBs"));
\r
73 call.setReturnType(XMLType.SOAP_ARRAY);
\r
75 return (String[]) call.invoke(new Object[] { });
\r
77 catch (Exception ex)
\r
86 * @return DOCUMENT ME!
\r
88 public String[] getSupportedFormats()
\r
92 call.setOperationName(new QName("urn:Dbfetch", "getSupportedFormats"));
\r
93 call.setReturnType(XMLType.SOAP_ARRAY);
\r
95 return (String[]) call.invoke(new Object[] { });
\r
97 catch (Exception ex)
\r
106 * @return DOCUMENT ME!
\r
108 public String[] getSupportedStyles()
\r
112 call.setOperationName(new QName("urn:Dbfetch", "getSupportedStyles"));
\r
113 call.setReturnType(XMLType.SOAP_ARRAY);
\r
115 return (String[]) call.invoke(new Object[] { });
\r
117 catch (Exception ex)
\r
123 public static void main (String [] args)
\r
125 EBIFetchClient ebi = new EBIFetchClient();
\r
126 String[] result = ebi.fetchData("uniprot:25K89D_SARPE;G6PblobD_HUMAN",
\r
130 java.io.PrintWriter out = new java.io.PrintWriter(
\r
131 new java.io.FileWriter("out.xml"));
\r
134 for(int i=0; i<result.length; i++)
\r
136 out.println(result[i]);
\r
139 }catch(Exception ex){ex.printStackTrace();}
\r
144 public File fetchDataAsFile(String ids, String f, String s)
\r
146 String [] data = fetchData(ids, f, s);
\r
147 File outFile = null;
\r
149 outFile = File.createTempFile("jalview", ".xml");
\r
150 outFile.deleteOnExit();
\r
151 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
\r
153 while( index < data.length )
\r
155 out.println(data[index]);
\r
159 }catch(Exception ex){}
\r
166 * @param ids DOCUMENT ME!
\r
167 * @param f DOCUMENT ME!
\r
168 * @param s DOCUMENT ME!
\r
170 * @return DOCUMENT ME!
\r
172 public String[] fetchData(String ids, String f, String s)
\r
174 // ids should be of the form uniprot:25KD_SARPE;ADHR_DROPS;
\r
175 // max 50 ids can be added at one time
\r
178 call.setOperationName(new QName("urn:Dbfetch", "fetchData"));
\r
179 call.addParameter("query", XMLType.XSD_STRING, ParameterMode.IN);
\r
180 call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN);
\r
181 call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN);
\r
182 call.setReturnType(XMLType.SOAP_ARRAY);
\r
194 return (String[]) call.invoke(new Object[] { ids, format, style });
\r
196 catch (Exception ex)
\r
205 * @param arg DOCUMENT ME!
\r
206 * @param f DOCUMENT ME!
\r
207 * @param s DOCUMENT ME!
\r
209 * @return DOCUMENT ME!
\r
211 public String fetchDataFile(String arg, String f, String s)
\r
223 call.setOperationName(new QName("urn:Dbfetch", "fetchDataFile"));
\r
224 call.addParameter("query", XMLType.XSD_STRING, ParameterMode.IN);
\r
225 call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN);
\r
226 call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN);
\r
228 QName qnameAttachment = new QName("urn:Dbfetch", "DataHandler");
\r
229 call.registerTypeMapping(javax.activation.DataSource.class,
\r
230 qnameAttachment, JAFDataHandlerSerializerFactory.class,
\r
231 JAFDataHandlerDeserializerFactory.class);
\r
233 call.setReturnType(qnameAttachment);
\r
237 Object ret = call.invoke(new Object[] { arg, format, style });
\r
241 System.err.println("Received null ");
\r
242 throw new AxisFault("", "Received null", null, null);
\r
245 if (ret instanceof String)
\r
247 System.err.println("Received problem response from server: " +
\r
249 throw new AxisFault("", (String) ret, null, null);
\r
252 if (!(ret instanceof DataHandler))
\r
254 //The wrong type of object that what was expected.
\r
255 System.err.println("Received problem response from server:" +
\r
256 ret.getClass().getName());
\r
257 throw new AxisFault("",
\r
258 "Received problem response from server:" +
\r
259 ret.getClass().getName(), null, null);
\r
262 //Still here, so far so good.
\r
263 DataHandler rdh = (DataHandler) ret;
\r
265 //From here we'll just treat the data resource as file.
\r
266 String receivedfileName = rdh.getName(); //Get the filename.
\r
268 if (receivedfileName == null)
\r
270 System.err.println("Could not get the file name.");
\r
271 throw new AxisFault("", "Could not get the file name.", null,
\r
275 if (arg.equalsIgnoreCase("medline"))
\r
277 return receivedfileName;
\r
279 else if (arg.equalsIgnoreCase("interpro"))
\r
281 return receivedfileName;
\r
285 System.err.println(receivedfileName);
\r
288 catch (Exception ex)
\r
290 ex.printStackTrace();
\r