1 24 package com.scalagent.kjoram.jms; 25 26 import com.scalagent.kjoram.messages.Message; 27 import java.util.Hashtable ; 28 import java.util.Enumeration ; 29 import java.util.Vector ; 30 31 35 public class ProducerMessages extends AbstractJmsRequest 36 { 37 38 private Message message = null; 39 40 private Vector messages = null; 41 42 43 48 public ProducerMessages(String dest) 49 { 50 super(dest); 51 messages = new Vector (); 52 } 53 54 61 public ProducerMessages(String dest, Message msg) 62 { 63 super(dest); 64 message = msg; 65 } 66 67 68 69 public void addMessage(Message msg) 70 { 71 messages.addElement(msg); 72 } 73 74 75 public void setMessage(Message msg) { 76 message = msg; 77 } 78 79 80 public void addMessages(Vector msgs) 81 { 82 for (Enumeration e = msgs.elements(); e.hasMoreElements(); ) 83 messages.addElement(e.nextElement()); 84 } 85 86 87 public Vector getMessages() 88 { 89 if (message != null) { 90 Vector vec = new Vector (); 91 vec.addElement(message); 92 return vec; 93 } 94 return messages; 95 } 96 97 101 public Hashtable soapCode() { 102 Hashtable h = super.soapCode(); 103 int size = 0; 105 if (messages != null) 106 size = messages.size(); 107 if (size > 0) { 108 Vector arrayMsg = new Vector (); 109 for (int i = 0; i<size; i++) { 110 Message msg = (Message) messages.elementAt(0); 111 messages.removeElementAt(0); 112 arrayMsg.insertElementAt(msg.soapCode(),i); 113 } 114 if (!arrayMsg.isEmpty()) 115 h.put("arrayMsg",arrayMsg); 116 } else { 117 if (message != null) { 118 h.put("singleMsg",message.soapCode()); 119 } 120 } 121 return h; 122 } 123 124 128 public static Object soapDecode(Hashtable h) { 129 ProducerMessages req = new ProducerMessages(null); 130 req.setRequestId(((Integer ) h.get("requestId")).intValue()); 131 req.setTarget((String ) h.get("target")); 132 Vector arrayMsg = (Vector ) h.get("arrayMsg"); 133 if (arrayMsg != null) { 134 for (int i = 0; i<arrayMsg.size(); i++) 135 req.addMessage(Message.soapDecode((Hashtable ) arrayMsg.elementAt(i))); 136 } else 137 req.setMessage(Message.soapDecode((Hashtable )h.get("singleMsg"))); 138 return req; 139 } 140 } 141 | Popular Tags |