1 6 7 package org.jfox.jms.message; 8 9 import java.io.Serializable ; 10 import javax.jms.DeliveryMode ; 11 import javax.jms.Destination ; 12 import javax.jms.JMSException ; 13 14 22 23 public class MessageHeader implements Serializable { 24 25 private Destination destination = null; 26 private int deliveryMode = DeliveryMode.NON_PERSISTENT; 27 private String messageID = null; 28 private long timestamp = 0; 29 private String correlationID = ""; 30 private Destination replyTo = null; 31 private boolean redelivered = false; 32 private String messageType = ""; 33 private long expiration = 0; 34 private int priority = 0; 35 36 public final static String MESSAGEID_PREFIX = "ID:"; 37 38 41 MessageHeader() { 42 } 43 44 51 public void setJMSDestination(Destination destination) 52 throws JMSException { 53 if (destination instanceof Destination ) { 54 this.destination = (Destination ) destination; 55 } else { 56 throw new JMSException ("Message Destination unKnown."); 57 } 58 } 59 60 68 public Destination getJMSDestination() throws JMSException { 69 return this.destination; 70 } 71 72 81 public void setJMSDeliveryMode(int deliveryMode) throws JMSException { 82 if (deliveryMode != DeliveryMode.NON_PERSISTENT && deliveryMode != DeliveryMode.PERSISTENT) { 83 throw new JMSException ("invalide Delivery Mode: " + deliveryMode); 84 } 85 this.deliveryMode = deliveryMode; 86 } 87 88 95 public int getJMSDeliveryMode() throws JMSException { 96 return deliveryMode; 97 } 98 99 111 public void setJMSMessageID(String id) throws JMSException { 112 if (!id.startsWith(MESSAGEID_PREFIX)) { 113 throw new JMSException ("The message id must start with ID:"); 114 } 115 this.messageID = id; 116 } 117 118 146 public String getJMSMessageID() throws JMSException { 147 return messageID; 148 156 } 157 158 170 public void setJMSTimestamp(long timestamp) throws JMSException { 171 this.timestamp = timestamp; 172 } 173 174 189 public long getJMSTimestamp() throws JMSException { 190 return timestamp; 191 } 192 193 238 public void setJMSCorrelationID(String correlationID) throws JMSException { 239 this.correlationID = correlationID; 240 } 241 242 257 public String getJMSCorrelationID() throws JMSException { 258 return correlationID; 259 } 260 261 288 void setJMSCorrelationIDAsBytes(byte[] correlationID) 289 throws JMSException { 290 this.correlationID = new String (correlationID); 291 } 292 293 307 byte[] getJMSCorrelationIDAsBytes() throws JMSException { 308 return correlationID.getBytes(); 309 } 310 311 343 public void setJMSReplyTo(Destination replyTo) throws JMSException { 344 if (replyTo instanceof Destination ) { 345 this.replyTo = (Destination ) replyTo; 346 } else { 347 throw new JMSException ("Illegal Destination Type."); 348 } 349 } 350 351 361 public Destination getJMSReplyTo() throws JMSException { 362 return this.replyTo; 363 } 364 365 377 public void setJMSRedelivered(boolean redelivered) throws JMSException { 378 this.redelivered = redelivered; 379 } 380 381 395 public boolean getJMSRedelivered() throws JMSException { 396 return this.redelivered; 397 } 398 399 408 public String getJMSType() throws JMSException { 409 return messageType; 410 } 411 412 439 public void setJMSType(String type) throws JMSException { 440 this.messageType = type; 441 } 442 443 451 public void setJMSExpiration(long expiration) throws JMSException { 452 if (expiration >= 0) { 453 this.expiration = expiration; 454 } else { 455 throw new JMSException ("Illegal Message Expiration."); 456 } 457 458 } 459 460 490 public long getJMSExpiration() throws JMSException { 491 return expiration; 492 } 493 494 502 public void setJMSPriority(int priority) throws JMSException { 503 if (priority >= 0 && priority < 10) { 504 this.priority = priority; 505 } else { 506 throw new JMSException ("Invalid message defaultPriority"); 507 } 508 } 509 510 524 public int getJMSPriority() throws JMSException { 525 return priority; 526 } 527 } 528 | Popular Tags |