1 45 package org.exolab.jms.message; 46 47 import java.io.Externalizable ; 48 import java.io.IOException ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectOutput ; 51 import javax.jms.Destination ; 52 import javax.jms.JMSException ; 53 54 55 62 class MessageHeader implements Externalizable , Cloneable { 63 64 static final long serialVersionUID = 1; 65 66 private DestinationImpl _replyTo = null; 67 private Timestamp _timestamp = null; 68 private CorrelationId _correlationId = null; 69 private boolean _redelivered = false; 70 private long _expiration = 0; 71 private Priority _priority = null; 72 private Type _type = null; 73 private DestinationImpl _destination = null; 74 private DeliveryModeImpl _mode = null; 75 76 77 81 private MessageId _id = null; 82 83 89 private transient String _ackId; 90 91 95 private String _wildcard = null; 96 97 101 private String _unused = null; 102 103 107 private long _consumerId; 108 109 110 public MessageHeader() { 111 } 112 113 119 public Object clone() throws CloneNotSupportedException { 120 MessageHeader result = (MessageHeader) super.clone(); 121 result._replyTo = _replyTo; 122 result._timestamp = _timestamp; 123 result._correlationId = _correlationId; 124 result._priority = _priority; 125 result._type = _type; 126 result._destination = _destination; 127 result._mode = _mode; 128 result._id = _id; 129 result._ackId = _ackId; 130 result._wildcard = (_wildcard == null ? null : _wildcard); 131 result._consumerId = _consumerId; 132 return result; 133 } 134 135 136 public void writeExternal(ObjectOutput out) throws IOException { 138 out.writeLong(serialVersionUID); 139 out.writeObject(_replyTo); 140 out.writeObject(_timestamp); 141 out.writeObject(_correlationId); 142 out.writeBoolean(_redelivered); 143 out.writeLong(_expiration); 144 out.writeObject(_priority); 145 out.writeObject(_type); 146 out.writeObject(_destination); 147 out.writeObject(_mode); 148 out.writeObject(_id); 149 out.writeObject(_wildcard); 150 out.writeObject(_unused); 151 out.writeLong(_consumerId); 152 } 153 154 public void readExternal(ObjectInput in) 155 throws IOException , ClassNotFoundException { 156 long version = in.readLong(); 157 if (version == serialVersionUID) { 158 _replyTo = (DestinationImpl) in.readObject(); 159 _timestamp = (Timestamp) in.readObject(); 160 _correlationId = (CorrelationId) in.readObject(); 161 _redelivered = in.readBoolean(); 162 _expiration = in.readLong(); 163 _priority = (Priority) in.readObject(); 164 _type = (Type) in.readObject(); 165 _destination = (DestinationImpl) in.readObject(); 166 _mode = (DeliveryModeImpl) in.readObject(); 167 _id = (MessageId) in.readObject(); 168 _wildcard = (String ) in.readObject(); 169 _unused = (String ) in.readObject(); 170 _consumerId = in.readLong(); 171 } else { 172 throw new IOException ("Incorrect version enountered: " + 173 version + " This version = " + 174 serialVersionUID); 175 } 176 } 177 178 Destination getJMSReplyTo() throws JMSException { 179 return _replyTo; 180 } 181 182 public void setJMSReplyTo(Destination replyTo) throws JMSException { 183 if (replyTo instanceof DestinationImpl) { 184 _replyTo = (DestinationImpl) replyTo; 185 } else { 186 throw new JMSException ("Unknown Destination Type"); 187 } 188 } 189 190 void setJMSDestination(Destination destination) throws JMSException { 191 if (destination instanceof DestinationImpl) { 192 _destination = (DestinationImpl) destination; 193 } else { 194 throw new JMSException ("Unknown Destination Type"); 195 } 196 } 197 198 public Destination getJMSDestination() throws JMSException { 199 return _destination; 200 } 201 202 public void setJMSMessageID(String id) throws JMSException { 203 if (id != null) { 204 if (!id.startsWith(MessageId.PREFIX)) { 205 throw new JMSException ("Invalid JMSMessageID: " + id); 206 } 207 _id = new MessageId(id); 208 } else { 209 _id = null; 210 } 211 } 212 213 public String getJMSMessageID() throws JMSException { 214 return (_id != null) ? _id.toString() : null; 215 } 216 217 227 public void setAckMessageID(String id) { 228 _ackId = id; 229 } 230 231 236 public String getAckMessageID() { 237 return _ackId; 238 } 239 240 public void setJMSTimestamp(long timestamp) throws JMSException { 241 _timestamp = new Timestamp(timestamp); 242 } 243 244 public long getJMSTimestamp() throws JMSException { 245 if (_timestamp != null) { 246 return _timestamp.toLong(); 247 } else { 248 throw new JMSException ("No Timestamp set"); 249 } 250 } 251 252 public void setJMSCorrelationIDAsBytes(byte[] correlationID) 253 throws JMSException { 254 _correlationId = new CorrelationId(correlationID); 255 } 256 257 public byte[] getJMSCorrelationIDAsBytes() throws JMSException { 258 return (_correlationId != null ? _correlationId.getBytes() : null); 259 } 260 261 public void setJMSCorrelationID(String correlationID) throws JMSException { 262 if (correlationID != null) { 263 _correlationId = new CorrelationId(correlationID); 264 } else { 265 _correlationId = null; 266 } 267 } 268 269 public String getJMSCorrelationID() throws JMSException { 270 return (_correlationId != null ? _correlationId.getString() : null); 271 } 272 273 public void setJMSDeliveryMode(int mode) throws JMSException { 274 _mode = new DeliveryModeImpl(mode); 275 } 276 277 public int getJMSDeliveryMode() throws JMSException { 278 if (_mode != null) { 279 return _mode.getDeliveryMode(); 280 } else { 281 throw new JMSException ("No Delivery Mode set"); 282 } 283 } 284 285 public boolean getJMSRedelivered() throws JMSException { 286 return _redelivered; 287 } 288 289 public void setJMSRedelivered(boolean redelivered) throws JMSException { 290 _redelivered = redelivered; 291 } 292 293 public void setJMSType(String type) throws JMSException { 294 if (type != null) { 295 _type = new Type(type); 296 } else { 297 _type = null; 298 } 299 } 300 301 public String getJMSType() throws JMSException { 302 return (_type != null) ? _type.getType() : null; 303 } 304 305 public void setJMSExpiration(long expiration) throws JMSException { 306 _expiration = expiration; 307 } 308 309 public long getJMSExpiration() throws JMSException { 310 return _expiration; 311 } 312 313 public void setJMSPriority(int priority) throws JMSException { 314 _priority = new Priority(priority); 315 } 316 317 public int getJMSPriority() throws JMSException { 318 if (_priority != null) { 319 return _priority.getPriority(); 320 } else { 321 return 0; 322 } 323 } 324 325 330 public long getConsumerId() { 331 return _consumerId; 332 } 333 334 339 public void setConsumerId(long consumerId) { 340 _consumerId = consumerId; 341 } 342 343 348 public MessageId getMessageId() { 349 return _id; 350 } 351 352 357 public String getWildcard() { 358 return _wildcard; 359 } 360 361 366 public void setWildcard(String wildcard) { 367 _wildcard = wildcard; 368 } 369 370 } 371 | Popular Tags |