Table 2–19 lists the methods defined in the JMS Message interface for retrieving the values of a message’s properties (see Message Properties). There is a retrieval method for each of the possible primitive types that a property value can assume: for instance, you can obtain a message’s time stamp with the statement
long timeStamp = inMsg.getLongProperty("JMSXRcvTimestamp");Table 2–19 Message Property Retrieval Methods
Name |
Description |
---|---|
Get integer property |
|
Get byte property |
|
Get short integer property |
|
Get long integer property |
|
Get floating-point property |
|
Get double-precision property |
|
Get boolean property |
|
Get string property |
|
Get property as object |
|
Get property names |
|
Does property exist? |
There is also a generic getObjectProperty method that returns a property value in objectified form, as a Java object of class Integer, Byte, Short, Long, Float , Double, Boolean, or String . For example, another way to obtain a message’s time stamp, equivalent to that shown above, would be
Long timeStampObject = (Long)inMsg.getObjectProperty("JMSXRcvTimestamp"); long timeStamp = timeStampObject.longValue();
If the message has no property with the requested name, getObjectProperty will return null; the message method propertyExists tests whether this is the case.
The getPropertyNames method returns a Java enumeration object for iterating through all of the property names associated with a given message; you can then use the retrieval methods shown in the table to retrieve each of the properties by name, as shown in Example 2–5.
Enumeration propNames = inMsg.getPropertyNames(); String eachName; Object eachValue; while ( propNames.hasMoreElements() ) { eachName = propNames.nextElement(); eachValue = inMsg.getObjectProperty(eachName); /* Do something with the value */ } |