From fb0b0f2434cf4af0cee7a146bc3d7ef37299a901 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Mon, 7 Feb 2005 17:09:57 +0000 Subject: [PATCH] New class --- src/jalview/io/EBIFetchClient.java | 160 ++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100755 src/jalview/io/EBIFetchClient.java diff --git a/src/jalview/io/EBIFetchClient.java b/src/jalview/io/EBIFetchClient.java new file mode 100755 index 0000000..be2f01e --- /dev/null +++ b/src/jalview/io/EBIFetchClient.java @@ -0,0 +1,160 @@ +package jalview.io; + +import org.apache.axis.client.*; + +import java.io.*; + +import javax.activation.DataHandler; +import org.apache.axis.AxisFault; +import org.apache.axis.encoding.XMLType; +import javax.xml.rpc.ParameterMode; +import javax.xml.namespace.QName; +import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory; +import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory; + + +public class EBIFetchClient +{ + Call call; + String format = "default"; + String style = "raw"; + + public EBIFetchClient() + { + try{ + call = (Call)new Service().createCall(); + call.setTargetEndpointAddress(new java.net.URL( + "http://www.ebi.ac.uk/ws/services/Dbfetch")); + }catch(Exception ex){} + } + + + public String [] getSupportedDBs() + { + try{ + + call.setOperationName(new QName("urn:Dbfetch", "getSupportedDBs")); + call.setReturnType(XMLType.SOAP_ARRAY); + return (String[]) call.invoke(new Object[]{}); + + }catch(Exception ex){return null;} + } + + public String [] getSupportedFormats() + { + try{ + call.setOperationName(new QName("urn:Dbfetch", "getSupportedFormats")); + call.setReturnType(XMLType.SOAP_ARRAY); + return (String[]) call.invoke(new Object[] {}); + + }catch(Exception ex){ return null; } + } + + public String [] getSupportedStyles() + { + try{ + call.setOperationName(new QName("urn:Dbfetch", "getSupportedStyles")); + call.setReturnType(XMLType.SOAP_ARRAY); + return (String[]) call.invoke(new Object[] {}); + + }catch(Exception ex){return null;} + } + + public String [] fetchData(String ids, String f, String s) + { + // ids should be of the form uniprot:25KD_SARPE;ADHR_DROPS; + // max 50 ids can be added at one time + try{ + call.setOperationName(new QName("urn:Dbfetch", "fetchData")); + call.addParameter("query", XMLType.XSD_STRING, ParameterMode.IN); + call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN); + call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN); + call.setReturnType(XMLType.SOAP_ARRAY); + + if (f != null) + format = f; + + if (s != null) + style = s; + + return (String[]) call.invoke(new Object[] {ids, format, style}); + + }catch(Exception ex){return null;} + + } + + public String fetchDataFile(String arg, String f, String s) + { + + if (f != null) + format = f; + + if (s != null) + style = s; + + + call.setOperationName(new QName("urn:Dbfetch", "fetchDataFile")); + call.addParameter("query", XMLType.XSD_STRING, ParameterMode.IN); + call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN); + call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN); + + QName qnameAttachment = new QName("urn:Dbfetch", "DataHandler"); + call.registerTypeMapping(javax.activation.DataSource.class, + qnameAttachment, + JAFDataHandlerSerializerFactory.class, + JAFDataHandlerDeserializerFactory.class); + + call.setReturnType(qnameAttachment); + + try{ + Object ret = call.invoke(new Object[] + {arg, format, style}); + + if (null == ret) + { + System.out.println("Received null "); + throw new AxisFault("", "Received null", null, null); + } + if (ret instanceof String) + { + System.out.println("Received problem response from server: " + ret); + throw new AxisFault("", (String) ret, null, null); + } + if (! (ret instanceof DataHandler)) + { + //The wrong type of object that what was expected. + System.out.println("Received problem response from server:" + + ret.getClass().getName()); + throw new AxisFault("", "Received problem response from server:" + + ret.getClass().getName(), null, null); + + } + //Still here, so far so good. + DataHandler rdh = (DataHandler) ret; + + //From here we'll just treat the data resource as file. + String receivedfileName = rdh.getName(); //Get the filename. + + if (receivedfileName == null) + { + System.err.println("Could not get the file name."); + throw new AxisFault("", "Could not get the file name.", null, null); + } + if (arg.equalsIgnoreCase("medline")) + { + return receivedfileName; + } + else if (arg.equalsIgnoreCase("interpro")) + { + return receivedfileName; + } + else + System.out.println(receivedfileName); + }catch(Exception ex) + {} + + return "ERROR"; + } + + +} -- 1.7.10.2