KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
11 import java.util.Enumeration JavaDoc;
12 import java.util.Hashtable JavaDoc;
13 import javax.jms.JMSException JavaDoc;
14 import javax.jms.MessageFormatException JavaDoc;
15
16 /**
17  * <p/>
18  * Built-in facility for supporting property values.
19  * </p>
20  * <p/>
21  * <p/>
22  * <p/>
23  * <P>Message properties support the following conversion table. The marked
24  * cases must be supported. The unmarked cases must throw a
25  * <CODE>JMSException</CODE>. The <CODE>String</CODE>-to-primitive conversions
26  * may throw a runtime exception if the
27  * primitive's <CODE>valueOf</CODE> method does not accept the
28  * <CODE>String</CODE> as a valid representation of the primitive.
29  * <p/>
30  * <P>A value written as the row type can be read as the column type.
31  * <p/>
32  * <PRE>
33  * | | boolean byte short int long float double String
34  * |----------------------------------------------------------
35  * |boolean | X X
36  * |byte | X X X X X
37  * |short | X X X X
38  * |int | X X X
39  * |long | X X
40  * |float | X X X
41  * |double | X X
42  * |String | X X X X X X X X
43  * |----------------------------------------------------------
44  * </PRE>
45  * <p/>
46  * <P>In addition to the type-specific set/get methods for properties, JMS
47  * provides the <CODE>setObjectProperty</CODE> and
48  * <CODE>getObjectProperty</CODE> methods. These support the same set of
49  * property types using the objectified primitive values. Their purpose is
50  * to allow the decision of property type to made at execution time rather
51  * than at compile time. They support the same property value conversions.
52  * <p/>
53  * <P>The <CODE>setObjectProperty</CODE> method accepts values of class
54  * <CODE>Boolean</CODE>, <CODE>Byte</CODE>, <CODE>Short</CODE>,
55  * <CODE>Integer</CODE>, <CODE>Long</CODE>, <CODE>Float</CODE>,
56  * <CODE>Double</CODE>, and <CODE>String</CODE>. An attempt
57  * to use any other class must throw a <CODE>JMSException</CODE>.
58  * <p/>
59  * <P>The <CODE>getObjectProperty</CODE> method only returns values of class
60  * <CODE>Boolean</CODE>, <CODE>Byte</CODE>, <CODE>Short</CODE>,
61  * <CODE>Integer</CODE>, <CODE>Long</CODE>, <CODE>Float</CODE>,
62  * <CODE>Double</CODE>, and <CODE>String</CODE>.
63  * <p/>
64  * <P>The order of property values is not defined. To iterate through a
65  * message's property values, use <CODE>getPropertyNames</CODE> to retrieve
66  * a property name enumeration and then use the various property get methods
67  * to retrieve their values.
68  * <p/>
69  * <P>A message's properties are deleted by the <CODE>clearProperties</CODE>
70  * method. This leaves the message with an empty set of properties.
71  * <p/>
72  * <P>Getting a property value for a name which has not been set returns a
73  * null value. Only the <CODE>getStringProperty</CODE> and
74  * <CODE>getObjectProperty</CODE> methods can return a null value.
75  * Attempting to read a null value as a primitive type must be treated as
76  * calling the primitive's corresponding <CODE>valueOf(String)</CODE>
77  * conversion method with a null value.
78  * <p/>
79  * <P>The JMS API reserves the <CODE>JMSX</CODE> property name prefix for JMS
80  * defined properties.
81  * The full set of these properties is defined in the Java Message Service
82  * specification. New JMS defined properties may be added in later versions
83  * of the JMS API. Support for these properties is optional. The
84  * <CODE>String[] ConnectionMetaData.getJMSXPropertyNames</CODE> method
85  * returns the names of the JMSX properties supported by a connection.
86  * <p/>
87  * <P>JMSX properties may be referenced in message selectors whether or not
88  * they are supported by a connection. If they are not present in a
89  * message, they are treated like any other absent property.
90  * <p/>
91  * <P>JMSX properties defined in the specification as "set by provider on
92  * send" are available to both the producer and the consumers of the message.
93  * JMSX properties defined in the specification as "set by provider on
94  * receive" are available only to the consumers.
95  * <p/>
96  * <P><CODE>JMSXGroupID</CODE> and <CODE>JMSXGroupSeq</CODE> are standard
97  * properties that clients
98  * should use if they want to group messages. All providers must support them.
99  * Unless specifically noted, the values and semantics of the JMSX properties
100  * are undefined.
101  * <p/>
102  * <P>The JMS API reserves the <CODE>JMS_<I>vendor_name</I></CODE> property
103  * name prefix for provider-specific properties. Each provider defines its own
104  * value for <CODE><I>vendor_name</I></CODE>. This is the mechanism a JMS
105  * provider uses to make its special per-message services available to a JMS
106  * client.
107  * <p/>
108  * <P>The purpose of provider-specific properties is to provide special
109  * features needed to integrate JMS clients with provider-native clients in a
110  * single JMS application. They should not be used for messaging between JMS
111  * clients.
112  *
113  * @author <a HREF="mailto:founder_chen@yahoo.com.cn">Peter.Cheng</a>
114  * @version Revision: 1.1 Date: 2002-12-01 21:57:33
115  */

