1 48 49 50 package org.exolab.jms.message; 51 52 53 import java.io.Externalizable ; 54 import java.io.IOException ; 55 import java.io.ObjectInput ; 56 import java.io.ObjectOutput ; 57 58 import javax.jms.DeliveryMode ; 59 import javax.jms.JMSException ; 60 61 62 68 public class DeliveryModeImpl implements DeliveryMode , Externalizable { 69 70 static final long serialVersionUID = 1; 72 73 private int mode_ = DeliveryMode.NON_PERSISTENT; 74 75 public DeliveryModeImpl() { 76 77 } 78 79 public DeliveryModeImpl(int mode) throws JMSException { 80 if (validMode(mode)) { 81 mode_ = mode; 82 } else { 83 throw new JMSException ("Invalid Mode"); 84 } 85 } 86 87 private boolean validMode(int mode) { 89 return (mode >= DeliveryMode.NON_PERSISTENT && 90 mode <= DeliveryMode.PERSISTENT); 91 } 92 93 public void writeExternal(ObjectOutput out) throws IOException { 95 out.writeLong(serialVersionUID); 96 out.writeInt(mode_); 97 } 98 99 100 public void readExternal(ObjectInput in) 102 throws IOException , ClassNotFoundException { 103 long version = in.readLong(); 104 if (version == serialVersionUID) { 105 mode_ = in.readInt(); 106 } else { 107 throw new IOException ("Incorrect version enountered: " + 108 version + " This version = " + 109 serialVersionUID); 110 } 111 } 112 113 public void setDeliveryMode(int mode) throws JMSException { 114 if (validMode(mode)) { 115 mode_ = mode; 116 } else { 117 throw new JMSException ("Invalid Mode"); 118 } 119 } 120 121 public int getDeliveryMode() { 122 return mode_; 123 } 124 125 public boolean isPersistent() { 127 return (mode_ == DeliveryMode.PERSISTENT ? true : false); 128 } 129 } 130 131 | Popular Tags |