1 7 package org.jboss.jms.message.standard; 8 9 import java.util.Enumeration ; 10 11 import javax.jms.Destination ; 12 import javax.jms.JMSException ; 13 14 import org.jboss.jms.client.SessionDelegate; 15 import org.jboss.jms.message.JBossMessage; 16 import org.jboss.jms.util.MessageProperties; 17 import org.jboss.util.id.GUID; 18 19 25 public class StandardMessage 26 implements JBossMessage 27 { 28 30 32 33 private transient SessionDelegate session; 34 35 36 private MessageProperties properties = new MessageProperties(); 37 38 39 private String messageID; 40 41 42 private Destination destination; 43 44 45 private int deliveryMode; 46 47 48 private int priority; 49 50 51 private long timestamp; 52 53 54 private long expiration; 55 56 57 private String type; 58 59 60 private Destination replyTo; 61 62 63 private String correlationID; 64 65 66 private boolean redelivered; 67 68 69 private boolean readonly = false; 70 71 73 75 77 public StandardMessage(SessionDelegate session) 78 throws JMSException 79 { 80 this.session = session; 81 } 82 83 85 public void acknowledge() throws JMSException 86 { 87 session.acknowledge(this, true); 88 } 89 90 public void clearBody() throws JMSException 91 { 92 readonly = false; 93 } 94 95 public void clearProperties() throws JMSException 96 { 97 properties.clear(); 98 } 99 100 public boolean getBooleanProperty(String name) throws JMSException 101 { 102 return properties.getBoolean(name); 103 } 104 105 public byte getByteProperty(String name) throws JMSException 106 { 107 return properties.getByte(name); 108 } 109 110 public double getDoubleProperty(String name) throws JMSException 111 { 112 return properties.getDouble(name); 113 } 114 115 public float getFloatProperty(String name) throws JMSException 116 { 117 return properties.getFloat(name); 118 } 119 120 public int getIntProperty(String name) throws JMSException 121 { 122 return properties.getInt(name); 123 } 124 125 public String getJMSCorrelationID() throws JMSException 126 { 127 return correlationID; 128 } 129 130 public byte[] getJMSCorrelationIDAsBytes() throws JMSException 131 { 132 return null; 134 } 135 136 public int getJMSDeliveryMode() throws JMSException 137 { 138 return deliveryMode; 139 } 140 141 public Destination getJMSDestination() throws JMSException 142 { 143 return destination; 144 } 145 146 public long getJMSExpiration() throws JMSException 147 { 148 return expiration; 149 } 150 151 public String getJMSMessageID() throws JMSException 152 { 153 return messageID; 154 } 155 156 public int getJMSPriority() throws JMSException 157 { 158 return priority; 159 } 160 161 public boolean getJMSRedelivered() throws JMSException 162 { 163 return redelivered; 164 } 165 166 public Destination getJMSReplyTo() throws JMSException 167 { 168 return replyTo; 169 } 170 171 public long getJMSTimestamp() throws JMSException 172 { 173 return timestamp; 174 } 175 176 public String getJMSType() throws JMSException 177 { 178 return type; 179 } 180 181 public long getLongProperty(String name) throws JMSException 182 { 183 return properties.getLong(name); 184 } 185 186 public Object getObjectProperty(String name) throws JMSException 187 { 188 return properties.getObject(name); 189 } 190 191 public Enumeration getPropertyNames() throws JMSException 192 { 193 return properties.getMapNames(); 194 } 195 196 public short getShortProperty(String name) throws JMSException 197 { 198 return properties.getShort(name); 199 } 200 201 public String getStringProperty(String name) throws JMSException 202 { 203 return properties.getString(name); 204 } 205 206 public boolean propertyExists(String name) throws JMSException 207 { 208 return properties.itemExists(name); 209 } 210 211 public void setBooleanProperty(String name, boolean value) throws JMSException 212 { 213 properties.setBoolean(name, value); 214 } 215 216 public void setByteProperty(String name, byte value) throws JMSException 217 { 218 properties.setByte(name, value); 219 } 220 221 public void setDoubleProperty(String name, double value) throws JMSException 222 { 223 properties.setDouble(name, value); 224 } 225 226 public void setFloatProperty(String name, float value) throws JMSException 227 { 228 properties.setFloat(name, value); 229 } 230 231 public void setIntProperty(String name, int value) throws JMSException 232 { 233 properties.setInt(name, value); 234 } 235 236 public void setJMSCorrelationID(String correlationID) throws JMSException 237 { 238 checkReadOnly(); 239 this.correlationID = correlationID; 240 } 241 242 public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException 243 { 244 checkReadOnly(); 245 } 247 248 public void setJMSDeliveryMode(int deliveryMode) throws JMSException 249 { 250 checkReadOnly(); 251 this.deliveryMode = deliveryMode; 252 } 253 254 public void setJMSDestination(Destination destination) throws JMSException 255 { 256 checkReadOnly(); 257 this.destination = destination; 258 } 259 260 public void setJMSExpiration(long expiration) throws JMSException 261 { 262 checkReadOnly(); 263 this.expiration = expiration; 264 } 265 266 public void setJMSMessageID(String id) throws JMSException 267 { 268 checkReadOnly(); 269 this.messageID = id; 270 } 271 272 public void setJMSPriority(int priority) throws JMSException 273 { 274 checkReadOnly(); 275 this.priority = priority; 276 } 277 278 public void setJMSRedelivered(boolean redelivered) throws JMSException 279 { 280 checkReadOnly(); 281 this.redelivered = redelivered; 282 } 283 284 public void setJMSReplyTo(Destination replyTo) throws JMSException 285 { 286 checkReadOnly(); 287 this.replyTo = replyTo; 288 } 289 290 public void setJMSTimestamp(long timestamp) throws JMSException 291 { 292 checkReadOnly(); 293 this.timestamp = timestamp; 294 } 295 296 public void setJMSType(String type) throws JMSException 297 { 298 checkReadOnly(); 299 this.type = type; 300 } 301 302 public void setLongProperty(String name, long value) throws JMSException 303 { 304 properties.setLong(name, value); 305 } 306 307 public void setObjectProperty(String name, Object value) throws JMSException 308 { 309 properties.setObject(name, value); 310 } 311 312 public void setShortProperty(String name, short value) throws JMSException 313 { 314 properties.setShort(name, value); 315 } 316 317 public void setStringProperty(String name, String value) throws JMSException 318 { 319 properties.setString(name, value); 320 } 321 322 324 public SessionDelegate getSessionDelegate() throws JMSException 325 { 326 return session; 327 } 328 329 public void generateMessageID() throws JMSException 330 { 331 checkReadOnly(); 332 messageID = GUID.asString(); 333 } 334 335 public void generateTimestamp() throws JMSException 336 { 337 checkReadOnly(); 338 timestamp = System.currentTimeMillis(); 339 } 340 341 public void makeReadOnly() throws JMSException 342 { 343 readonly = true; 344 properties.setReadOnly(true); 345 } 346 347 349 public Object clone() 350 throws CloneNotSupportedException 351 { 352 return super.clone(); 353 } 354 355 357 359 361 366 private void checkReadOnly() 367 throws JMSException 368 { 369 if (readonly) 370 throw new JMSException ("The message is read only"); 371 } 372 373 375 } 376 | Popular Tags |