001/* 002 * Copyright (c) 1998-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2015-08-24 22:47:39 +0000 (Mon, 24 Aug 2015) $' 007 * '$Revision: 33633 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.sdm.spa; 031 032// FOR SOAPLAB API 033 034import java.net.MalformedURLException; 035import java.net.URL; 036import java.util.Arrays; 037import java.util.Comparator; 038import java.util.Map; 039import java.util.Vector; 040 041import org.embl.ebi.SoaplabShare.AnalysisWS; 042 043import embl.ebi.soap.axis.AxisCall; 044import embl.ebi.utils.GException; 045import ptolemy.gui.GraphicalMessageHandler; 046 047/////////////////////////////////////////////////////////////// 048////SoaplabServiceClient 049/** 050 * The following client is used by other web service soaplab related actors 051 * while executing the web service as well as transmitting the above client 052 * through various actors in the workflow. The gist of the following client lies 053 * in the doCall method which establishes contact with the WSDL and executes the 054 * desired enetered operation. 055 * 056 * @author Nandita Mangal 057 * @version $Id: SoaplabServiceClient.java, v 1.0 2005/19/07 058 * @category.name web 059 * @category.name external execution 060 */ 061 062public class SoaplabServiceClient { 063 064 /** 065 * Construct a SoaplabServiceClient with given wsdl. 066 * 067 * @param wsdl_URL 068 * The wsdl of the derived web service to be executed 069 * @exception MalformedURLException 070 * If the url is not valid 071 * @exception GException 072 * Error with the given WSDL analysis interface 073 */ 074 075 public SoaplabServiceClient(String wsdl_URL) throws MalformedURLException, 076 GException { 077 call = new AxisCall(new URL(wsdl_URL)); 078 InputMethods = new Vector(); // input set_<name> operations of 079 // webservice 080 OutputMethods = new Vector(); // output get_<name> operations of 081 // webservice 082 083 } 084 085 // //////////////////////////////////////////////////////////////////// 086 // // Public Methods //// 087 088 /** 089 * To create a new job in the client. Call the standard operation 090 * "createEmtpyJob", via the doCall method 091 */ 092 public void setJobId() { 093 jobId = (String) (doCall("createEmptyJob", new Object[] {})); 094 } 095 096 /** 097 * To get the client's job Id which was created in setJobID via 098 * "createEmptyJob". 099 */ 100 public String getJobId() { 101 return jobId; 102 } 103 104 /** 105 * To get a list of all the InputMethods (set_<name>) methods in the given 106 * WSDL of the client.Inputmethods were set via caliing the 107 * generateInputMethods(). 108 */ 109 public Vector getInputMethods() { 110 return InputMethods; 111 112 } 113 114 /** 115 * To get a list of all the OutputMethods (get_<name>) methods in the given 116 * WSDL of the client.Outputmethods were set via caliing the 117 * generateOutputMethods(). 118 */ 119 public Vector getOutputMethods() { 120 return OutputMethods; 121 } 122 123 /** 124 * To generate all the output get_<name> operations belonging to the derived 125 * web service.INPUT_NAME gives the actual operation name of get_<name> 126 */ 127 public void generateOutputMethods() { 128 try { 129 130 Map[] attrs = (Map[]) doCall("getResultSpec", new Object[] {}); 131 if (attrs != null) { 132 Arrays.sort(attrs, new Comparator() { 133 public int compare(Object a, Object b) { 134 String name1 = (String) ((Map) a) 135 .get(AnalysisWS.INPUT_NAME); 136 String name2 = (String) ((Map) b) 137 .get(AnalysisWS.INPUT_NAME); 138 return name1.compareTo(name2); 139 } 140 }); 141 142 for (int i = 0; i < attrs.length; i++) { 143 OutputMethods.add(attrs[i].get(AnalysisWS.INPUT_NAME)); 144 145 } 146 147 } 148 } catch (Exception e) { 149 } 150 151 } 152 153 /** 154 * To generate all the input set_<name> operations belonging to the derived 155 * web service.INPUT_NAME gives the actual operation name of set_<name> 156 */ 157 158 public void generateInputMethods() { 159 160 try { 161 162 Map[] attrs = (Map[]) doCall("getInputSpec", new Object[] {}); 163 if (attrs != null) { 164 Arrays.sort(attrs, new Comparator() { 165 public int compare(Object a, Object b) { 166 String name1 = (String) ((Map) a) 167 .get(AnalysisWS.INPUT_NAME); 168 String name2 = (String) ((Map) b) 169 .get(AnalysisWS.INPUT_NAME); 170 return name1.compareTo(name2); 171 } 172 }); 173 174 for (int i = 0; i < attrs.length; i++) { 175 InputMethods.add(attrs[i].get(AnalysisWS.INPUT_NAME)); 176 177 } 178 179 } 180 181 } catch (Exception e) { 182 } 183 184 } 185 186 // //////////////////////////////////////////////////////////////////// 187 // // protected methods //// 188 189 /** 190 * Performs the actual web service execution via calling the AxisCall's 191 * doCall method which executes the given operation with input values. 192 * 193 * @param method 194 * The name of soaplab operation to be executed 195 * @param parameters 196 * InputValues to be given to the above soaplab operation while 197 * executing.One of the required parameters is the client's job 198 * id. 199 */ 200 protected Object doCall(String method, Object[] parameters) { 201 202 try { 203 return call.doCall(method, parameters); 204 } catch (Exception ex) { 205 _confErrorStr += "\n" 206 + ex.getMessage() 207 + "There was an error while executing the web service. Kindly make sure the WSDL is valid. "; 208 209 } 210 if (!(_confErrorStr.equals(""))) { 211 GraphicalMessageHandler.message(_confErrorStr); 212 } 213 return null; 214 } 215 216 // ///////////////////////////////////////////////////////////////////////////////// 217 // // private variables //// 218 219 private AxisCall call; 220 private String jobId; 221 private Vector InputMethods; 222 private Vector OutputMethods; 223 private String _confErrorStr = ""; 224 225} // end of SoaplabServiceClient