1 6 7 package org.jfox.jms.message; 8 9 import java.io.Serializable ; 10 import java.util.Enumeration ; 11 import javax.jms.Destination ; 12 import javax.jms.JMSException ; 13 import javax.jms.Message ; 14 import javax.jms.MessageNotWriteableException ; 15 16 import org.jfox.jms.JMSConsumer; 17 import org.jfox.jms.JMSSession; 18 19 29 30 public class JMSMessage implements Message , Serializable , Comparable { 31 32 private MessageHeader messageHeader = new MessageHeader(); 33 private MessageProperties messageProperties = new MessageProperties(); 34 35 private boolean propertiesModifiable = true; 37 38 private boolean bodyModifiable = true; 40 41 44 private transient JMSSession session = null; 45 48 private transient JMSConsumer consumer = null; 49 50 public JMSMessage() { 51 try { 52 setJMSPriority(DEFAULT_PRIORITY); 53 setJMSDeliveryMode(DEFAULT_DELIVERY_MODE); 54 } catch (JMSException e) { 55 } 56 57 try { 58 clearProperties(); 59 } catch (JMSException je) { 60 } 61 setBodyModifiable(true); 62 } 63 64 73 public String getJMSMessageID() throws JMSException { 74 return messageHeader.getJMSMessageID(); 75 } 76 77 85 public void setJMSMessageID(String id) throws JMSException { 86 messageHeader.setJMSMessageID(id); 87 } 88 89 98 public long getJMSTimestamp() throws JMSException { 99 return messageHeader.getJMSTimestamp(); 100 } 101 102 114 public void setJMSTimestamp(long timestamp) throws JMSException { 115 messageHeader.setJMSTimestamp(timestamp); 116 } 117 118 132 public byte[] getJMSCorrelationIDAsBytes() throws JMSException { 133 return messageHeader.getJMSCorrelationIDAsBytes(); 134 } 135 136 154 public void setJMSCorrelationIDAsBytes(byte[] correlationID) 155 throws JMSException { 156 messageHeader.setJMSCorrelationIDAsBytes(correlationID); 157 } 158 159 174 public String getJMSCorrelationID() throws JMSException { 175 return messageHeader.getJMSCorrelationID(); 176 } 177 178 188 public void setJMSCorrelationID(String correlationID) throws JMSException { 189 messageHeader.setJMSCorrelationID(correlationID); 190 } 191 192 202 public Destination getJMSReplyTo() throws JMSException { 203 return messageHeader.getJMSReplyTo(); 204 } 205 206 216 public void setJMSReplyTo(Destination replyTo) throws JMSException { 217 messageHeader.setJMSReplyTo(replyTo); 218 } 219 220 228 public Destination getJMSDestination() throws JMSException { 229 return messageHeader.getJMSDestination(); 230 } 231 232 244 public void setJMSDestination(Destination destination) 245 throws JMSException { 246 messageHeader.setJMSDestination(destination); 247 } 248 249 258 public int getJMSDeliveryMode() throws JMSException { 259 return messageHeader.getJMSDeliveryMode(); 260 } 261 262 275 public void setJMSDeliveryMode(int deliveryMode) throws JMSException { 276 messageHeader.setJMSDeliveryMode(deliveryMode); 277 } 278 279 293 public boolean getJMSRedelivered() throws JMSException { 294 return messageHeader.getJMSRedelivered(); 295 } 296 297 309 public void setJMSRedelivered(boolean redelivered) throws JMSException { 310 messageHeader.setJMSRedelivered(redelivered); 311 } 312 313 322 public String getJMSType() throws JMSException { 323 return messageHeader.getJMSType(); 324 } 325 326 334 public void setJMSType(String type) throws JMSException { 335 messageHeader.setJMSType(type); 336 } 337 338 348 public long getJMSExpiration() throws JMSException { 349 return messageHeader.getJMSExpiration(); 350 } 351 352 364 public void setJMSExpiration(long expiration) throws JMSException { 365 messageHeader.setJMSExpiration(expiration); 366 } 367 368 382 public int getJMSPriority() throws JMSException { 383 return messageHeader.getJMSPriority(); 384 } 385 386 398 public void setJMSPriority(int priority) throws JMSException { 399 messageHeader.setJMSPriority(priority); 400 } 401 402 408 public void clearProperties() throws JMSException { 409 messageProperties.clearProperties(); 410 propertiesModifiable = true; 411 bodyModifiable = true; 412 } 413 414 420 public boolean propertyExists(String name) throws JMSException { 421 return messageProperties.propertyExists(name); 422 } 423 424 435 public boolean getBooleanProperty(String name) throws JMSException { 436 return messageProperties.getBooleanProperty(name); 437 } 438 439 450 public byte getByteProperty(String name) throws JMSException { 451 return messageProperties.getByteProperty(name); 452 } 453 454 465 public short getShortProperty(String name) throws JMSException { 466 return messageProperties.getShortProperty(name); 467 } 468 469 480 public int getIntProperty(String name) throws JMSException { 481 return messageProperties.getIntProperty(name); 482 } 483 484 495 public long getLongProperty(String name) throws JMSException { 496 return messageProperties.getLongProperty(name); 497 } 498 499 510 public float getFloatProperty(String name) throws JMSException { 511 return messageProperties.getFloatProperty(name); 512 } 513 514 525 public double getDoubleProperty(String name) throws JMSException { 526 return messageProperties.getDoubleProperty(name); 527 } 528 529 541 public String getStringProperty(String name) throws JMSException { 542 return messageProperties.getStringProperty(name); 543 } 544 545 562 public Object getObjectProperty(String name) throws JMSException { 563 return messageProperties.getObjectProperty(name); 564 } 565 566 577 public Enumeration getPropertyNames() throws JMSException { 578 return messageProperties.getPropertyNames(); 579 } 580 581 592 public void setBooleanProperty(String name, boolean value) 593 throws JMSException { 594 if (isPropertiesModifiable()) { 595 messageProperties.setBooleanProperty(name, value); 596 } else { 597 throw new MessageNotWriteableException ("Message boolean property is read-only"); 598 } 599 } 600 601 612 public void setByteProperty(String name, byte value) throws JMSException { 613 if (isPropertiesModifiable()) { 614 messageProperties.setByteProperty(name, value); 615 } else { 616 throw new MessageNotWriteableException ("Message byte property is read-only"); 617 } 618 } 619 620 631 public void setShortProperty(String name, short value) 632 throws JMSException { 633 if (isPropertiesModifiable()) { 634 messageProperties.setShortProperty(name, value); 635 } else { 636 throw new MessageNotWriteableException ("Message short property is read-only"); 637 } 638 } 639 640 651 public void setIntProperty(String name, int value) throws JMSException { 652 if (isPropertiesModifiable()) { 653 messageProperties.setIntProperty(name, value); 654 } else { 655 throw new MessageNotWriteableException ("Message int property is read-only"); 656 } 657 } 658 659 670 public void setLongProperty(String name, long value) throws JMSException { 671 if (isPropertiesModifiable()) { 672 messageProperties.setLongProperty(name, value); 673 } else { 674 throw new MessageNotWriteableException ("Message long property is read-only"); 675 } 676 } 677 678 689 public void setFloatProperty(String name, float value) 690 throws JMSException { 691 if (isPropertiesModifiable()) { 692 messageProperties.setFloatProperty(name, value); 693 } else { 694 throw new MessageNotWriteableException ("Message float property is read-only"); 695 } 696 } 697 698 709 public void setDoubleProperty(String name, double value) 710 throws JMSException { 711 if (isPropertiesModifiable()) { 712 messageProperties.setDoubleProperty(name, value); 713 } else { 714 throw new MessageNotWriteableException ("Message double property is read-only"); 715 } 716 } 717 718 729 public void setStringProperty(String name, String value) 730 throws JMSException { 731 if (isPropertiesModifiable()) { 732 messageProperties.setStringProperty(name, value); 733 } else { 734 throw new MessageNotWriteableException ("Message string property is read-only"); 735 } 736 } 737 738 756 public void setObjectProperty(String name, Object value) 757 throws JMSException { 758 if (isPropertiesModifiable()) { 759 messageProperties.setObjectProperty(name, value); 760 } else { 761 throw new MessageNotWriteableException ("Message object property is read-only"); 762 } 763 } 764 765 768 public void acknowledge() throws JMSException { 769 if (session == null || consumer == null) { 770 throw new JMSException ("message not delivered."); 771 } 772 session.acknowledge(consumer, this); 773 } 774 775 787 public void clearBody() throws JMSException { 788 setBodyModifiable(true); 789 } 790 791 797 public void setPropertiesModifiable(boolean state) { 798 propertiesModifiable = state; 799 } 800 801 807 public boolean isPropertiesModifiable() { 808 return propertiesModifiable; 809 } 810 811 817 public void setBodyModifiable(boolean state) { 818 bodyModifiable = state; 819 } 820 821 827 public boolean isBodyModifiable() { 828 return bodyModifiable; 829 } 830 831 public int compareTo(Object pObject) { 832 if (pObject == null || !(pObject instanceof Message )) return 0; 833 try { 834 return this.getJMSPriority() - ((Message ) pObject).getJMSPriority(); 835 } catch (Exception e) { 836 return 0; 837 } 838 } 839 840 public void setSession(JMSSession session) { 841 this.session = session; 842 } 843 844 public void setConsumer(JMSConsumer consumer) { 845 this.consumer = consumer; 846 } 847 } | Popular Tags |