+/*\r
+* Jalview - A Sequence Alignment Editor and Viewer\r
+* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+*\r
+* This program is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU General Public License\r
+* as published by the Free Software Foundation; either version 2\r
+* of the License, or (at your option) any later version.\r
+*\r
+* This program is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with this program; if not, write to the Free Software\r
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+*/\r
package jalview.io;\r
\r
-import org.apache.axis.client.*;\r
-\r
import java.io.*;\r
\r
-import javax.activation.DataHandler;\r
import org.apache.axis.AxisFault;\r
+import org.apache.axis.client.*;\r
import org.apache.axis.encoding.XMLType;\r
-import javax.xml.rpc.ParameterMode;\r
-import javax.xml.namespace.QName;\r
-import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;\r
import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory;\r
+import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;\r
\r
+import javax.activation.DataHandler;\r
\r
-public class EBIFetchClient\r
-{\r
- Call call;\r
- String format = "default";\r
- String style = "raw";\r
-\r
- public EBIFetchClient()\r
- {\r
- try{\r
- call = (Call)new Service().createCall();\r
- call.setTargetEndpointAddress(new java.net.URL(\r
- "http://www.ebi.ac.uk/ws/services/Dbfetch"));\r
- }catch(Exception ex){}\r
- }\r
-\r
-\r
- public String [] getSupportedDBs()\r
- {\r
- try{\r
-\r
- call.setOperationName(new QName("urn:Dbfetch", "getSupportedDBs"));\r
- call.setReturnType(XMLType.SOAP_ARRAY);\r
- return (String[]) call.invoke(new Object[]{});\r
-\r
- }catch(Exception ex){return null;}\r
- }\r
-\r
- public String [] getSupportedFormats()\r
- {\r
- try{\r
- call.setOperationName(new QName("urn:Dbfetch", "getSupportedFormats"));\r
- call.setReturnType(XMLType.SOAP_ARRAY);\r
- return (String[]) call.invoke(new Object[] {});\r
-\r
- }catch(Exception ex){ return null; }\r
- }\r
+import javax.xml.namespace.QName;\r
+import javax.xml.rpc.ParameterMode;\r
\r
- public String [] getSupportedStyles()\r
- {\r
- try{\r
- call.setOperationName(new QName("urn:Dbfetch", "getSupportedStyles"));\r
- call.setReturnType(XMLType.SOAP_ARRAY);\r
- return (String[]) call.invoke(new Object[] {});\r
\r
- }catch(Exception ex){return null;}\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
+public class EBIFetchClient\r
+{\r
+ Call call;\r
+ String format = "default";\r
+ String style = "raw";\r
+\r
+ /**\r
+ * Creates a new EBIFetchClient object.\r
+ */\r
+ public EBIFetchClient()\r
+ {\r
+ try\r
+ {\r
+ call = (Call) new Service().createCall();\r
+ call.setTargetEndpointAddress(new java.net.URL(\r
+ "http://www.ebi.ac.uk/ws/services/Dbfetch"));\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
}\r
\r
- public String [] fetchData(String ids, String f, String s)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public String[] getSupportedDBs()\r
{\r
- // ids should be of the form uniprot:25KD_SARPE;ADHR_DROPS;\r
- // max 50 ids can be added at one time\r
- try{\r
- call.setOperationName(new QName("urn:Dbfetch", "fetchData"));\r
- call.addParameter("query", XMLType.XSD_STRING, ParameterMode.IN);\r
- call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN);\r
- call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN);\r
- call.setReturnType(XMLType.SOAP_ARRAY);\r
+ try\r
+ {\r
+ call.setOperationName(new QName("urn:Dbfetch", "getSupportedDBs"));\r
+ call.setReturnType(XMLType.SOAP_ARRAY);\r
\r
- if (f != null)\r
- format = f;\r
+ return (String[]) call.invoke(new Object[] { });\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ return null;\r
+ }\r
+ }\r
\r
- if (s != null)\r
- style = s;\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public String[] getSupportedFormats()\r
+ {\r
+ try\r
+ {\r
+ call.setOperationName(new QName("urn:Dbfetch", "getSupportedFormats"));\r
+ call.setReturnType(XMLType.SOAP_ARRAY);\r
\r
- return (String[]) call.invoke(new Object[] {ids, format, style});\r
+ return (String[]) call.invoke(new Object[] { });\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ return null;\r
+ }\r
+ }\r
\r
- }catch(Exception ex){return null;}\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public String[] getSupportedStyles()\r
+ {\r
+ try\r
+ {\r
+ call.setOperationName(new QName("urn:Dbfetch", "getSupportedStyles"));\r
+ call.setReturnType(XMLType.SOAP_ARRAY);\r
\r
+ return (String[]) call.invoke(new Object[] { });\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ return null;\r
+ }\r
}\r
\r
- public String fetchDataFile(String arg, String f, String s)\r
+ public static void main (String [] args)\r
{\r
+ EBIFetchClient ebi = new EBIFetchClient();\r
+ String[] result = ebi.fetchData("uniprot:25K89D_SARPE;G6PblobD_HUMAN",\r
+ "xml", null);\r
\r
- if (f != null)\r
- format = f;\r
+ try{\r
+ java.io.PrintWriter out = new java.io.PrintWriter(\r
+ new java.io.FileWriter("out.xml"));\r
\r
- if (s != null)\r
- style = s;\r
\r
+ for(int i=0; i<result.length; i++)\r
+ {\r
+ out.println(result[i]);\r
+ }\r
+ out.close();\r
+ }catch(Exception ex){ex.printStackTrace();}\r
\r
- call.setOperationName(new QName("urn:Dbfetch", "fetchDataFile"));\r
- call.addParameter("query", XMLType.XSD_STRING, ParameterMode.IN);\r
- call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN);\r
- call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN);\r
-\r
- QName qnameAttachment = new QName("urn:Dbfetch", "DataHandler");\r
- call.registerTypeMapping(javax.activation.DataSource.class,\r
- qnameAttachment,\r
- JAFDataHandlerSerializerFactory.class,\r
- JAFDataHandlerDeserializerFactory.class);\r
+ }\r
\r
- call.setReturnType(qnameAttachment);\r
\r
+ public File fetchDataAsFile(String ids, String f, String s)\r
+ {\r
+ String [] data = fetchData(ids, f, s);\r
+ File outFile = null;\r
try{\r
- Object ret = call.invoke(new Object[]\r
- {arg, format, style});\r
-\r
- if (null == ret)\r
+ outFile = File.createTempFile("jalview", ".xml");\r
+ outFile.deleteOnExit();\r
+ PrintWriter out = new PrintWriter(new FileOutputStream(outFile));\r
+ int index=0;\r
+ while( index < data.length )\r
{\r
- System.out.println("Received null ");\r
- throw new AxisFault("", "Received null", null, null);\r
+ out.println(data[index]);\r
+ index++;\r
}\r
- if (ret instanceof String)\r
+ out.close();\r
+ }catch(Exception ex){}\r
+ return outFile;\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param ids DOCUMENT ME!\r
+ * @param f DOCUMENT ME!\r
+ * @param s DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public String[] fetchData(String ids, String f, String s)\r
+ {\r
+ // ids should be of the form uniprot:25KD_SARPE;ADHR_DROPS;\r
+ // max 50 ids can be added at one time\r
+ try\r
{\r
- System.out.println("Received problem response from server: " + ret);\r
- throw new AxisFault("", (String) ret, null, null);\r
+ call.setOperationName(new QName("urn:Dbfetch", "fetchData"));\r
+ call.addParameter("query", XMLType.XSD_STRING, ParameterMode.IN);\r
+ call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN);\r
+ call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN);\r
+ call.setReturnType(XMLType.SOAP_ARRAY);\r
+\r
+ if (f != null)\r
+ {\r
+ format = f;\r
+ }\r
+\r
+ if (s != null)\r
+ {\r
+ style = s;\r
+ }\r
+\r
+ return (String[]) call.invoke(new Object[] { ids, format, style });\r
}\r
- if (! (ret instanceof DataHandler))\r
+ catch (Exception ex)\r
{\r
- //The wrong type of object that what was expected.\r
- System.out.println("Received problem response from server:" +\r
- ret.getClass().getName());\r
- throw new AxisFault("", "Received problem response from server:" +\r
- ret.getClass().getName(), null, null);\r
-\r
+ return null;\r
}\r
- //Still here, so far so good.\r
- DataHandler rdh = (DataHandler) ret;\r
+ }\r
\r
- //From here we'll just treat the data resource as file.\r
- String receivedfileName = rdh.getName(); //Get the filename.\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param arg DOCUMENT ME!\r
+ * @param f DOCUMENT ME!\r
+ * @param s DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public String fetchDataFile(String arg, String f, String s)\r
+ {\r
+ if (f != null)\r
+ {\r
+ format = f;\r
+ }\r
\r
- if (receivedfileName == null)\r
+ if (s != null)\r
{\r
- System.err.println("Could not get the file name.");\r
- throw new AxisFault("", "Could not get the file name.", null, null);\r
+ style = s;\r
}\r
- if (arg.equalsIgnoreCase("medline"))\r
+\r
+ call.setOperationName(new QName("urn:Dbfetch", "fetchDataFile"));\r
+ call.addParameter("query", XMLType.XSD_STRING, ParameterMode.IN);\r
+ call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN);\r
+ call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN);\r
+\r
+ QName qnameAttachment = new QName("urn:Dbfetch", "DataHandler");\r
+ call.registerTypeMapping(javax.activation.DataSource.class,\r
+ qnameAttachment, JAFDataHandlerSerializerFactory.class,\r
+ JAFDataHandlerDeserializerFactory.class);\r
+\r
+ call.setReturnType(qnameAttachment);\r
+\r
+ try\r
{\r
- return receivedfileName;\r
+ Object ret = call.invoke(new Object[] { arg, format, style });\r
+\r
+ if (null == ret)\r
+ {\r
+ System.err.println("Received null ");\r
+ throw new AxisFault("", "Received null", null, null);\r
+ }\r
+\r
+ if (ret instanceof String)\r
+ {\r
+ System.err.println("Received problem response from server: " +\r
+ ret);\r
+ throw new AxisFault("", (String) ret, null, null);\r
+ }\r
+\r
+ if (!(ret instanceof DataHandler))\r
+ {\r
+ //The wrong type of object that what was expected.\r
+ System.err.println("Received problem response from server:" +\r
+ ret.getClass().getName());\r
+ throw new AxisFault("",\r
+ "Received problem response from server:" +\r
+ ret.getClass().getName(), null, null);\r
+ }\r
+\r
+ //Still here, so far so good.\r
+ DataHandler rdh = (DataHandler) ret;\r
+\r
+ //From here we'll just treat the data resource as file.\r
+ String receivedfileName = rdh.getName(); //Get the filename.\r
+\r
+ if (receivedfileName == null)\r
+ {\r
+ System.err.println("Could not get the file name.");\r
+ throw new AxisFault("", "Could not get the file name.", null,\r
+ null);\r
+ }\r
+\r
+ if (arg.equalsIgnoreCase("medline"))\r
+ {\r
+ return receivedfileName;\r
+ }\r
+ else if (arg.equalsIgnoreCase("interpro"))\r
+ {\r
+ return receivedfileName;\r
+ }\r
+ else\r
+ {\r
+ System.err.println(receivedfileName);\r
+ }\r
}\r
- else if (arg.equalsIgnoreCase("interpro"))\r
+ catch (Exception ex)\r
{\r
- return receivedfileName;\r
+ ex.printStackTrace();\r
}\r
- else\r
- System.out.println(receivedfileName);\r
- }catch(Exception ex)\r
- {}\r
\r
- return "ERROR";\r
+ return "ERROR";\r
}\r
-\r
-\r
}\r