1 22 package com.scalagent.kjoram.ksoap; 23 24 import com.scalagent.kjoram.excepts.MessageFormatException; 25 import com.scalagent.kjoram.jms.*; 26 import com.scalagent.ksoap.SoapObject; 27 28 import java.lang.*; 29 import java.util.Vector ; 30 import java.util.Hashtable ; 31 32 36 public class ConversionSoapHelper { 37 38 public static final String NAMESPACE = "urn:ProxyService"; 39 40 43 public static SoapObject getSoapObject(AbstractJmsRequest request, 44 String name, 45 int cnxId) 46 throws MessageFormatException { 47 SoapObject sO = null; 48 49 if (request instanceof GetReply) { 50 sO = getSoapObject((GetReply)request); 51 } else { 52 sO = new SoapObject(NAMESPACE, "send"); 53 sO.addProperty("name",name); 54 sO.addProperty("cnxId",new Integer (cnxId)); 55 Hashtable h = request.soapCode(); 56 if (h != null) 57 sO.addProperty("map",h); 58 } 59 return sO; 60 } 61 62 65 public static Object getObject(SoapObject sO) 66 throws MessageFormatException { 67 68 Hashtable h = null; 69 String nameSpace = sO.getNamespace(); 70 String name = sO.getName(); 71 72 if (nameSpace.equals("urn:ProxyService")) { 73 if (name.equals("getReplyResponse")) { 74 Object o = sO.getProperty("return"); 75 h = (Hashtable ) sO.getProperty("return"); 76 } else if (name.equals("setConnectionResponse")) { 77 return new Integer (getSetCnx(sO)); 78 } else if (name.equals("sendResponse")) { 79 return null; 80 } else { 81 throw new MessageFormatException("SoapObject " + name 82 + " can't be converted to a Hashtable."); 83 } 84 } else { 85 throw new MessageFormatException("SoapObject " + nameSpace 86 + " != urn:ProxyService."); 87 } 88 89 String className = (String ) h.get("className"); 90 if (className == null) 91 throw new MessageFormatException( "SoapObject " + name 92 + " no className found."); 93 94 if (className.equals("org.objectweb.joram.shared.client.CnxConnectReply")){ 95 return CnxConnectReply.soapDecode(h); 96 } else if (className.equals("org.objectweb.joram.shared.client.ServerReply")){ 97 return ServerReply.soapDecode(h); 98 } else if (className.equals("org.objectweb.joram.shared.client.MomExceptionReply")){ 99 return MomExceptionReply.soapDecode(h); 100 } else if (className.equals("org.objectweb.joram.shared.client.ProducerMessages")){ 101 return ProducerMessages.soapDecode(h); 102 } else if (className.equals("org.objectweb.joram.shared.client.QBrowseReply")){ 103 return QBrowseReply.soapDecode(h); 104 } else if (className.equals("org.objectweb.joram.shared.client.SessCreateTDReply")){ 105 return SessCreateTDReply.soapDecode(h); 106 } else if (className.equals("org.objectweb.joram.shared.client.CnxCloseReply")){ 107 return CnxCloseReply.soapDecode(h); 108 } else if (className.equals("org.objectweb.joram.shared.client.CnxConnectReply")){ 109 return CnxConnectReply.soapDecode(h); 110 } else if (className.equals("org.objectweb.joram.shared.client.ConsumerMessages")){ 111 return ConsumerMessages.soapDecode(h); 112 } else if (className.equals("org.objectweb.joram.shared.client.GetAdminTopicReply")){ 113 return GetAdminTopicReply.soapDecode(h); 114 } else { 115 throw new MessageFormatException( "SoapObject " + className 116 + " can't be converted to an Object."); 117 } 118 } 119 120 static SoapObject getSoapObject(SetCnx request) { 121 SoapObject sO = new SoapObject(NAMESPACE, "setConnection"); 122 sO.addProperty("name", request.name); 123 sO.addProperty("password", request.password); 124 sO.addProperty("timeout", request.timeout); 125 return sO; 126 } 127 128 static int getSetCnx(SoapObject sO) { 129 int ret = -1; 130 try { 131 ret = ((Integer ) sO.getProperty("return")).intValue(); 132 if (ret < 0) 133 ret = -1; 134 } catch (Exception e) {ret = -1;} 135 return ret; 136 } 137 138 static private SoapObject getSoapObject(GetReply request) { 139 SoapObject sO = new SoapObject(NAMESPACE, "getReply"); 140 sO.addProperty("name", request.name); 141 sO.addProperty("cnxId", new Integer (request.cnxId)); 142 return sO; 143 } 144 } 145 | Popular Tags |