KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > jms > message > JMSMessage


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.jms.message;
8
9 import java.io.Serializable JavaDoc;
10 import java.util.Enumeration JavaDoc;
11 import javax.jms.Destination JavaDoc;
12 import javax.jms.JMSException JavaDoc;
13 import javax.jms.Message JavaDoc;
14 import javax.jms.MessageNotWriteableException JavaDoc;
15
16 import org.jfox.jms.JMSConsumer;
17 import org.jfox.jms.JMSSession;
18
19 /**
20  * <p/>
21  * This class implements the JMS Message. The message class is the underlying
22  * object for all the JMS message items. This message class provides the basic
23  * functionality for message processing including header items and properties.
24  * </p>
25  *
26  * @author <a HREF="mailto:founder_chen@yahoo.com.cn">Peter.Cheng</a>
27  * @version Revision: 1.1 Date: 2002-12-01 22:09:17
28  */

29
30 public class JMSMessage implements Message JavaDoc, Serializable JavaDoc, Comparable JavaDoc {
31
32     private MessageHeader messageHeader = new MessageHeader();
33     private MessageProperties messageProperties = new MessageProperties();
34
35     // true if message properties are modifiable, false if message properties
36
private boolean propertiesModifiable = true;
37
38     // true if message body is modifiable, false if message body is read-only
39
private boolean bodyModifiable = true;
40
41     /**
42      * 消息接收的session
43      */

44     private transient JMSSession session = null;
45     /**
46      * 消息接收的consumer
47      */

48     private transient JMSConsumer consumer = null;
49
50     public JMSMessage() {
51         try {
52             setJMSPriority(DEFAULT_PRIORITY);
53             setJMSDeliveryMode(DEFAULT_DELIVERY_MODE);
54         } catch (JMSException JavaDoc e) {
55         }
56
57         try {
58             clearProperties();
59         } catch (JMSException JavaDoc je) {
60         }
61         setBodyModifiable(true);
62     }
63
64     /**
65      * Gets the message ID.
66      *
67      * @return messageID
68      * @throws javax.jms.JMSException if the JMS provider fails to get the message ID due to
69      * some internal error.
70      * @see javax.jms.Message#setJMSMessageID(String)
71      * @see javax.jms.MessageProducer#setDisableMessageID(boolean)
72      */

73     public String JavaDoc getJMSMessageID() throws JMSException JavaDoc {
74         return messageHeader.getJMSMessageID();
75     }
76
77     /**
78      * Sets the message ID.
79      *
80      * @param id the ID of the message
81      * @throws javax.jms.JMSException if the JMS provider fails to set the message ID due to
82      * some internal error.
83      * @see javax.jms.Message#getJMSMessageID()
84      */

85     public void setJMSMessageID(String JavaDoc id) throws JMSException JavaDoc {
86         messageHeader.setJMSMessageID(id);
87     }
88
89     /**
90      * Gets the message timestamp.
91      *
92      * @return the message timestamp
93      * @throws javax.jms.JMSException if the JMS provider fails to get the timestamp due to
94      * some internal error.
95      * @see javax.jms.Message#setJMSTimestamp(long)
96      * @see javax.jms.MessageProducer#setDisableMessageTimestamp(boolean)
97      */

98     public long getJMSTimestamp() throws JMSException JavaDoc {
99         return messageHeader.getJMSTimestamp();
100     }
101
102     /**
103      * Sets the message timestamp.
104      * <p/>
105      * <P>
106      * JMS providers set this field when a message is sent. This method can be
107      * used to change the value for a message that has been received.
108      *
109      * @param timestamp the timestamp for this message
110      * @throws javax.jms.JMSException if the JMS provider fails to set the timestamp due to
111      * some internal error.
112      * @see javax.jms.Message#getJMSTimestamp()
113      */

114     public void setJMSTimestamp(long timestamp) throws JMSException JavaDoc {
115         messageHeader.setJMSTimestamp(timestamp);
116     }
117
118     /**
119      * Gets the correlation ID as an array of bytes for the message.
120      * <p/>
121      * <P>
122      * The use of a <CODE>byte[]</CODE> value for <CODE>JMSCorrelationID
123      * </CODE> is non-portable.
124      *
125      * @return the correlation ID of a message as an array of bytes
126      * @throws javax.jms.JMSException if the JMS provider fails to get the correlation ID due
127      * to some internal error.
128      * @see javax.jms.Message#setJMSCorrelationID(String)
129      * @see javax.jms.Message#getJMSCorrelationID()
130      * @see javax.jms.Message#setJMSCorrelationIDAsBytes(byte[])
131      */

132     public byte[] getJMSCorrelationIDAsBytes() throws JMSException JavaDoc {
133         return messageHeader.getJMSCorrelationIDAsBytes();
134     }
135
136     /**
137      * Sets the correlation ID as an array of bytes for the message.
138      * <p/>
139      * <P>
140      * The array is copied before the method returns, so future modifications
141      * to the array will not alter this message header.
142      * <p/>
143      * <P>
144      * The use of a <CODE>byte[]</CODE> value for <CODE>JMSCorrelationID
145      * </CODE> is non-portable.
146      *
147      * @param correlationID the correlation ID value as an array of bytes
148      * @throws javax.jms.JMSException if the JMS provider fails to set the correlation ID due
149      * to some internal error.
150      * @see javax.jms.Message#setJMSCorrelationID(String)
151      * @see javax.jms.Message#getJMSCorrelationID()
152      * @see javax.jms.Message#getJMSCorrelationIDAsBytes()
153      */

154     public void setJMSCorrelationIDAsBytes(byte[] correlationID)
155             throws JMSException JavaDoc {
156         messageHeader.setJMSCorrelationIDAsBytes(correlationID);
157     }
158
159     /**
160      * Gets the correlation ID for the message.
161      * <p/>
162      * <P>
163      * This method is used to return correlation ID values that are either
164      * provider-specific message IDs or application-specific <CODE>String
165      * </CODE> values.
166      *
167      * @return the correlation ID of a message as a <CODE>String</CODE>
168      * @throws javax.jms.JMSException if the JMS provider fails to get the correlation ID due
169      * to some internal error.
170      * @see javax.jms.Message#setJMSCorrelationID(String)
171      * @see javax.jms.Message#getJMSCorrelationIDAsBytes()
172      * @see javax.jms.Message#setJMSCorrelationIDAsBytes(byte[])
173      */

174     public String JavaDoc getJMSCorrelationID() throws JMSException JavaDoc {
175         return messageHeader.getJMSCorrelationID();
176     }
177
178     /**
179      * Sets the correlation ID for the message.
180      *
181      * @param correlationID the message ID of a message being referred to
182      * @throws javax.jms.JMSException if the JMS provider fails to set the correlation ID due
183      * to some internal error.
184      * @see javax.jms.Message#getJMSCorrelationID()
185      * @see javax.jms.Message#getJMSCorrelationIDAsBytes()
186      * @see javax.jms.Message#setJMSCorrelationIDAsBytes(byte[])
187      */

188     public void setJMSCorrelationID(String JavaDoc correlationID) throws JMSException JavaDoc {
189         messageHeader.setJMSCorrelationID(correlationID);
190     }
191
192     /**
193      * Gets the <CODE>Destination</CODE> object to which a reply to this
194      * message should be sent.
195      *
196      * @return <CODE>Destination</CODE> to which to send a response to this
197      * message
198      * @throws javax.jms.JMSException if the JMS provider fails to get the <CODE>JMSReplyTo
199      * </CODE> destination due to some internal error.
200      * @see javax.jms.Message#setJMSReplyTo(javax.jms.Destination)
201      */

202     public Destination JavaDoc getJMSReplyTo() throws JMSException JavaDoc {
203         return messageHeader.getJMSReplyTo();
204     }
205
206     /**
207      * Sets the <CODE>Destination</CODE> object to which a reply to this
208      * message should be sent.
209      *
210      * @param replyTo <CODE>Destination</CODE> to which to send a response to
211      * this message
212      * @throws javax.jms.JMSException if the JMS provider fails to set the <CODE>JMSReplyTo
213      * </CODE> destination due to some internal error.
214      * @see javax.jms.Message#getJMSReplyTo()
215      */

216     public void setJMSReplyTo(Destination JavaDoc replyTo) throws JMSException JavaDoc {
217         messageHeader.setJMSReplyTo(replyTo);
218     }
219
220     /**
221      * Gets the <CODE>Destination</CODE> object for this message.
222      *
223      * @return the destination of this message
224      * @throws javax.jms.JMSException if the JMS provider fails to get the destination due to
225      * some internal error.
226      * @see javax.jms.Message#setJMSDestination(javax.jms.Destination)
227      */

228     public Destination JavaDoc getJMSDestination() throws JMSException JavaDoc {
229         return messageHeader.getJMSDestination();
230     }
231
232     /**
233      * Sets the <CODE>Destination</CODE> object for this message.
234      * <p/>
235      * <P>
236      * JMS providers set this field when a message is sent. This method can be
237      * used to change the value for a message that has been received.
238      *
239      * @param destination the destination for this message
240      * @throws javax.jms.JMSException if the JMS provider fails to set the destination due to
241      * some internal error.
242      * @see javax.jms.Message#getJMSDestination()
243      */

244     public void setJMSDestination(Destination JavaDoc destination)
245             throws JMSException JavaDoc {
246         messageHeader.setJMSDestination(destination);
247     }
248
249     /**
250      * Gets the <CODE>DeliveryMode</CODE> value specified for this message.
251      *
252      * @return the delivery mode for this message
253      * @throws javax.jms.JMSException if the JMS provider fails to get the delivery mode due to
254      * some internal error.
255      * @see javax.jms.Message#setJMSDeliveryMode(int)
256      * @see javax.jms.DeliveryMode
257      */

258     public int getJMSDeliveryMode() throws JMSException JavaDoc {
259         return messageHeader.getJMSDeliveryMode();
260     }
261
262     /**
263      * Sets the <CODE>DeliveryMode</CODE> value for this message.
264      * <p/>
265      * <P>
266      * JMS providers set this field when a message is sent. This method can be
267      * used to change the value for a message that has been received.
268      *
269      * @param deliveryMode the delivery mode for this message
270      * @throws javax.jms.JMSException if the JMS provider fails to set the delivery mode due to
271      * some internal error.
272      * @see javax.jms.Message#getJMSDeliveryMode()
273      * @see javax.jms.DeliveryMode
274      */

275     public void setJMSDeliveryMode(int deliveryMode) throws JMSException JavaDoc {
276         messageHeader.setJMSDeliveryMode(deliveryMode);
277     }
278
279     /**
280      * Gets an indication of whether this message is being redelivered.
281      * <p/>
282      * <P>
283      * If a client receives a message with the <CODE>JMSRedelivered</CODE>
284      * field set, it is likely, but not guaranteed, that this message was
285      * delivered earlier but that its receipt was not acknowledged at that
286      * time.
287      *
288      * @return true if this message is being redelivered
289      * @throws javax.jms.JMSException if the JMS provider fails to get the redelivered state
290      * due to some internal error.
291      * @see javax.jms.Message#setJMSRedelivered(boolean)
292      */

293     public boolean getJMSRedelivered() throws JMSException JavaDoc {
294         return messageHeader.getJMSRedelivered();
295     }
296
297     /**
298      * Specifies whether this message is being redelivered.
299      * <p/>
300      * <P>
301      * This field is set at the time the message is delivered. This method can
302      * be used to change the value for a message that has been received.
303      *
304      * @param redelivered an indication of whether this message is being redelivered
305      * @throws javax.jms.JMSException if the JMS provider fails to set the redelivered state
306      * due to some internal error.
307      * @see javax.jms.Message#getJMSRedelivered()
308      */

309     public void setJMSRedelivered(boolean redelivered) throws JMSException JavaDoc {
310         messageHeader.setJMSRedelivered(redelivered);
311     }
312
313     /**
314      * Gets the message type identifier supplied by the client when the message
315      * was sent.
316      *
317      * @return the message type
318      * @throws javax.jms.JMSException if the JMS provider fails to get the message type due to
319      * some internal error.
320      * @see javax.jms.Message#setJMSType(String)
321      */

322     public String JavaDoc getJMSType() throws JMSException JavaDoc {
323         return messageHeader.getJMSType();
324     }
325
326     /**
327      * Sets the message type.
328      *
329      * @param type the message type
330      * @throws javax.jms.JMSException if the JMS provider fails to set the message type due to
331      * some internal error.
332      * @see javax.jms.Message#getJMSType()
333      */

334     public void setJMSType(String JavaDoc type) throws JMSException JavaDoc {
335         messageHeader.setJMSType(type);
336     }
337
338     /**
339      * Gets the message's expiration value.
340      *
341      * @return the time the message expires, which is the sum of the
342      * time-to-live value specified by the client and the GMT at the
343      * time of the send
344      * @throws javax.jms.JMSException if the JMS provider fails to get the message expiration
345      * due to some internal error.
346      * @see javax.jms.Message#setJMSExpiration(long)
347      */

348     public long getJMSExpiration() throws JMSException JavaDoc {
349         return messageHeader.getJMSExpiration();
350     }
351
352     /**
353      * Sets the message's expiration value.
354      * <p/>
355      * <P>
356      * JMS providers set this field when a message is sent. This method can be
357      * used to change the value for a message that has been received.
358      *
359      * @param expiration the message's expiration time
360      * @throws javax.jms.JMSException if the JMS provider fails to set the message expiration
361      * due to some internal error.
362      * @see javax.jms.Message#getJMSExpiration()
363      */

364     public void setJMSExpiration(long expiration) throws JMSException JavaDoc {
365         messageHeader.setJMSExpiration(expiration);
366     }
367
368     /**
369      * Gets the message defaultPriority level.
370      * <p/>
371      * <P>
372      * The JMS API defines ten levels of defaultPriority value, with 0 as the
373      * lowest defaultPriority and 9 as the highest. In addition, clients should
374      * consider priorities 0-4 as gradations of normal defaultPriority and
375      * priorities 5-9 as gradations of expedited defaultPriority.
376      *
377      * @return the default message defaultPriority
378      * @throws javax.jms.JMSException if the JMS provider fails to get the message
379      * defaultPriority due to some internal error.
380      * @see javax.jms.Message#setJMSPriority(int)
381      */

382     public int getJMSPriority() throws JMSException JavaDoc {
383         return messageHeader.getJMSPriority();
384     }
385
386     /**
387      * Sets the defaultPriority level for this message.
388      * <p/>
389      * <P>
390      * JMS providers set this field when a message is sent. This method can be
391      * used to change the value for a message that has been received.
392      *
393      * @param priority the defaultPriority of this message
394      * @throws javax.jms.JMSException if the JMS provider fails to set the message
395      * defaultPriority due to some internal error.
396      * @see javax.jms.Message#getJMSPriority()
397      */

398     public void setJMSPriority(int priority) throws JMSException JavaDoc {
399         messageHeader.setJMSPriority(priority);
400     }
401
402     /**
403      * Clears a message's properties.
404      *
405      * @throws javax.jms.JMSException if an error occurs while clearing the properties.
406      * @see javax.jms.Message#clearProperties()
407      */

408     public void clearProperties() throws JMSException JavaDoc {
409         messageProperties.clearProperties();
410         propertiesModifiable = true;
411         bodyModifiable = true;
412     }
413
414     /**
415      * Indicates whether a property value exists.
416      *
417      * @throws javax.jms.JMSException if an error occurs while clearing the properties.
418      * @see javax.jms.Message#propertyExists(String)
419      */

420     public boolean propertyExists(String JavaDoc name) throws JMSException JavaDoc {
421         return messageProperties.propertyExists(name);
422     }
423
424     /**
425      * Returns the value of the <CODE>boolean</CODE> property with the
426      * specified name.
427      *
428      * @param name the name of the <CODE>boolean</CODE> property
429      * @return the <CODE>boolean</CODE> property value for the specified name
430      * @throws javax.jms.JMSException if the JMS provider fails to get the property value due
431      * to some internal error.
432      * @throws javax.jms.MessageFormatException
433      * if this type conversion is invalid.
434      */

435     public boolean getBooleanProperty(String JavaDoc name) throws JMSException JavaDoc {
436         return messageProperties.getBooleanProperty(name);
437     }
438
439     /**
440      * Returns the value of the <CODE>byte</CODE> property with the specified
441      * name.
442      *
443      * @param name the name of the <CODE>byte</CODE> property
444      * @return the <CODE>byte</CODE> property value for the specified name
445      * @throws javax.jms.JMSException if the JMS provider fails to get the property value due
446      * to some internal error.
447      * @throws javax.jms.MessageFormatException
448      * if this type conversion is invalid.
449      */

450     public byte getByteProperty(String JavaDoc name) throws JMSException JavaDoc {
451         return messageProperties.getByteProperty(name);
452     }
453
454     /**
455      * Returns the value of the <CODE>short</CODE> property with the
456      * specified name.
457      *
458      * @param name the name of the <CODE>short</CODE> property
459      * @return the <CODE>short</CODE> property value for the specified name
460      * @throws javax.jms.JMSException if the JMS provider fails to get the property value due
461      * to some internal error.
462      * @throws javax.jms.MessageFormatException
463      * if this type conversion is invalid.
464      */

465     public short getShortProperty(String JavaDoc name) throws JMSException JavaDoc {
466         return messageProperties.getShortProperty(name);
467     }
468
469     /**
470      * Returns the value of the <CODE>int</CODE> property with the specified
471      * name.
472      *
473      * @param name the name of the <CODE>int</CODE> property
474      * @return the <CODE>int</CODE> property value for the specified name
475      * @throws javax.jms.JMSException if the JMS provider fails to get the property value due
476      * to some internal error.
477      * @throws javax.jms.MessageFormatException
478      * if this type conversion is invalid.
479      */

480     public int getIntProperty(String JavaDoc name) throws JMSException JavaDoc {
481         return messageProperties.getIntProperty(name);
482     }
483
484     /**
485      * Returns the value of the <CODE>long</CODE> property with the specified
486      * name.
487      *
488      * @param name the name of the <CODE>long</CODE> property
489      * @return the <CODE>long</CODE> property value for the specified name
490      * @throws javax.jms.JMSException if the JMS provider fails to get the property value due
491      * to some internal error.
492      * @throws javax.jms.MessageFormatException
493      * if this type conversion is invalid.
494      */

495     public long getLongProperty(String JavaDoc name) throws JMSException JavaDoc {
496         return messageProperties.getLongProperty(name);
497     }
498
499     /**
500      * Returns the value of the <CODE>float</CODE> property with the
501      * specified name.
502      *
503      * @param name the name of the <CODE>float</CODE> property
504      * @return the <CODE>float</CODE> property value for the specified name
505      * @throws javax.jms.JMSException if the JMS provider fails to get the property value due
506      * to some internal error.
507      * @throws javax.jms.MessageFormatException
508      * if this type conversion is invalid.
509      */

510     public float getFloatProperty(String JavaDoc name) throws JMSException JavaDoc {
511         return messageProperties.getFloatProperty(name);
512     }
513
514     /**
515      * Returns the value of the <CODE>double</CODE> property with the
516      * specified name.
517      *
518      * @param name the name of the <CODE>double</CODE> property
519      * @return the <CODE>double</CODE> property value for the specified name
520      * @throws javax.jms.JMSException if the JMS provider fails to get the property value due
521      * to some internal error.
522      * @throws javax.jms.MessageFormatException
523      * if this type conversion is invalid.
524      */

525     public double getDoubleProperty(String JavaDoc name) throws JMSException JavaDoc {
526         return messageProperties.getDoubleProperty(name);
527     }
528
529     /**
530      * Returns the value of the <CODE>String</CODE> property with the
531      * specified name.
532      *
533      * @param name the name of the <CODE>String</CODE> property
534      * @return the <CODE>String</CODE> property value for the specified name;
535      * if there is no property by this name, a null value is returned
536      * @throws javax.jms.JMSException if the JMS provider fails to get the property value due
537      * to some internal error.
538      * @throws javax.jms.MessageFormatException
539      * if this type conversion is invalid.
540      */

541     public String JavaDoc getStringProperty(String JavaDoc name) throws JMSException JavaDoc {
542         return messageProperties.getStringProperty(name);
543     }
544
545     /**
546      * Returns the value of the Java object property with the specified name.
547      * <p/>
548      * <P>
549      * This method can be used to return, in objectified format, an object that
550      * has been stored as a property in the message with the equivalent <CODE>
551      * setObjectProperty</CODE> method call, or its equivalent primitive
552      * <CODE>set <I>type</I> Property</CODE> method.
553      *
554      * @param name the name of the Java object property
555      * @return the Java object property value with the specified name, in
556      * objectified format (for example, if the property was set as an
557      * <CODE>int</CODE>, an <CODE>Integer</CODE> is returned); if
558      * there is no property by this name, a null value is returned
559      * @throws javax.jms.JMSException if the JMS provider fails to get the property value due
560      * to some internal error.
561      */

562     public Object JavaDoc getObjectProperty(String JavaDoc name) throws JMSException JavaDoc {
563         return messageProperties.getObjectProperty(name);
564     }
565
566     /**
567      * Returns an <CODE>Enumeration</CODE> of all the property names.
568      * <p/>
569      * <P>
570      * Note that JMS standard header fields are not considered properties and
571      * are not returned in this enumeration.
572      *
573      * @return an enumeration of all the names of property values
574      * @throws javax.jms.JMSException if the JMS provider fails to get the property names due
575      * to some internal error.
576      */

577     public Enumeration JavaDoc getPropertyNames() throws JMSException JavaDoc {
578         return messageProperties.getPropertyNames();
579     }
580
581     /**
582      * Sets a <CODE>boolean</CODE> property value with the specified name
583      * into the message.
584      *
585      * @param name the name of the <CODE>boolean</CODE> property
586      * @param value the <CODE>boolean</CODE> property value to set
587      * @throws javax.jms.JMSException if the JMS provider fails to set the property due to some
588      * internal error.
589      * @throws javax.jms.MessageNotWriteableException
590      * if properties are read-only
591      */

592     public void setBooleanProperty(String JavaDoc name, boolean value)
593             throws JMSException JavaDoc {
594         if (isPropertiesModifiable()) {
595             messageProperties.setBooleanProperty(name, value);
596         } else {
597             throw new MessageNotWriteableException JavaDoc("Message boolean property is read-only");
598         }
599     }
600
601     /**
602      * Sets a <CODE>byte</CODE> property value with the specified name into
603      * the message.
604      *
605      * @param name the name of the <CODE>byte</CODE> property
606      * @param value the <CODE>byte</CODE> property value to set
607      * @throws javax.jms.JMSException if the JMS provider fails to set the property due to some
608      * internal error.
609      * @throws javax.jms.MessageNotWriteableException
610      * if properties are read-only
611      */

612     public void setByteProperty(String JavaDoc name, byte value) throws JMSException JavaDoc {
613         if (isPropertiesModifiable()) {
614             messageProperties.setByteProperty(name, value);
615         } else {
616             throw new MessageNotWriteableException JavaDoc("Message byte property is read-only");
617         }
618     }
619
620     /**
621      * Sets a <CODE>short</CODE> property value with the specified name into
622      * the message.
623      *
624      * @param name the name of the <CODE>short</CODE> property
625      * @param value the <CODE>short</CODE> property value to set
626      * @throws javax.jms.JMSException if the JMS provider fails to set the property due to some
627      * internal error.
628      * @throws javax.jms.MessageNotWriteableException
629      * if properties are read-only
630      */

631     public void setShortProperty(String JavaDoc name, short value)
632             throws JMSException JavaDoc {
633         if (isPropertiesModifiable()) {
634             messageProperties.setShortProperty(name, value);
635         } else {
636             throw new MessageNotWriteableException JavaDoc("Message short property is read-only");
637         }
638     }
639
640     /**
641      * Sets an <CODE>int</CODE> property value with the specified name into
642      * the message.
643      *
644      * @param name the name of the <CODE>int</CODE> property
645      * @param value the <CODE>int</CODE> property value to set
646      * @throws javax.jms.JMSException if the JMS provider fails to set the property due to some
647      * internal error.
648      * @throws javax.jms.MessageNotWriteableException
649      * if properties are read-only
650      */

651     public void setIntProperty(String JavaDoc name, int value) throws JMSException JavaDoc {
652         if (isPropertiesModifiable()) {
653             messageProperties.setIntProperty(name, value);
654         } else {
655             throw new MessageNotWriteableException JavaDoc("Message int property is read-only");
656         }
657     }
658
659     /**
660      * Sets a <CODE>long</CODE> property value with the specified name into
661      * the message.
662      *
663      * @param name the name of the <CODE>long</CODE> property
664      * @param value the <CODE>long</CODE> property value to set
665      * @throws javax.jms.JMSException if the JMS provider fails to set the property due to some
666      * internal error.
667      * @throws javax.jms.MessageNotWriteableException
668      * if properties are read-only
669      */

670     public void setLongProperty(String JavaDoc name, long value) throws JMSException JavaDoc {
671         if (isPropertiesModifiable()) {
672             messageProperties.setLongProperty(name, value);
673         } else {
674             throw new MessageNotWriteableException JavaDoc("Message long property is read-only");
675         }
676     }
677
678     /**
679      * Sets a <CODE>float</CODE> property value with the specified name into
680      * the message.
681      *
682      * @param name the name of the <CODE>float</CODE> property
683      * @param value the <CODE>float</CODE> property value to set
684      * @throws javax.jms.JMSException if the JMS provider fails to set the property due to some
685      * internal error.
686      * @throws javax.jms.MessageNotWriteableException
687      * if properties are read-only
688      */

689     public void setFloatProperty(String JavaDoc name, float value)
690             throws JMSException JavaDoc {
691         if (isPropertiesModifiable()) {
692             messageProperties.setFloatProperty(name, value);
693         } else {
694             throw new MessageNotWriteableException JavaDoc("Message float property is read-only");
695         }
696     }
697
698     /**
699      * Sets a <CODE>double</CODE> property value with the specified name into
700      * the message.
701      *
702      * @param name the name of the <CODE>double</CODE> property
703      * @param value the <CODE>double</CODE> property value to set
704      * @throws javax.jms.JMSException if the JMS provider fails to set the property due to some
705      * internal error.
706      * @throws javax.jms.MessageNotWriteableException
707      * if properties are read-only
708      */

709     public void setDoubleProperty(String JavaDoc name, double value)
710             throws JMSException JavaDoc {
711         if (isPropertiesModifiable()) {
712             messageProperties.setDoubleProperty(name, value);
713         } else {
714             throw new MessageNotWriteableException JavaDoc("Message double property is read-only");
715         }
716     }
717
718     /**
719      * Sets a <CODE>String</CODE> property value with the specified name into
720      * the message.
721      *
722      * @param name the name of the <CODE>String</CODE> property
723      * @param value the <CODE>String</CODE> property value to set
724      * @throws javax.jms.JMSException if the JMS provider fails to set the property due to some
725      * internal error.
726      * @throws javax.jms.MessageNotWriteableException
727      * if properties are read-only
728      */

729     public void setStringProperty(String JavaDoc name, String JavaDoc value)
730             throws JMSException JavaDoc {
731         if (isPropertiesModifiable()) {
732             messageProperties.setStringProperty(name, value);
733         } else {
734             throw new MessageNotWriteableException JavaDoc("Message string property is read-only");
735         }
736     }
737
738     /**
739      * Sets a Java object property value with the specified name into the
740      * message.
741      * <p/>
742      * <P>
743      * Note that this method works only for the objectified primitive object
744      * types (<CODE>Integer</CODE>,<CODE>Double</CODE>,<CODE>Long
745      * </CODE> ...) and <CODE>String</CODE> objects.
746      *
747      * @param name the name of the Java object property
748      * @param value the Java object property value to set
749      * @throws javax.jms.JMSException if the JMS provider fails to set the property due to some
750      * internal error.
751      * @throws javax.jms.MessageFormatException
752      * if the object is invalid
753      * @throws javax.jms.MessageNotWriteableException
754      * if properties are read-only
755      */

756     public void setObjectProperty(String JavaDoc name, Object JavaDoc value)
757             throws JMSException JavaDoc {
758         if (isPropertiesModifiable()) {
759             messageProperties.setObjectProperty(name, value);
760         } else {
761             throw new MessageNotWriteableException JavaDoc("Message object property is read-only");
762         }
763     }
764
765     /**
766      * @see javax.jms.Message#acknowledge()
767      */

768     public void acknowledge() throws JMSException JavaDoc {
769         if (session == null || consumer == null) {
770             throw new JMSException JavaDoc("message not delivered.");
771         }
772         session.acknowledge(consumer, this);
773     }
774
775     /**
776      * Clears out the message body. Clearing a message's body does not clear
777      * its header values or property entries.
778      * <p/>
779      * <P>
780      * If this message body was read-only, calling this method leaves the
781      * message body in the same state as an empty body in a newly created
782      * message.
783      *
784      * @throws javax.jms.JMSException if the JMS provider fails to clear the message body due
785      * to some internal error.
786      */

787     public void clearBody() throws JMSException JavaDoc {
788         setBodyModifiable(true);
789     }
790
791     /**
792      * Set the read only state of the message properties.
793      *
794      * @param state false if the message properties are read-only, true if the
795      * message properties can be modified.
796      */

797     public void setPropertiesModifiable(boolean state) {
798         propertiesModifiable = state;
799     }
800
801     /**
802      * Return true if the message properties are modifiable, else it is in
803      * read-only mode.
804      *
805      * @return true if message properties can be modified, false if not
806      */

807     public boolean isPropertiesModifiable() {
808         return propertiesModifiable;
809     }
810
811     /**
812      * Set the read only state of teh message body.
813      *
814      * @param state false if the message body are read-only, true if the message
815      * body can be modified.
816      */

817     public void setBodyModifiable(boolean state) {
818         bodyModifiable = state;
819     }
820
821     /**
822      * Return true if the message body is modifiable, else it is in read-only
823      * mode.
824      *
825      * @return true if message body can be modified, false if not
826      */

827     public boolean isBodyModifiable() {
828         return bodyModifiable;
829     }
830
831     public int compareTo(Object JavaDoc pObject) {
832         if (pObject == null || !(pObject instanceof Message JavaDoc)) return 0;
833         try {
834             return this.getJMSPriority() - ((Message JavaDoc) pObject).getJMSPriority();
835         } catch (Exception JavaDoc 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