116
117 public class MessageProperties implements Serializable JavaDoc {
118
119     // JMS-Standard Tags and Values
120
private static final String JavaDoc JMSX_USERID = "JMSXUserID";
121     private static final String JavaDoc JMSX_APPID = "JMSXAppID";
122     private static final String JavaDoc JMSX_GROUPID = "JMSXGroupID";
123     private static final String JavaDoc JMSX_GROUPSEQ = "JMSXGroupSeq";
124
125     private Hashtable JavaDoc properties = new Hashtable JavaDoc();
126
127
128     /**
129      * Sets a <CODE>boolean</CODE> property value with the specified name into
130      * the message.
131      *
132      * @param name the name of the <CODE>boolean</CODE> property
133      * @param value the <CODE>boolean</CODE> property value to set
134      * @throws javax.jms.JMSException if the JMS provider fails to set the property
135      * due to some internal error.
136      */

137     public void setBooleanProperty(String JavaDoc name, boolean value) throws JMSException JavaDoc {
138         setProperty(name, new Boolean JavaDoc(value));
139     }
140
141     /**
142      * Returns the value of the <CODE>boolean</CODE> property with the
143      * specified name.
144      *
145      * @param name the name of the <CODE>boolean</CODE> property
146      * @return the <CODE>boolean</CODE> property value for the specified name
147      * @throws javax.jms.JMSException if the JMS provider fails to get the property
148      * value due to some internal error.
149      * @throws javax.jms.MessageFormatException
150      * if this type conversion is invalid.
151      */

152     public boolean getBooleanProperty(String JavaDoc name) throws JMSException JavaDoc {
153         return getBoolean(properties.get(name));
154     }
155
156     /**
157      * Sets a <CODE>byte</CODE> property value with the specified name into
158      * the message.
159      *
160      * @param name the name of the <CODE>byte</CODE> property
161      * @param value the <CODE>byte</CODE> property value to set
162      * @throws javax.jms.JMSException if the JMS provider fails to set the property
163      * due to some internal error.
164      */

165     public void setByteProperty(String JavaDoc name, byte value) throws JMSException JavaDoc {
166         setProperty(name, new Byte JavaDoc(value));
167     }
168
169     /**
170      * Returns the value of the <CODE>byte</CODE> property with the specified
171      * name.
172      *
173      * @param name the name of the <CODE>byte</CODE> property
174      * @return the <CODE>byte</CODE> property value for the specified name
175      * @throws javax.jms.JMSException if the JMS provider fails to get the property
176      * value due to some internal error.
177      * @throws javax.jms.MessageFormatException
178      * if this type conversion is invalid.
179      */

180     public byte getByteProperty(String JavaDoc name) throws JMSException JavaDoc {
181         return getByte(properties.get(name));
182     }
183
184     /**
185      * Sets a <CODE>short</CODE> property value with the specified name into
186      * the message.
187      *
188      * @param name the name of the <CODE>short</CODE> property
189      * @param value the <CODE>short</CODE> property value to set
190      * @throws javax.jms.JMSException if the JMS provider fails to set the property
191      * due to some internal error.
192      */

193     public void setShortProperty(String JavaDoc name, short value) throws JMSException JavaDoc {
194         setProperty(name, new Short JavaDoc(value));
195     }
196
197     /**
198      * Returns the value of the <CODE>short</CODE> property with the specified
199      * name.
200      *
201      * @param name the name of the <CODE>short</CODE> property
202      * @return the <CODE>short</CODE> property value for the specified name
203      * @throws javax.jms.JMSException if the JMS provider fails to get the property
204      * value due to some internal error.
205      * @throws javax.jms.MessageFormatException
206      * if this type conversion is invalid.
207      */

208     public short getShortProperty(String JavaDoc name) throws JMSException JavaDoc {
209         return getShort(properties.get(name));
210     }
211
212     /**
213      * Sets an <CODE>int</CODE> property value with the specified name into
214      * the message.
215      *
216      * @param name the name of the <CODE>int</CODE> property
217      * @param value the <CODE>int</CODE> property value to set
218      * @throws javax.jms.JMSException if the JMS provider fails to set the property
219      * due to some internal error.
220      */

221     public void setIntProperty(String JavaDoc name, int value) throws JMSException JavaDoc {
222         setProperty(name, new Integer JavaDoc(value));
223     }
224
225     /**
226      * Returns the value of the <CODE>int</CODE> property with the specified
227      * name.
228      *
229      * @param name the name of the <CODE>int</CODE> property
230      * @return the <CODE>int</CODE> property value for the specified name
231      * @throws javax.jms.JMSException if the JMS provider fails to get the property
232      * value due to some internal error.
233      * @throws javax.jms.MessageFormatException
234      * if this type conversion is invalid.
235      */

236     public int getIntProperty(String JavaDoc name) throws JMSException JavaDoc {
237         return getInt(properties.get(name));
238     }
239
240     /**
241      * Sets a <CODE>long</CODE> property value with the specified name into
242      * the message.
243      *
244      * @param name the name of the <CODE>long</CODE> property
245      * @param value the <CODE>long</CODE> property value to set
246      * @throws javax.jms.JMSException if the JMS provider fails to set the property
247      * due to some internal error.
248      */

249     public void setLongProperty(String JavaDoc name, long value) throws JMSException JavaDoc {
250         setProperty(name, new Long JavaDoc(value));
251     }
252
253     /**
254      * Returns the value of the <CODE>long</CODE> property with the specified
255      * name.
256      *
257      * @param name the name of the <CODE>long</CODE> property
258      * @return the <CODE>long</CODE> property value for the specified name
259      * @throws javax.jms.JMSException if the JMS provider fails to get the property
260      * value due to some internal error.
261      * @throws javax.jms.MessageFormatException
262      * if this type conversion is invalid.
263      */

264     public long getLongProperty(String JavaDoc name) throws JMSException JavaDoc {
265         return getLong(properties.get(name));
266     }
267
268     /**
269      * Sets a <CODE>float</CODE> property value with the specified name into
270      * the message.
271      *
272      * @param name the name of the <CODE>float</CODE> property
273      * @param value the <CODE>float</CODE> property value to set
274      * @throws javax.jms.JMSException if the JMS provider fails to set the property
275      * due to some internal error.
276      */

277     public void setFloatProperty(String JavaDoc name, float value) throws JMSException JavaDoc {
278         setProperty(name, new Float JavaDoc(value));
279     }
280
281     /**
282      * Returns the value of the <CODE>float</CODE> property with the specified
283      * name.
284      *
285      * @param name the name of the <CODE>float</CODE> property
286      * @return the <CODE>float</CODE> property value for the specified name
287      * @throws javax.jms.JMSException if the JMS provider fails to get the property
288      * value due to some internal error.
289      * @throws javax.jms.MessageFormatException
290      * if this type conversion is invalid.
291      */

292     public float getFloatProperty(String JavaDoc name) throws JMSException JavaDoc {
293         return getFloat(properties.get(name));
294     }
295
296     /**
297      * Sets a <CODE>double</CODE> property value with the specified name into
298      * the message.
299      *
300      * @param name the name of the <CODE>double</CODE> property
301      * @param value the <CODE>double</CODE> property value to set
302      * @throws javax.jms.JMSException if the JMS provider fails to set the property
303      * due to some internal error.
304      */

305     public void setDoubleProperty(String JavaDoc name, double value) throws JMSException JavaDoc {
306         setProperty(name, new Double JavaDoc(value));
307     }
308
309     /**
310      * Returns the value of the <CODE>double</CODE> property with the specified
311      * name.
312      *
313      * @param name the name of the <CODE>double</CODE> property
314      * @return the <CODE>double</CODE> property value for the specified name
315      * @throws javax.jms.JMSException if the JMS provider fails to get the property
316      * value due to some internal error.
317      * @throws javax.jms.MessageFormatException
318      * if this type conversion is invalid.
319      */

320     public double getDoubleProperty(String JavaDoc name) throws JMSException JavaDoc {
321         return getDouble(properties.get(name));
322     }
323
324     /**
325      * Sets a <CODE>String</CODE> property value with the specified name into
326      * the message.
327      *
328      * @param name the name of the <CODE>String</CODE> property
329      * @param value the <CODE>String</CODE> property value to set
330      * @throws javax.jms.JMSException if the JMS provider fails to set the property
331      * due to some internal error.
332      */

333     public void setStringProperty(String JavaDoc name, String JavaDoc value) throws JMSException JavaDoc {
334         setProperty(name, new String JavaDoc(value));
335     }
336
337     /**
338      * Returns the value of the <CODE>String</CODE> property with the specified
339      * name.
340      *
341      * @param name the name of the <CODE>String</CODE> property
342      * @return the <CODE>String</CODE> property value for the specified name;
343      * if there is no property by this name, a null value is returned
344      * @throws javax.jms.JMSException if the JMS provider fails to get the property
345      * value due to some internal error.
346      * @throws javax.jms.MessageFormatException
347      * if this type conversion is invalid.
348      */

349     public String JavaDoc getStringProperty(String JavaDoc name) throws JMSException JavaDoc {
350         return getString(properties.get(name));
351     }
352
353     /**
354      * Sets a Java object property value with the specified name into the
355      * message.
356      * <p/>
357      * <P>Note that this method works only for the objectified primitive
358      * object types (<CODE>Integer</CODE>, <CODE>Double</CODE>,
359      * <CODE>Long</CODE> ...) and <CODE>String</CODE> objects.
360      *
361      * @param name the name of the Java object property
362      * @param value the Java object property value to set
363      * @throws javax.jms.JMSException if the JMS provider fails to set the property
364      * due to some internal error.
365      * @throws javax.jms.MessageFormatException
366      * if the object is invalid
367      */

368     public void setObjectProperty(String JavaDoc name, Object JavaDoc value) throws JMSException JavaDoc {
369         if (value instanceof Boolean JavaDoc) {
370             setBooleanProperty(name, ((Boolean JavaDoc) value).booleanValue());
371         } else if (value instanceof Byte JavaDoc) {
372             setByteProperty(name, ((Byte JavaDoc) value).byteValue());
373         } else if (value instanceof Short JavaDoc) {
374             setShortProperty(name, ((Short JavaDoc) value).shortValue());
375         } else if (value instanceof Integer JavaDoc) {
376             setIntProperty(name, ((Integer JavaDoc) value).intValue());
377         } else if (value instanceof Long JavaDoc) {
378             setLongProperty(name, ((Long JavaDoc) value).longValue());
379         } else if (value instanceof Float JavaDoc) {
380             setFloatProperty(name, ((Float JavaDoc) value).floatValue());
381         } else if (value instanceof Double JavaDoc) {
382             setDoubleProperty(name, ((Double JavaDoc) value).doubleValue());
383         } else if (value instanceof String JavaDoc) {
384             setStringProperty(name, (String JavaDoc) value);
385         } else if (value == null) {
386             setProperty(name, null);
387         } else {
388             throw new MessageFormatException JavaDoc("Does not support objects of " + "type=" + value.getClass().getName());
389         }
390     }
391
392     /**
393      * Returns the value of the Java object property with the specified name.
394      * <p/>
395      * <P>This method can be used to return, in objectified format,
396      * an object that has been stored as a property in the message with the
397      * equivalent <CODE>setObjectProperty</CODE> method call, or its equivalent
398      * primitive <CODE>set<I>type</I>Property</CODE> method.
399      *
400      * @param name the name of the Java object property
401      * @return the Java object property value with the specified name, in
402      * objectified format (for example, if the property was set as an
403      * <CODE>int</CODE>, an <CODE>Integer</CODE> is
404      * returned); if there is no property by this name, a null value
405      * is returned
406      * @throws javax.jms.JMSException if the JMS provider fails to get the property
407      * value due to some internal error.
408      */

409     public Object JavaDoc getObjectProperty(String JavaDoc name) throws JMSException JavaDoc {
410         Object JavaDoc value = properties.get(name);
411         if (value != null) {
412             if (value instanceof Boolean JavaDoc) {
413                 return new Boolean JavaDoc(((Boolean JavaDoc) value).booleanValue());
414             } else if (value instanceof Byte JavaDoc) {
415                 return new Byte JavaDoc(((Byte JavaDoc) value).byteValue());
416             } else if (value instanceof Short JavaDoc) {
417                 return new Short JavaDoc(((Short JavaDoc) value).shortValue());
418             } else if (value instanceof Integer JavaDoc) {
419                 return new Integer JavaDoc(((Integer JavaDoc) value).intValue());
420             } else if (value instanceof Long JavaDoc) {
421                 return new Long JavaDoc(((Long JavaDoc) value).longValue());
422             } else if (value instanceof Float JavaDoc) {
423                 return new Float JavaDoc(((Float JavaDoc) value).floatValue());
424             } else if (value instanceof Double JavaDoc) {
425                 return new Double JavaDoc(((Double JavaDoc) value).doubleValue());
426             } else {
427                 return new String JavaDoc((String JavaDoc) value);
428             }
429         } else {
430             return null;
431         }
432     }
433
434
435     /**
436      * Inner common method setProperty
437      *
438      * @param name the name of the Java object property
439      * @param value the Java object property value to set
440      * @throws javax.jms.JMSException if the JMS provider fails to set the property
441      * due to some internal error.
442      */

443     private void setProperty(String JavaDoc name, Object JavaDoc value) throws JMSException JavaDoc {
444         if (name == null) {
445             throw new JMSException JavaDoc("It's invalid property name");
446         } else {
447             if (name.equalsIgnoreCase("NULL") ||
448                     name.equalsIgnoreCase("TRUE") ||
449                     name.equalsIgnoreCase("FALSE") ||
450                     name.equals("NOT") ||
451                     name.equals("AND") ||
452                     name.equals("OR") ||
453                     name.equals("BETWEEN") ||
454                     name.equals("LIKE") ||
455                     name.equals("IN") ||
456                     name.equals("IS")) {
457                 throw new JMSException JavaDoc("Invalid property name");
458             } else {
459                 if (name.startsWith("JMS") && !name.startsWith("JMS_")) {
460                     throw new JMSException JavaDoc("Properties cannot begin with JMS");
461                 } else {
462                     properties.put(name, value);
463                 }
464             }
465         }
466     }
467
468     /**
469      * Convert value to boolean
470      *
471      * @param value
472      * @return the converted boolean
473      * @throws javax.jms.MessageFormatException
474      * if the conversion is invalid
475      */

476     private boolean getBoolean(Object JavaDoc value) throws MessageFormatException JavaDoc {
477         if (value instanceof Boolean JavaDoc) {
478             return ((Boolean JavaDoc) value).booleanValue();
479         } else if (value instanceof String JavaDoc) {
480             return Boolean.valueOf((String JavaDoc) value).booleanValue();
481         } else if (value == null) {
482             return Boolean.valueOf((String JavaDoc) value).booleanValue();
483         } else {
484             throw new MessageFormatException JavaDoc("Can't convert value of type "
485                     + value.getClass().getName() + " to Boolean");
486         }
487     }
488
489     /**
490      * Convert value to byte
491      *
492      * @param value
493      * @return the converted byte
494      * @throws javax.jms.MessageFormatException
495      * if the conversion is invalid
496      */

497     private byte getByte(Object JavaDoc value) throws MessageFormatException JavaDoc {
498         if (value instanceof Byte JavaDoc) {
499             return ((Byte JavaDoc) value).byteValue();
500         } else if (value instanceof String JavaDoc) {
501             return Byte.parseByte((String JavaDoc) value);
502         } else if (value == null) {
503             return Byte.valueOf((String JavaDoc) value).byteValue();
504         } else {
505             throw new MessageFormatException JavaDoc("Can't convert value of type "
506                     + value.getClass().getName() + " to Byte");
507         }
508     }
509
510     /**
511      * Convert value to short
512      *
513      * @param value
514      * @return the converted short
515      * @throws javax.jms.MessageFormatException
516      * if the conversion is invalid
517      */

518     private short getShort(Object JavaDoc value) throws MessageFormatException JavaDoc {
519         if (value instanceof Short JavaDoc) {
520             return ((Short JavaDoc) value).shortValue();
521         } else if (value instanceof Byte JavaDoc) {
522             return ((Byte JavaDoc) value).shortValue();
523         } else if (value instanceof String JavaDoc) {
524             return Short.parseShort((String JavaDoc) value);
525         } else if (value == null) {
526             return Short.valueOf((String JavaDoc) value).shortValue();
527         } else {
528             throw new MessageFormatException JavaDoc("Can't convert value of type "
529                     + value.getClass().getName() + " to Short");
530         }
531     }
532
533     /**
534      * Convert value to int
535      *
536      * @param value
537      * @return the converted int
538      * @throws javax.jms.MessageFormatException
539      * if the conversion is invalid
540      * @throws NumberFormatException if value is a String and the conversion
541      * is invalid
542      */

543     private int getInt(Object JavaDoc value) throws MessageFormatException JavaDoc {
544         if (value instanceof Integer JavaDoc) {
545             return ((Integer JavaDoc) value).intValue();
546         } else if (value instanceof Byte JavaDoc) {
547             return ((Byte JavaDoc) value).intValue();
548         } else if (value instanceof Short JavaDoc) {
549             return ((Short JavaDoc) value).intValue();
550         } else if (value instanceof String JavaDoc) {
551             return Integer.parseInt((String JavaDoc) value);
552         } else if (value == null) {
553             return Integer.valueOf((String JavaDoc) value).intValue();
554         } else {
555             throw new MessageFormatException JavaDoc("Can't convert value of type "
556                     + value.getClass().getName() + " to Int");
557         }
558     }
559
560
561     /**
562      * Convert value to long
563      *
564      * @param value
565      * @return the converted long
566      * @throws javax.jms.MessageFormatException
567      * if the conversion is invalid
568      * @throws NumberFormatException if value is a String and the conversion
569      * is invalid
570      */

571     private long getLong(Object JavaDoc value) throws MessageFormatException JavaDoc {
572         if (value instanceof Long JavaDoc) {
573             return ((Long JavaDoc) value).longValue();
574         } else if (value instanceof Byte JavaDoc) {
575             return ((Byte JavaDoc) value).longValue();
576         } else if (value instanceof Short JavaDoc) {
577             return ((Short JavaDoc) value).longValue();
578         } else if (value instanceof Integer JavaDoc) {
579             return ((Integer JavaDoc) value).longValue();
580         } else if (value instanceof String JavaDoc) {
581             return Long.parseLong((String JavaDoc) value);
582         } else if (value == null) {
583             return Long.valueOf((String JavaDoc) value).longValue();
584         } else {
585             throw new MessageFormatException JavaDoc("Can't convert value of type "
586                     + value.getClass().getName() + " to Long");
587         }
588     }
589
590     /**
591      * Convert value to float
592      *
593      * @param value
594      * @return the converted float
595      * @throws javax.jms.MessageFormatException
596      * if the conversion is invalid
597      * @throws NumberFormatException if value is a String and the conversion
598      * is invalid
599      */

600     private float getFloat(Object JavaDoc value) throws MessageFormatException JavaDoc {
601         if (value instanceof Float JavaDoc) {
602             return ((Float JavaDoc) value).floatValue();
603         } else if (value instanceof String JavaDoc) {
604             return Float.parseFloat((String JavaDoc) value);
605         } else if (value == null) {
606             return Float.valueOf((String JavaDoc) value).floatValue();
607         } else {
608             throw new MessageFormatException JavaDoc("Can't convert value of type "
609                     + value.getClass().getName() + " to Float");
610         }
611     }
612
613     /**
614      * Convert value to double
615      *
616      * @param value the object to convert from
617      * @return the converted double
618      * @throws javax.jms.MessageFormatException
619      * if the conversion is invalid
620      * @throws NumberFormatException if value is a String and the conversion
621      * is invalid
622      */

623     private double getDouble(Object JavaDoc value) throws MessageFormatException JavaDoc {
624         if (value instanceof Double JavaDoc) {
625             return ((Double JavaDoc) value).doubleValue();
626         } else if (value instanceof Float JavaDoc) {
627             return ((Float JavaDoc) value).doubleValue();
628         } else if (value instanceof String JavaDoc) {
629             return Double.parseDouble((String JavaDoc) value);
630         } else if (value == null) {
631             return Double.valueOf((String JavaDoc) value).doubleValue();
632         } else {
633             throw new MessageFormatException JavaDoc("Can't convert value of type "
634                     + value.getClass().getName() + " to Double");
635         }
636     }
637
638     /**
639      * Convert value to String
640      *
641      * @param value the object to convert from
642      * @return the converted String
643      * @throws javax.jms.MessageFormatException
644      * if the conversion is invalid
645      */

646     private String JavaDoc getString(Object JavaDoc value) throws MessageFormatException JavaDoc {
647         return (value == null) ? null : String.valueOf(value);
648     }
649
650
651     /**
652      * Clear any values contained in the properties section of the message.
653      *
654      * @see javax.jms.Message
655      */

656     public void clearProperties() {
657         properties.clear();
658     }
659
660     /**
661      * Determine if the specified property exists.
662      *
663      * @see javax.jms.Message
664      */

665     public boolean propertyExists(String JavaDoc name) {
666         return properties.containsKey(name);
667     }
668
669     /**
670      * Returns an <CODE>Enumeration</CODE> of all the property names.
671      *
672      * @return an enumeration of all the names of property values
673      */

674     public Enumeration JavaDoc getPropertyNames() {
675         return Collections.enumeration(properties.keySet());
676     }
677 }
678
Popular Tags