KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > kjoram > messages > Message


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Frederic Maistre (INRIA)
22  * Contributor(s): Nicolas Tachker (ScalAgent)
23  */

24 package com.scalagent.kjoram.messages;
25
26 import com.scalagent.kjoram.excepts.*;
27
28 import java.io.*;
29 import java.util.*;
30
31 /**
32  * The <code>Message</code> class actually provides the transport facility
33  * for the data exchanged during MOM operations.
34  * <p>
35  * A message may either carry a String, or a serializable object, or an
36  * hashtable, or bytes, even nothing. It is charaterized by properties and
37  * "header" fields.
38  */

39 public class Message {
40   /** The message type (SIMPLE, TEXT, MAP, BYTES). */
41   int type;
42
43   /** <code>true</code> if the message must be persisted. **/
44   boolean persistent = true;
45
46   /** The message identifier. */
47   String JavaDoc id = null;
48   /** The message priority (from 0 to 9, 9 being the highest). */
49   int priority = 4;
50   /** The message expiration time (0 for infinite time-to-live). */
51   long expiration = 0;
52   /** The message time stamp. */
53   long timestamp;
54   /** The message destination identifier. */
55   String JavaDoc toId = null;
56   /** <code>true</code> if the message destination is a queue. */
57   boolean toQueue;
58   /** The correlation identifier field. */
59   String JavaDoc correlationId = null;
60   /** The reply to destination identifier. */
61   String JavaDoc replyToId = null;
62   /** <code>true</code> if the "reply to" destination is a queue. */
63   boolean replyToQueue;
64
65   /**
66    * Table holding header fields that may be required by particular
67    * clients (such as JMS clients).
68    */

69   Hashtable optionalHeader = null;
70
71   /** The bytes body. */
72   byte[] body_bytes = null;
73   /** The map body. */
74   Hashtable body_map = null;
75   /** The text body. */
76   String JavaDoc body_text = null;
77   /** <code>true</code> if the body is read-only. */
78   boolean bodyRO = false;
79
80   /** The message properties table. */
81   Hashtable properties = null;
82   /** <code>true</code> if the properties are read-only. */
83   boolean propertiesRO = false;
84
85   /** The number of delivery attempts for this message. */
86   public int deliveryCount = 0;
87   /**
88    * <code>true</code> if the message has been denied at least once by a
89    * consumer.
90    */

91   public boolean denied = false;
92
93   /** <code>true</code> if the message target destination is deleted. */
94   public boolean deletedDest = false;
95   /** <code>true</code> if the message expired. */
96   public boolean expired = false;
97   /** <code>true</code> if the message could not be written on the dest. */
98   public boolean notWriteable = false;
99   /** <code>true</code> if the message is considered as undeliverable. */
100   public boolean undeliverable = false;
101   
102   /**
103    * The number of acknowledgements a message still expects from its
104    * subscribers before having been fully consumed by them (field used
105    * by JMS proxies).
106    */

107   public transient int acksCounter;
108   /**
109    * The number of acknowledgements a message still expects from its
110    * durable subscribers before having been fully consumed by them (field used
111    * by JMS proxies).
112    */

113   public transient int durableAcksCounter;
114
115   /**
116    * Constructs a <code>Message</code> instance.
117    */

118   public Message()
119   {
120     this.type = MessageType.SIMPLE;
121   }
122
123   
124   /** Sets the message identifier. */
125   public void setIdentifier(String JavaDoc id)
126   {
127     this.id = id;
128   }
129
130   /** Sets the message persistence mode. */
131   public void setPersistent(boolean persistent)
132   {
133     this.persistent = persistent;
134   }
135
136   /**
137    * Sets the message priority.
138    *
139    * @param priority Priority value: 0 the lowest, 9 the highest, 4 normal.
140    */

141   public void setPriority(int priority)
142   {
143     if (priority >= 0 && priority <= 9)
144       this.priority = priority;
145   }
146
147   /** Sets the message expiration. */
148   public void setExpiration(long expiration)
149   {
150     if (expiration >= 0)
151       this.expiration = expiration;
152   }
153
154   /** Sets the message time stamp. */
155   public void setTimestamp(long timestamp)
156   {
157     this.timestamp = timestamp;
158   }
159
160   /**
161    * Sets the message destination.
162    *
163    * @param id The destination identifier.
164    * @param queue <code>true</code> if the destination is a queue.
165    */

166   public void setDestination(String JavaDoc id, boolean queue)
167   {
168     this.toId = id;
169     this.toQueue = queue;
170   }
171
172   /** Sets the message correlation identifier. */
173   public void setCorrelationId(String JavaDoc correlationId)
174   {
175     this.correlationId = correlationId;
176   }
177
178   /**
179    * Sets the destination to which a reply should be sent.
180    *
181    * @param id The destination identifier.
182    * @param queue <code>true</code> if the destination is a queue.
183    */

184   public void setReplyTo(String JavaDoc id, boolean queue)
185   {
186     this.replyToId = id;
187     this.replyToQueue = queue;
188   }
189
190   /**
191    * Sets an optional header field value.
192    *
193    * @param name The header field name.
194    * @param value The corresponding value.
195    */

196   public void setOptionalHeader(String JavaDoc name, Object JavaDoc value)
197   {
198     if (name == null || name.equals(""))
199       throw new IllegalArgumentException JavaDoc("Invalid header name: " + name);
200
201     if (value == null)
202       return;
203
204     if (optionalHeader == null)
205       optionalHeader = new Hashtable();
206
207     optionalHeader.put(name, value);
208   }
209
210   /** Returns the message type. */
211   public int getType()
212   {
213     return type;
214   }
215
216   /** Returns the message identifier. */
217   public String JavaDoc getIdentifier()
218   {
219     return id;
220   }
221
222   /** Returns <code>true</code> if the message is persistent. */
223   public boolean getPersistent()
224   {
225     return persistent;
226   }
227
228   /** Returns the message priority. */
229   public int getPriority()
230   {
231     return priority;
232   }
233
234   /** Returns the message expiration time. */
235   public long getExpiration()
236   {
237     return expiration;
238   }
239   
240   /** Returns the message time stamp. */
241   public long getTimestamp()
242   {
243     return timestamp;
244   }
245
246   /** Returns the message destination identifier. */
247   public String JavaDoc getDestinationId()
248   {
249     return toId;
250   }
251
252   /** Returns <code>true</code> if the destination is a queue. */
253   public boolean toQueue()
254   {
255     return toQueue;
256   }
257
258   /** Returns the message correlation identifier. */
259   public String JavaDoc getCorrelationId()
260   {
261     return correlationId;
262   }
263
264   /** Returns the destination id the reply should be sent to. */
265   public String JavaDoc getReplyToId()
266   {
267     return replyToId;
268   }
269
270   /** Returns <code>true</code> if the reply to destination is a queue. */
271   public boolean replyToQueue()
272   {
273     return replyToQueue;
274   }
275
276   /**
277    * Returns an optional header field value.
278    *
279    * @param name The header field name.
280    */

281   public Object JavaDoc getOptionalHeader(String JavaDoc name)
282   {
283     if (optionalHeader == null)
284       return null;
285
286     return optionalHeader.get(name);
287   }
288
289   /**
290    * Sets a property as a boolean value.
291    *
292    * @param name The property name.
293    * @param value The property value.
294    *
295    * @exception MessageROException If the message properties are read-only.
296    */

297   public void setBooleanProperty(String JavaDoc name, boolean value)
298          throws MessageROException
299   {
300     preparePropSetting(name);
301     properties.put(name, new Boolean JavaDoc(value));
302   }
303
304   /**
305    * Sets a property as a byte value.
306    *
307    * @param name The property name.
308    * @param value The property value.
309    *
310    * @exception MessageROException If the message properties are read-only.
311    */

312   public void setByteProperty(String JavaDoc name, byte value)
313          throws MessageROException
314   {
315     preparePropSetting(name);
316     properties.put(name, new Byte JavaDoc(value));
317   }
318
319   /**
320    * Sets a property as a double value.
321    *
322    * @param name The property name.
323    * @param value The property value.
324    *
325    * @exception MessageROException If the message properties are read-only.
326    */

327 // public void setDoubleProperty(String name, double value)
328
// throws MessageROException
329
// {
330
// preparePropSetting(name);
331
// properties.put(name, new Double(value));
332
// }
333

334   /**
335    * Sets a property as a float value.
336    *
337    * @param name The property name.
338    * @param value The property value.
339    *
340    * @exception MessageROException If the message properties are read-only.
341    */

342 // public void setFloatProperty(String name, float value)
343
// throws MessageROException
344
// {
345
// preparePropSetting(name);
346
// properties.put(name, new Float(value));
347
// }
348

349   /**
350    * Sets a property as an int value.
351    *
352    * @param name The property name.
353    * @param value The property value.
354    *
355    * @exception MessageROException If the message properties are read-only.
356    */

357   public void setIntProperty(String JavaDoc name, int value) throws MessageROException
358   {
359     preparePropSetting(name);
360     properties.put(name, new Integer JavaDoc(value));
361   }
362
363   /**
364    * Sets a property as a long value.
365    *
366    * @param name The property name.
367    * @param value The property value.
368    *
369    * @exception MessageROException If the message properties are read-only.
370    */

371   public void setLongProperty(String JavaDoc name, long value)
372          throws MessageROException
373   {
374     preparePropSetting(name);
375     properties.put(name, new Long JavaDoc(value));
376   }
377
378   /**
379    * Sets a property value.
380    *
381    * @param name The property name.
382    * @param value The property value.
383    *
384    * @exception MessageROException If the message properties are read-only.
385    * @exception MessageValueException If the value is not a Java primitive
386    * object.
387    */

388   public void setObjectProperty(String JavaDoc name, Object JavaDoc value)
389          throws MessageException
390   {
391     preparePropSetting(name);
392
393     if (value instanceof Boolean JavaDoc
394         || value instanceof String JavaDoc
395         || value instanceof Integer JavaDoc
396         || value instanceof Long JavaDoc
397         || value instanceof Short JavaDoc
398         || value instanceof Byte JavaDoc)
399       properties.put(name, value);
400
401     else
402       throw new MessageValueException("Can't set non primitive Java object"
403                                       + " as a property value.");
404   }
405
406   /**
407    * Sets a property as a short value.
408    *
409    * @param name The property name.
410    * @param value The property value.
411    *
412    * @exception MessageROException If the message properties are read-only.
413    */

414   public void setShortProperty(String JavaDoc name, short value)
415          throws MessageROException
416   {
417     preparePropSetting(name);
418     properties.put(name, new Short JavaDoc(value));
419   }
420
421   /**
422    * Sets a property as a String.
423    *
424    * @param name The property name.
425    * @param value The property value.
426    *
427    * @exception MessageROException If the message properties are read-only.
428    */

429   public void setStringProperty(String JavaDoc name, String JavaDoc value)
430          throws MessageROException
431   {
432     preparePropSetting(name);
433     properties.put(name, new String JavaDoc(value));
434   }
435
436   /**
437    * Returns a property as a boolean value.
438    *
439    * @exception MessageValueException If the property type is invalid.
440    */

441   public boolean getBooleanProperty(String JavaDoc name) throws MessageValueException
442   {
443     if (properties == null)
444       throw new RuntimeException JavaDoc("getBooleanProperty properties = null");
445     return ConversionHelper.toBoolean(properties.get(name));
446   }
447   
448   /**
449    *
450    * @exception MessageValueException If the property type is invalid.
451    */

452   public byte getByteProperty(String JavaDoc name) throws MessageValueException
453   {
454     if (properties == null)
455     throw new RuntimeException JavaDoc("getByteProperty properties = null");
456     return ConversionHelper.toByte(properties.get(name));
457   }
458
459   /**
460    * Returns a property as a double value.
461    *
462    * @param name The property name.
463    *
464    * @exception MessageValueException If the property type is invalid.
465    */

466 // public double getDoubleProperty(String name) throws MessageValueException
467
// {
468
// if (properties == null)
469
// return Double.valueOf(null).doubleValue();
470
// return ConversionHelper.toDouble(properties.get(name));
471
// }
472

473   /**
474    * Returns a property as a float value.
475    *
476    * @param name The property name.
477    *
478    * @exception MessageValueException If the property type is invalid.
479    */

480 // public float getFloatProperty(String name) throws MessageValueException
481
// {
482
// if (properties == null)
483
// return Float.valueOf(null).floatValue();
484
// return ConversionHelper.toFloat(properties.get(name));
485
// }
486

487   /**
488    * Returns a property as a int value.
489    *
490    * @param name The property name.
491    *
492    * @exception MessageValueException If the property type is invalid.
493    */

494   public int getIntProperty(String JavaDoc name) throws MessageValueException
495   {
496     if (properties == null)
497       return Integer.valueOf(null).intValue();
498     return ConversionHelper.toInt(properties.get(name));
499   }
500
501   /**
502    * Returns a property as a long value.
503    *
504    * @param name The property name.
505    *
506    * @exception MessageValueException If the property type is invalid.
507    */

508   public long getLongProperty(String JavaDoc name) throws MessageValueException
509   {
510     if (properties == null)
511       throw new RuntimeException JavaDoc("getLongProperty properties = null");
512     return ConversionHelper.toLong(properties.get(name));
513   }
514
515   /**
516    * Returns a property as an object.
517    *
518    * @param name The property name.
519    */

520   public Object JavaDoc getObjectProperty(String JavaDoc name)
521   {
522     if (properties == null)
523       return null;
524     return properties.get(name);
525   }
526
527   /**
528    * Returns a property as a short value.
529    *
530    * @param name The property name.
531    *
532    * @exception MessageValueException If the property type is invalid.
533    */

534   public short getShortProperty(String JavaDoc name) throws MessageValueException
535   {
536     if (properties == null)
537       throw new RuntimeException JavaDoc("getShortProperty properties = null");
538     return ConversionHelper.toShort(properties.get(name));
539   }
540
541   /**
542    * Returns a property as a String.
543    *
544    * @param name The property name.
545    */

546   public String JavaDoc getStringProperty(String JavaDoc name)
547   {
548     if (properties == null)
549       return null;
550     return ConversionHelper.toString(properties.get(name));
551   }
552   
553   /**
554    * Returns <code>true</code> if a given property exists.
555    *
556    * @param name The name of the property to check.
557    */

558   public boolean propertyExists(String JavaDoc name)
559   {
560     if (properties == null)
561       return false;
562
563     return properties.containsKey(name);
564   }
565
566   /** Returns an enumeration of the properties names. */
567   public Enumeration getPropertyNames()
568   {
569     if (properties == null)
570       return (new Hashtable()).keys();
571
572     return properties.keys();
573   }
574
575   /** Empties the properties table. */
576   public void clearProperties()
577   {
578     propertiesRO = false;
579
580     if (properties == null)
581       return;
582
583     properties.clear();
584     properties = null;
585   }
586   
587   /**
588    * Sets a map as the body of the message.
589    *
590    * @exception IOException In case of an error while setting the map.
591    * @exception MessageROException If the message body is read-only.
592    */

593   public void setMap(Hashtable map) throws Exception JavaDoc
594   {
595     if (bodyRO)
596       throw new MessageROException("Can't set the body as it is READ-ONLY.");
597
598     body_map = map;
599     type = MessageType.MAP;
600   }
601
602   /**
603    * Sets a String as the body of the message.
604    *
605    * @exception MessageROException If the message body is read-only.
606    */

607   public void setText(String JavaDoc text) throws MessageROException
608   {
609     if (bodyRO)
610       throw new MessageROException("Can't set the body as it is READ-ONLY.");
611
612     body_text = text;
613     type = MessageType.TEXT;
614   }
615
616   /**
617    * Sets the message body as a stream of bytes.
618    *
619    * @exception MessageROException If the message body is read-only.
620    */

621   public void setStream(byte[] bytes) throws MessageROException
622   {
623     if (bodyRO)
624       throw new MessageROException("Can't set the body as it is READ-ONLY.");
625
626     body_bytes = bytes;
627     type = MessageType.STREAM;
628   }
629
630   /**
631    * Sets the message body as an array of bytes.
632    *
633    * @exception MessageROException If the message body is read-only.
634    */

635   public void setBytes(byte[] bytes) throws MessageROException
636   {
637     if (bodyRO)
638       throw new MessageROException("Can't set the body as it is READ-ONLY.");
639
640     body_bytes = bytes;
641     type = MessageType.BYTES;
642   }
643
644   /**
645    * Returns the map body of the message.
646    */

647   public Hashtable getMap()
648   {
649     return body_map;
650   }
651
652   /** Gets the String body of the message. */
653   public String JavaDoc getText()
654   {
655     return body_text;
656   }
657
658   /** Returns the stream of bytes body of the message. */
659   public byte[] getStream()
660   {
661     if (type != MessageType.STREAM)
662       return null;
663
664     return body_bytes;
665   }
666
667   /** Returns the array of bytes body of the message. */
668   public byte[] getBytes()
669   {
670     if (type != MessageType.BYTES)
671       return null;
672
673     return body_bytes;
674   }
675
676   /**
677    * Method clearing the message body.
678    */

679   public void clearBody()
680   {
681     body_bytes = null;
682     body_map = null;
683     body_text = null;
684     bodyRO = false;
685   }
686
687   /** Returns <code>true</code> if the message is valid. */
688   public boolean isValid()
689   {
690     if (expiration == 0)
691       return true;
692
693     return ((expiration - System.currentTimeMillis()) > 0);
694   }
695
696   /** Clones the message. */
697   public Object JavaDoc clone()
698   {
699     Message clone = new Message();
700     clone.type = type;
701     clone.persistent = persistent;
702     clone.id = id;
703     clone.priority = priority;
704     clone.expiration = expiration;
705     clone.timestamp = timestamp;
706     clone.toId = toId;
707     clone.toQueue = toQueue;
708     clone.correlationId = correlationId;
709     clone.replyToId = replyToId;
710     clone.replyToQueue = replyToQueue;
711     clone.body_text = body_text;
712     clone.bodyRO = bodyRO;
713     clone.propertiesRO = propertiesRO;
714     clone.deliveryCount = deliveryCount;
715     clone.denied = denied;
716     clone.deletedDest = deletedDest;
717     clone.expired = expired;
718     clone.notWriteable = notWriteable;
719     clone.undeliverable = undeliverable;
720     clone.acksCounter = acksCounter;
721     clone.durableAcksCounter = durableAcksCounter;
722     
723     if (body_bytes != null) {
724       byte[] b = new byte[body_bytes.length];
725       for (int i = 0; i < body_bytes.length; i++)
726         b[i] = body_bytes[i];
727       clone.body_bytes = b;
728     }
729     if (body_map != null) {
730       clone.body_map = new Hashtable();
731       for (Enumeration e = body_map.keys(); e.hasMoreElements(); ) {
732         Object JavaDoc key = e.nextElement();
733         clone.body_map.put(key,body_map.get(key));
734       }
735     }
736     if (optionalHeader != null) {
737       clone.optionalHeader = new Hashtable();
738       for (Enumeration e = optionalHeader.keys(); e.hasMoreElements(); ) {
739         Object JavaDoc key = e.nextElement();
740         clone.optionalHeader.put(key,optionalHeader.get(key));
741       }
742     }
743     if (properties != null) {
744       clone.properties = new Hashtable();
745       for (Enumeration e = properties.keys(); e.hasMoreElements(); ) {
746         Object JavaDoc key = e.nextElement();
747         clone.properties.put(key,properties.get(key));
748       }
749     }
750     return clone;
751   }
752
753   /**
754    * Transforms this message into a vector of primitive values that can
755    * be vehiculated through the SOAP protocol.
756    */

757   public Hashtable soapCode() {
758     Hashtable h = new Hashtable();
759
760     // Building a hashtable containg the fields values:
761
Hashtable fieldsTb = new Hashtable();
762
763     fieldsTb.put("type", new Integer JavaDoc(type));
764     fieldsTb.put("id", id);
765     fieldsTb.put("persistent", new Boolean JavaDoc(persistent));
766     fieldsTb.put("priority", new Integer JavaDoc(priority));
767     fieldsTb.put("expiration", new Long JavaDoc(expiration));
768     fieldsTb.put("timestamp", new Long JavaDoc(timestamp));
769     fieldsTb.put("toId", toId);
770     fieldsTb.put("toQueue", new Boolean JavaDoc(toQueue));
771     if (correlationId != null)
772       fieldsTb.put("correlationId", correlationId);
773     if (replyToId != null) {
774       fieldsTb.put("replyToId", replyToId);
775       fieldsTb.put("replyToQueue", new Boolean JavaDoc(replyToQueue));
776     }
777     if (body_bytes != null)
778       fieldsTb.put("body_bytes", body_bytes);
779     else if (body_map != null)
780       fieldsTb.put("body_map", body_map);
781     else if (body_text != null)
782       fieldsTb.put("body_text", body_text);
783     fieldsTb.put("bodyRO", new Boolean JavaDoc(bodyRO));
784     fieldsTb.put("propertiesRO", new Boolean JavaDoc(propertiesRO));
785     fieldsTb.put("deliveryCount", new Integer JavaDoc(deliveryCount));
786     fieldsTb.put("denied", new Boolean JavaDoc(denied));
787     fieldsTb.put("deletedDest", new Boolean JavaDoc(deletedDest));
788     fieldsTb.put("expired", new Boolean JavaDoc(expired));
789     fieldsTb.put("notWriteable", new Boolean JavaDoc(notWriteable));
790     fieldsTb.put("undeliverable", new Boolean JavaDoc(undeliverable));
791
792     h.put("fieldsTb",fieldsTb);
793
794     // Adding the hashtable of optional headers:
795
if (optionalHeader != null)
796       h.put("optionalHeader",optionalHeader);
797
798     // Adding the hashtable of properties:
799
if (properties != null)
800       h.put("properties",properties);
801
802     return h;
803   }
804
805   /**
806    * Transforms a vector of primitive values into a <code>Message</code>
807    * instance.
808    */

809   public static Message soapDecode(Hashtable h)
810   {
811     if (h == null) return null;
812
813     Hashtable fieldsTb = (Hashtable) h.get("fieldsTb");
814
815     Message msg = new Message();
816
817     try {
818       msg.type = ConversionHelper.toInt(fieldsTb.get("type"));
819       msg.id = (String JavaDoc) fieldsTb.get("id");
820       msg.persistent = ConversionHelper.toBoolean(fieldsTb.get("persistent"));
821       msg.priority = ConversionHelper.toInt(fieldsTb.get("priority"));
822       msg.expiration = ConversionHelper.toLong(fieldsTb.get("expiration"));
823       msg.timestamp = ConversionHelper.toLong(fieldsTb.get("timestamp"));
824       msg.toId = (String JavaDoc) fieldsTb.get("toId");
825       msg.toQueue = ConversionHelper.toBoolean(fieldsTb.get("toQueue"));
826       msg.correlationId = (String JavaDoc) fieldsTb.get("correlationId");
827       msg.replyToId = (String JavaDoc) fieldsTb.get("replyToId");
828       if (msg.replyToId != null) {
829         msg.replyToQueue =
830           ConversionHelper.toBoolean(fieldsTb.get("replyToQueue"));
831       }
832       msg.body_bytes = ConversionHelper.toBytes(fieldsTb.get("body_bytes"));
833       msg.body_map = (Hashtable) fieldsTb.get("body_map");
834       msg.body_text = (String JavaDoc) fieldsTb.get("body_text");
835       msg.bodyRO = ConversionHelper.toBoolean(fieldsTb.get("bodyRO"));
836       msg.propertiesRO =
837         ConversionHelper.toBoolean(fieldsTb.get("propertiesRO"));
838       msg.deliveryCount = ConversionHelper.toInt(fieldsTb.get("deliveryCount"));
839       msg.denied = ConversionHelper.toBoolean(fieldsTb.get("denied"));
840       msg.deletedDest = ConversionHelper.toBoolean(fieldsTb.get("deletedDest"));
841       msg.expired = ConversionHelper.toBoolean(fieldsTb.get("expired"));
842       msg.notWriteable =
843         ConversionHelper.toBoolean(fieldsTb.get("notWriteable"));
844       msg.undeliverable =
845         ConversionHelper.toBoolean(fieldsTb.get("undeliverable"));
846
847       msg.optionalHeader = (Hashtable) h.get("optionalHeader");
848       msg.properties = (Hashtable) h.get("properties");
849     }
850     // Should never happen!
851
catch (MessageValueException exc) {
852       exc.printStackTrace();
853     }
854   
855     return msg;
856     }
857   
858   /**
859    * Method actually preparing the setting of a new property.
860    *
861    * @param name The property name.
862    *
863    * @exception MessageROException If the message properties are read-only.
864    */

865   private void preparePropSetting(String JavaDoc name) throws MessageROException
866   {
867     if (propertiesRO) {
868       throw new MessageROException("Can't set property as the message "
869                                    + "properties are READ-ONLY.");
870     }
871
872     if (name == null || name.equals(""))
873       throw new IllegalArgumentException JavaDoc("Invalid property name: " + name);
874
875     if (properties == null)
876       properties = new Hashtable();
877   }
878
879   /**
880    * Specializes the serialization method for protecting the message's
881    * properties and body as soon as it is sent.
882    */

883 // private void writeObject(ObjectOutputStream s) throws IOException
884
// {
885
// s.defaultWriteObject();
886
// bodyRO = true;
887
// propertiesRO = true;
888
// }
889

890   /**
891    * Specializes the deserialization method for initializing the message's
892    * transient fields.
893    */

894 // private void readObject(ObjectInputStream s)
895
// throws IOException, ClassNotFoundException
896
// {
897
// s.defaultReadObject();
898
// acksCounter = 0;
899
// durableAcksCounter = 0;
900
// }
901
}
902
Popular Tags