X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FEBIFetchClient.java;h=5b21bfe092515f97283c01493969dcf18073d963;hb=588042b69abf8e60bcc950b24c283933c7dd422f;hp=3c6e5f9050109f86badd33815603eada6e06b6e4;hpb=5cd8e373c75fb348ecda4d94d8a46468fb92756d;p=jalview.git diff --git a/src/jalview/io/EBIFetchClient.java b/src/jalview/io/EBIFetchClient.java index 3c6e5f9..5b21bfe 100755 --- a/src/jalview/io/EBIFetchClient.java +++ b/src/jalview/io/EBIFetchClient.java @@ -16,166 +16,160 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ - package jalview.io; -import org.apache.axis.client.*; - -import java.io.*; - -import javax.activation.DataHandler; import org.apache.axis.AxisFault; +import org.apache.axis.client.*; 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; +import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory; +import java.io.*; -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;} - } +import javax.activation.DataHandler; - public String [] getSupportedFormats() - { - try{ - call.setOperationName(new QName("urn:Dbfetch", "getSupportedFormats")); - call.setReturnType(XMLType.SOAP_ARRAY); - return (String[]) call.invoke(new Object[] {}); +import javax.xml.namespace.QName; +import javax.xml.rpc.ParameterMode; - }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[] {}); +public class EBIFetchClient { + Call call; + String format = "default"; + String style = "raw"; - }catch(Exception ex){return null;} + 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 [] 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[] 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 fetchDataFile(String arg, String f, String s) - { - - if (f != null) - format = f; + public String[] getSupportedFormats() { + try { + call.setOperationName(new QName("urn:Dbfetch", "getSupportedFormats")); + call.setReturnType(XMLType.SOAP_ARRAY); - 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); + return (String[]) call.invoke(new Object[] { }); + } catch (Exception ex) { + return null; + } + } - call.setReturnType(qnameAttachment); + public String[] getSupportedStyles() { + try { + call.setOperationName(new QName("urn:Dbfetch", "getSupportedStyles")); + call.setReturnType(XMLType.SOAP_ARRAY); - try{ - Object ret = call.invoke(new Object[] - {arg, format, style}); + return (String[]) call.invoke(new Object[] { }); + } catch (Exception ex) { + return null; + } + } - if (null == ret) - { - System.err.println("Received null "); - throw new AxisFault("", "Received null", null, 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; } - if (ret instanceof String) - { - System.err.println("Received problem response from server: " + ret); - throw new AxisFault("", (String) ret, null, null); + } + + public String fetchDataFile(String arg, String f, String s) { + if (f != null) { + format = f; } - if (! (ret instanceof DataHandler)) - { - //The wrong type of object that what was expected. - System.err.println("Received problem response from server:" + - ret.getClass().getName()); - throw new AxisFault("", "Received problem response from server:" + - ret.getClass().getName(), null, null); + if (s != null) { + style = s; } - //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. + 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); - if (receivedfileName == null) - { - System.err.println("Could not get the file name."); - throw new AxisFault("", "Could not get the file name.", null, null); + 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.err.println("Received null "); + throw new AxisFault("", "Received null", null, null); + } + + if (ret instanceof String) { + System.err.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.err.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.err.println(receivedfileName); + } + } catch (Exception ex) { + ex.printStackTrace(); } - if (arg.equalsIgnoreCase("medline")) - { - return receivedfileName; - } - else if (arg.equalsIgnoreCase("interpro")) - { - return receivedfileName; - } - else - System.err.println(receivedfileName); - }catch(Exception ex) - { - ex.printStackTrace(); - } - - return "ERROR"; - } - + return "ERROR"; + } }