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 ConsumerMessages extends AbstractJmsReply 36 { 37 38 private Message message = null; 39 40 private Vector messages = null; 41 42 private String comingFrom = null; 43 44 private boolean queueMode; 45 46 47 56 public ConsumerMessages(int correlationId, Message message, 57 String comingFrom, boolean queueMode) 58 { 59 super(correlationId); 60 this.message = message; 61 this.comingFrom = comingFrom; 62 this.queueMode = queueMode; 63 if (message != null) { 64 messages = new Vector (); 65 messages.addElement(message); 66 } 67 } 68 69 78 public ConsumerMessages(int correlationId, Vector messages, 79 String comingFrom, boolean queueMode) 80 { 81 super(correlationId); 82 this.messages = messages; 83 this.comingFrom = comingFrom; 84 this.queueMode = queueMode; 85 } 86 87 95 public ConsumerMessages(int correlationId, String comingFrom, 96 boolean queueMode) 97 { 98 super(correlationId); 99 this.comingFrom = comingFrom; 100 this.queueMode = queueMode; 101 messages = new Vector (); 102 } 103 104 107 public ConsumerMessages() { 108 messages = new Vector (); 109 } 110 111 112 public Vector getMessages() 113 { 114 if (messages == null) { 115 messages = new Vector (); 116 if (message != null) 117 messages.addElement(message); 118 } 119 return messages; 120 } 121 122 126 public String comesFrom() 127 { 128 return comingFrom; 129 } 130 131 public void setComesFrom(String comingFrom) { 132 this.comingFrom = comingFrom; 133 } 134 135 136 public boolean getQueueMode() 137 { 138 return queueMode; 139 } 140 141 public void setQueueMode(boolean queueMode) { 142 this.queueMode = queueMode; 143 } 144 145 146 public Message getMessage() 147 { 148 if (messages == null || messages.isEmpty()) 149 return null; 150 151 return (Message) messages.elementAt(0); 152 } 153 154 public void addMessage(Message msg) { 155 messages.addElement(msg); 156 } 157 158 public void setMessage(Message msg) { 159 message = msg; 160 } 161 162 166 public Hashtable soapCode() { 167 Hashtable h = super.soapCode(); 168 if (comingFrom != null) 169 h.put("comingFrom",comingFrom); 170 h.put("queueMode",new Boolean (queueMode)); 171 int size = 0; 173 if (messages != null) 174 size = messages.size(); 175 if (size > 0) { 176 Vector arrayMsg = new Vector (); 177 for (int i = 0; i<size; i++) { 178 Message msg = (Message) messages.elementAt(0); 179 messages.removeElementAt(0); 180 arrayMsg.insertElementAt(msg.soapCode(),i); 181 } 182 if (arrayMsg != null) 183 h.put("arrayMsg",arrayMsg); 184 } else { 185 if (message != null) { 186 h.put("singleMsg",message.soapCode()); 187 } 188 } 189 return h; 190 } 191 192 196 public static Object soapDecode(Hashtable h) { 197 ConsumerMessages req = new ConsumerMessages(); 198 req.setCorrelationId(((Integer ) h.get("correlationId")).intValue()); 199 req.setComesFrom((String ) h.get("comingFrom")); 200 req.setQueueMode(((Boolean ) h.get("queueMode")).booleanValue()); 201 Vector arrayMsg = (Vector ) h.get("arrayMsg"); 202 if (arrayMsg != null) { 203 for (int i = 0; i<arrayMsg.size(); i++) 204 req.addMessage(Message.soapDecode((Hashtable ) arrayMsg.elementAt(i))); 205 } else 206 req.setMessage(Message.soapDecode((Hashtable )h.get("singleMsg"))); 207 return req; 208 } 209 } 210 | Popular Tags |