View Javadoc
1 /*** 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Exoffice Technologies. For written permission, 18 * please contact tma@netspace.net.au. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Exoffice Technologies. Exolab is a registered 23 * trademark of Exoffice Technologies. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 2003 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: BasicMessage.java,v 1.2 2004/02/02 03:49:55 tanderson Exp $ 44 */ 45 46 package org.exolab.jmscts.jms.message; 47 48 import java.util.Collections; 49 import java.util.Enumeration; 50 import java.util.HashMap; 51 52 import javax.jms.Destination; 53 import javax.jms.JMSException; 54 import javax.jms.Message; 55 import javax.jms.MessageFormatException; 56 import javax.jms.MessageNotReadableException; 57 import javax.jms.MessageNotWriteableException; 58 59 60 /*** 61 * This class provides a basic implementation of the javax.jms.Message 62 * interface. 63 * 64 * @version $Revision: 1.2 $ $Date: 2004/02/02 03:49:55 $ 65 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 66 * @see javax.jms.Message 67 */ 68 public class BasicMessage implements Message { 69 70 /*** 71 * If <code>true</code>, message properties are read-only 72 */ 73 private boolean _propertiesReadOnly = false; 74 75 /*** 76 * If <code>true</code>, the message body is read-only 77 */ 78 private boolean _bodyReadOnly = false; 79 80 /*** 81 * The message ID 82 */ 83 private String _messageID; 84 85 /*** 86 * The message type 87 */ 88 private String _type; 89 90 /*** 91 * The message timestamp 92 */ 93 private long _timestamp; 94 95 /*** 96 * The correlation ID 97 */ 98 private String _correlationID; 99 100 /*** 101 * The correlation ID bytes 102 */ 103 private byte[] _correlationIDBytes; 104 105 /*** 106 * The message destination 107 */ 108 private Destination _destination; 109 110 /*** 111 * The reply-to destination 112 */ 113 private Destination _replyTo; 114 115 /*** 116 * The delivery mode 117 */ 118 private int _deliveryMode; 119 120 /*** 121 * The message's expiration value 122 */ 123 private long _expiration; 124 125 /*** 126 * The message priority 127 */ 128 private int _priority; 129 130 /*** 131 * Determines if the message is being redelivered 132 */ 133 private boolean _redelivered; 134 135 /*** 136 * The map of message header properties 137 */ 138 private HashMap _properties = new HashMap(); 139 140 141 /*** 142 * Construct a new <code>BasicMessage</code> 143 */ 144 public BasicMessage() { 145 } 146 147 /*** 148 * No-op. 149 */ 150 public void acknowledge() { 151 } 152 153 /*** 154 * Clear the message body 155 * 156 * @throws JMSException for any error 157 */ 158 public void clearBody() throws JMSException { 159 _bodyReadOnly = false; 160 } 161 162 /*** 163 * Clear the message properties 164 */ 165 public void clearProperties() { 166 _properties.clear(); 167 _propertiesReadOnly = false; 168 } 169 170 /*** 171 * Get the message ID 172 * 173 * @return the message ID 174 */ 175 public String getJMSMessageID() { 176 return _messageID; 177 } 178 179 /*** 180 * Set the message ID 181 * 182 * @param messageID the message ID 183 */ 184 public void setJMSMessageID(String messageID) { 185 _messageID = messageID; 186 } 187 188 /*** 189 * Get the message type 190 * 191 * @return the message type 192 */ 193 public String getJMSType() { 194 return _type; 195 } 196 197 /*** 198 * Set the message type 199 * 200 * @param type the message type 201 */ 202 public void setJMSType(String type) { 203 _type = type; 204 } 205 206 /*** 207 * Get the message timestamp 208 * 209 * @return the message timestamp 210 */ 211 public long getJMSTimestamp() { 212 return _timestamp; 213 } 214 215 /*** 216 * Set the message timetamp 217 * 218 * @param timestamp the message timestamp 219 */ 220 public void setJMSTimestamp(long timestamp) { 221 _timestamp = timestamp; 222 } 223 224 /*** 225 * Get the correlation ID for the message 226 * 227 * @return the correlation ID for the message 228 */ 229 public String getJMSCorrelationID() { 230 return _correlationID; 231 } 232 233 /*** 234 * Set the correlation ID 235 * 236 * @param correlationID the correlation ID 237 */ 238 public void setJMSCorrelationID(String correlationID) { 239 _correlationID = correlationID; 240 } 241 242 /*** 243 * Get the correlation ID as an array of bytes 244 * 245 * @return the correlation ID as an array of bytes 246 */ 247 public byte[] getJMSCorrelationIDAsBytes() { 248 return _correlationIDBytes; 249 } 250 251 /*** 252 * Set the correlation ID as an array of bytes 253 * 254 * @param correlationID the correlation ID as an array of bytes 255 */ 256 public void setJMSCorrelationIDAsBytes(byte[] correlationID) { 257 _correlationIDBytes = correlationID; 258 } 259 260 /*** 261 * Get the message destination 262 * 263 * @return the message destination 264 */ 265 public Destination getJMSDestination() { 266 return _destination; 267 } 268 269 /*** 270 * Set the message destination 271 * 272 * @param destination the message destination 273 */ 274 public void setJMSDestination(Destination destination) { 275 _destination = destination; 276 } 277 278 /*** 279 * Get the reply-to destination 280 * 281 * @return the reply-to destination 282 */ 283 public Destination getJMSReplyTo() { 284 return _replyTo; 285 } 286 287 /*** 288 * Set the reply-to destination 289 * 290 * @param replyTo the reply-to destination 291 */ 292 public void setJMSReplyTo(Destination replyTo) { 293 _replyTo = replyTo; 294 } 295 296 /*** 297 * Get the message delivery mode 298 * 299 * @return the message delivery mode 300 */ 301 public int getJMSDeliveryMode() { 302 return _deliveryMode; 303 } 304 305 /*** 306 * Set the message delivery mode 307 * 308 * @param deliveryMode the message delivery mode 309 */ 310 public void setJMSDeliveryMode(int deliveryMode) { 311 _deliveryMode = deliveryMode; 312 } 313 314 /*** 315 * Get the message's expiration value 316 * 317 * @return the message's expiration value 318 */ 319 public long getJMSExpiration() { 320 return _expiration; 321 } 322 323 /*** 324 * Set the message's expiration value 325 * 326 * @param expiration the message's expiration value 327 */ 328 public void setJMSExpiration(long expiration) { 329 _expiration = expiration; 330 } 331 332 /*** 333 * Get the message priority 334 * 335 * @return the message priority 336 */ 337 public int getJMSPriority() { 338 return _priority; 339 } 340 341 /*** 342 * Set the message priority 343 * 344 * @param priority the message priority 345 */ 346 public void setJMSPriority(int priority) { 347 _priority = priority; 348 } 349 350 /*** 351 * Determine if the message is being delivered 352 * 353 * @return <code>true</code> if the message is being delivered 354 */ 355 public boolean getJMSRedelivered() { 356 return _redelivered; 357 } 358 359 /*** 360 * Set to indicate if the message is being redelivered 361 * 362 * @param redelivered if <code>true</code> indicates the message is being 363 * delivered 364 */ 365 public void setJMSRedelivered(boolean redelivered) { 366 _redelivered = redelivered; 367 } 368 369 /*** 370 * Determines if a property exists 371 * 372 * @param name the property name 373 * @return <code>true</code> if the property exists 374 */ 375 public boolean propertyExists(String name) { 376 return _properties.containsKey(name); 377 } 378 379 /*** 380 * Returns the boolean property value with the give name 381 * 382 * @param name the name of the boolean property 383 * @return the boolean property value with the given name 384 * @throws MessageFormatException if the type conversion is invalid 385 */ 386 public boolean getBooleanProperty(String name) 387 throws MessageFormatException { 388 return FormatConverter.getBoolean(_properties.get(name)); 389 } 390 391 /*** 392 * Set a boolean property value with the given name 393 * 394 * @param name the name of the boolean property 395 * @param value the boolean property value 396 */ 397 public void setBooleanProperty(String name, boolean value) { 398 _properties.put(name, new Boolean(value)); 399 } 400 401 /*** 402 * Returns the byte property value with the give name 403 * 404 * @param name the name of the byte property 405 * @return the byte property value with the given name 406 * @throws MessageFormatException if the type conversion is invalid 407 */ 408 public byte getByteProperty(String name) throws MessageFormatException { 409 return FormatConverter.getByte(_properties.get(name)); 410 } 411 412 /*** 413 * Set a byte property value with the given name 414 * 415 * @param name the name of the byte property 416 * @param value the byte property value 417 */ 418 public void setByteProperty(String name, byte value) { 419 _properties.put(name, new Byte(value)); 420 } 421 422 /*** 423 * Returns the short property value with the give name 424 * 425 * @param name the name of the short property 426 * @return the short property value with the given name 427 * @throws MessageFormatException if the type conversion is invalid 428 */ 429 public short getShortProperty(String name) throws MessageFormatException { 430 return FormatConverter.getShort(_properties.get(name)); 431 } 432 433 /*** 434 * Set a short property value with the given name 435 * 436 * @param name the name of the short property 437 * @param value the short property value 438 */ 439 public void setShortProperty(String name, short value) { 440 _properties.put(name, new Short(value)); 441 } 442 443 /*** 444 * Returns the int property value with the give name 445 * 446 * @param name the name of the int property 447 * @return the int property value with the given name 448 * @throws MessageFormatException if the type conversion is invalid 449 */ 450 public int getIntProperty(String name) throws MessageFormatException { 451 return FormatConverter.getInt(_properties.get(name)); 452 } 453 454 /*** 455 * Set an int property value with the given name 456 * 457 * @param name the name of the int property 458 * @param value the int property value 459 */ 460 public void setIntProperty(String name, int value) { 461 _properties.put(name, new Integer(value)); 462 } 463 464 /*** 465 * Returns the long property value with the give name 466 * 467 * @param name the name of the long property 468 * @return the long property value with the given name 469 * @throws MessageFormatException if the type conversion is invalid 470 */ 471 public long getLongProperty(String name) throws MessageFormatException { 472 return FormatConverter.getLong(_properties.get(name)); 473 } 474 475 /*** 476 * Set a long property value with the given name 477 * 478 * @param name the name of the long property 479 * @param value the long property value 480 */ 481 public void setLongProperty(String name, long value) { 482 _properties.put(name, new Long(value)); 483 } 484 485 /*** 486 * Returns the float property value with the give name 487 * 488 * @param name the name of the float property 489 * @return the float property value with the given name 490 * @throws MessageFormatException if the type conversion is invalid 491 */ 492 public float getFloatProperty(String name) throws MessageFormatException { 493 return FormatConverter.getFloat(_properties.get(name)); 494 } 495 496 /*** 497 * Set a float property value with the given name 498 * 499 * @param name the name of the float property 500 * @param value the float property value 501 */ 502 public void setFloatProperty(String name, float value) { 503 _properties.put(name, new Float(value)); 504 } 505 506 /*** 507 * Returns the double property value with the give name 508 * 509 * @param name the name of the double property 510 * @return the double property value with the given name 511 * @throws MessageFormatException if the type conversion is invalid 512 */ 513 public double getDoubleProperty(String name) 514 throws MessageFormatException { 515 return FormatConverter.getDouble(_properties.get(name)); 516 } 517 518 /*** 519 * Set a double property value with the given name 520 * 521 * @param name the name of the double property 522 * @param value the double property value 523 */ 524 public void setDoubleProperty(String name, double value) { 525 _properties.put(name, new Double(value)); 526 } 527 528 /*** 529 * Returns the String property value with the give name 530 * 531 * @param name the name of the String property 532 * @return the String property value with the given name 533 * @throws MessageFormatException if the type conversion is invalid 534 */ 535 public String getStringProperty(String name) 536 throws MessageFormatException { 537 return FormatConverter.getString(_properties.get(name)); 538 } 539 540 /*** 541 * Set a String property value with the given name 542 * 543 * @param name the name of the String property 544 * @param value the String property value 545 */ 546 public void setStringProperty(String name, String value) { 547 _properties.put(name, value); 548 } 549 550 /*** 551 * Returns the Object property value with the give name 552 * 553 * @param name the name of the Object property 554 * @return the Object property value with the given name 555 */ 556 public Object getObjectProperty(String name) { 557 return _properties.get(name); 558 } 559 560 /*** 561 * Set an Object property value with the given name 562 * 563 * @param name the name of the Object property 564 * @param value the Object property value 565 */ 566 public void setObjectProperty(String name, Object value) { 567 _properties.put(name, value); 568 } 569 570 /*** 571 * Return an enumeration of all the property names 572 * 573 * @return an enumeration of all the property names 574 */ 575 public Enumeration getPropertyNames() { 576 return Collections.enumeration(_properties.keySet()); 577 } 578 579 /*** 580 * Sets the read-only state of the message 581 * 582 * @param readOnly if true, make the message body and properties read-only 583 * @throws JMSException if the read-only state cannot be changed 584 */ 585 public void setReadOnly(boolean readOnly) throws JMSException { 586 _propertiesReadOnly = readOnly; 587 _bodyReadOnly = readOnly; 588 } 589 590 /*** 591 * Determines if the message properties are read only 592 * 593 * @return <code>true</code> if the message properties are read only 594 */ 595 protected boolean getPropertiesReadOnly() { 596 return _propertiesReadOnly; 597 } 598 599 /*** 600 * Sets the read-only state of the message properties 601 * 602 * @param readOnly if <code>true</code>, make the message properties 603 * read-only 604 */ 605 protected void setPropertiesReadOnly(boolean readOnly) { 606 _propertiesReadOnly = readOnly; 607 } 608 609 /*** 610 * Determines if the message body is read only 611 * 612 * @return <code>true</code> if the message body is read only 613 */ 614 protected boolean getBodyReadOnly() { 615 return _bodyReadOnly; 616 } 617 618 /*** 619 * Sets the read-only state of the message body 620 * 621 * @param readOnly if <code>true</code>, make the message body 622 */ 623 protected void setBodyReadOnly(boolean readOnly) { 624 _bodyReadOnly = readOnly; 625 } 626 627 /*** 628 * Determines if properties may be set 629 * 630 * @throws MessageNotWriteableException if message is read-only 631 */ 632 protected void checkPropertyWrite() throws MessageNotWriteableException { 633 if (_propertiesReadOnly) { 634 throw new MessageNotWriteableException( 635 "Message in read-only mode"); 636 } 637 } 638 639 /*** 640 * Determines if the message body may be written 641 * 642 * @throws MessageNotWriteableException if the message is read-only 643 */ 644 protected void checkWrite() throws MessageNotWriteableException { 645 if (_bodyReadOnly) { 646 throw new MessageNotWriteableException( 647 "Message in read-only mode"); 648 } 649 } 650 651 /*** 652 * Determines if the message body may be read 653 * 654 * @throws MessageNotReadableException if the message is write-only 655 */ 656 protected void checkRead() throws MessageNotReadableException { 657 if (!_bodyReadOnly) { 658 throw new MessageNotReadableException( 659 "Message in write-only mode"); 660 } 661 } 662 663 }

This page was automatically generated by Maven