public final class MapMessage extends Message implements MapMessage
javax.jms.MapMessage
interface.
A MapMessage object is used to send a set of name-value pairs. The names are String objects, and the values are primitive Java data types. The names must have a value that is not null, and not an empty string. MapMessage inherits from the Message interface and adds a message body that contains a Map.
The primitive types can be read or written explicitly using methods for each type. They may also be read or written generically as objects. For instance, a call to MapMessage.setInt("foo", 6) is equivalent to MapMessage.setObject("foo", new Integer(6)).
When a client receives a MapMessage, it is in read-only mode. If a client attempts to write to the message at this point, a MessageNotWriteableException is thrown. If clearBody is called, the message can now be both read from and written to.
MapMessage objects support conversions (see table below). Unsupported conversions must throw a JMSException. The String-to-primitive conversions may throw a runtime exception if the primitive's valueOf() method does not accept it as a valid String representation of the primitive.
A value written as the row type can be read as the column type.
| | boolean byte short char int long float double String byte[] +--------+------------------------------------------------------------- |boolean | X X |byte | X X X X X |short | X X X X |char | X X |int | X X X |long | X X |float | X X X |double | X X |String | X X X X X X X X |byte[] | X +----------------------------------------------------------------------
Attempting to read a null value as a primitive type must be treated as calling the primitive's corresponding valueOf(String) conversion method with a null value. Since char does not support a String conversion, attempting to read a null value as a char must throw a NullPointerException.
Modifier and Type | Field and Description |
---|---|
private HashMap |
map
The wrapped hashmap.
|
jmsDest, logger, momMsg, propertiesRO, RObody, session
DEFAULT_DELIVERY_MODE, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE
Constructor and Description |
---|
MapMessage()
Instantiates a bright new
MapMessage . |
MapMessage(Session session,
Message momMsg)
Instantiates a
MapMessage wrapping a consumed MOM
message containing an hashtable. |
Modifier and Type | Method and Description |
---|---|
void |
clearBody()
API method.
|
boolean |
getBoolean(String name)
API method.
|
byte |
getByte(String name)
API method.
|
byte[] |
getBytes(String name)
API method.
|
char |
getChar(String name)
API method.
|
double |
getDouble(String name)
API method.
|
protected <T> T |
getEffectiveBody(Class<T> c)
Get message body
|
float |
getFloat(String name)
API method.
|
int |
getInt(String name)
API method.
|
long |
getLong(String name)
API method.
|
Enumeration |
getMapNames()
API method.
|
Object |
getObject(String name)
API method.
|
short |
getShort(String name)
API method.
|
String |
getString(String name)
API method.
|
boolean |
itemExists(String name)
API method.
|
protected void |
prepare()
Method actually preparing the message for sending by transfering the
local body into the wrapped MOM message.
|
void |
setBoolean(String name,
boolean value)
API method.
|
void |
setByte(String name,
byte value)
API method.
|
void |
setBytes(String name,
byte[] value)
API method.
|
void |
setBytes(String name,
byte[] value,
int offset,
int length)
API method.
|
void |
setChar(String name,
char value)
API method.
|
void |
setDouble(String name,
double value)
API method.
|
void |
setFloat(String name,
float value)
API method.
|
void |
setInt(String name,
int value)
API method.
|
void |
setLong(String name,
long value)
API method.
|
void |
setObject(String name,
Object value)
API method.
|
void |
setShort(String name,
short value)
API method.
|
void |
setString(String name,
String value)
API method.
|
acknowledge, clearProperties, convertJMSMessage, getBody, getBooleanProperty, getByteProperty, getCompressedMinSize, getCompressionLevel, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDeliveryTime, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getMomMsg, getObjectProperty, getProperties, getPropertyNames, getShortProperty, getStringProperty, isBodyAssignableTo, isCompressed, prepareJMSMessage, propertyExists, resetPropertiesRO, setBooleanProperty, setByteProperty, setCompressedMinSize, setCompressionLevel, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDeliveryTime, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setShortProperty, setStringProperty, toString, toString, wrapMomMessage
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
acknowledge, clearProperties, getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getObjectProperty, getPropertyNames, getShortProperty, getStringProperty, propertyExists, setBooleanProperty, setByteProperty, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setShortProperty, setStringProperty
private transient HashMap map
MapMessage()
MapMessage
.MapMessage(Session session, Message momMsg) throws MessageFormatException
MapMessage
wrapping a consumed MOM
message containing an hashtable.sess
- The consuming session.momMsg
- The MOM message to wrap.MessageFormatException
- In case of a problem when getting the
MOM message data.public void clearBody() throws JMSException
Calling this method leaves the message body in the same state as an empty body in a newly created message.
clearBody
in interface Message
clearBody
in class Message
JMSException
- Actually never thrown.public void setBoolean(String name, boolean value) throws JMSException
setBoolean
in interface MapMessage
name
- the name of the boolean.value
- the boolean value to set in the MapMessageNotWriteableException
- If the message body is read-only.JMSException
public void setByte(String name, byte value) throws JMSException
setByte
in interface MapMessage
name
- the name of the byte.value
- the byte value to set in the MapMessageNotWriteableException
- If the message body is read-only.JMSException
public void setBytes(String name, byte[] value) throws JMSException
setBytes
in interface MapMessage
name
- the name of the byte array.value
- the byte array value to set in the Map; the array is copied so that
the value for name will not be altered by future modificationsMessageNotWriteableException
- If the message body is read-only.JMSException
public void setBytes(String name, byte[] value, int offset, int length) throws JMSException
setBytes
in interface MapMessage
name
- the name of the byte array.value
- the byte array value to set in the Map; the array is copied so that
the value for name will not be altered by future modifications.offset
- the initial offset within the byte array.length
- the number of bytes to use.MessageNotWriteableException
- If the message body is read-only.JMSException
public void setChar(String name, char value) throws JMSException
setChar
in interface MapMessage
name
- the name of the char.value
- the char value to set in the MapMessageNotWriteableException
- If the message body is read-only.JMSException
public void setDouble(String name, double value) throws JMSException
setDouble
in interface MapMessage
name
- the name of the double.value
- the double value to set in the MapMessageNotWriteableException
- If the message body is read-only.JMSException
public void setFloat(String name, float value) throws JMSException
setFloat
in interface MapMessage
name
- the name of the float.value
- the float value to set in the MapMessageNotWriteableException
- If the message body is read-only.JMSException
public void setInt(String name, int value) throws JMSException
setInt
in interface MapMessage
name
- the name of the int.value
- the int value to set in the MapMessageNotWriteableException
- If the message body is read-only.JMSException
public void setLong(String name, long value) throws JMSException
setLong
in interface MapMessage
name
- the name of the long.value
- the long value to set in the MapMessageNotWriteableException
- If the message body is read-only.JMSException
public void setShort(String name, short value) throws JMSException
setShort
in interface MapMessage
name
- the name of the short.value
- the short value to set in the MapMessageNotWriteableException
- If the message body is read-only.JMSException
public void setString(String name, String value) throws JMSException
setString
in interface MapMessage
name
- the name of the String.value
- the String value to set in the MapMessageNotWriteableException
- If the message body is read-only.JMSException
public void setObject(String name, Object value) throws JMSException
This method works only for the objectified primitive object types (Integer, Double, Long ...), String objects, and byte arrays.
setObject
in interface MapMessage
name
- the name of the object.value
- the Java object value to set in the MapMessageNotWriteableException
- If the message body is read-only.MessageFormatException
- If the value type is invalid.JMSException
public boolean getBoolean(String name) throws JMSException
getBoolean
in interface MapMessage
name
- the key whose associated value is to be returned.MessageFormatException
- If the value type is invalid.JMSException
public byte getByte(String name) throws JMSException
getByte
in interface MapMessage
name
- the key whose associated value is to be returned.MessageFormatException
- If the value type is invalid.JMSException
public byte[] getBytes(String name) throws JMSException
getBytes
in interface MapMessage
name
- the key whose associated value is to be returned.MessageFormatException
- If the value type is invalid.JMSException
public char getChar(String name) throws JMSException
getChar
in interface MapMessage
name
- the key whose associated value is to be returned.MessageFormatException
- If the value type is invalid.JMSException
public double getDouble(String name) throws JMSException
getDouble
in interface MapMessage
name
- the key whose associated value is to be returned.MessageFormatException
- If the value type is invalid.JMSException
public float getFloat(String name) throws JMSException
getFloat
in interface MapMessage
name
- the key whose associated value is to be returned.MessageFormatException
- If the value type is invalid.JMSException
public int getInt(String name) throws JMSException
getInt
in interface MapMessage
name
- the key whose associated value is to be returned.MessageFormatException
- If the value type is invalid.JMSException
public long getLong(String name) throws JMSException
getLong
in interface MapMessage
name
- the key whose associated value is to be returned.MessageFormatException
- If the value type is invalid.JMSException
public Object getObject(String name) throws JMSException
getObject
in interface MapMessage
name
- the key whose associated value is to be returned.JMSException
- Actually never thrown.public short getShort(String name) throws JMSException
getShort
in interface MapMessage
name
- the key whose associated value is to be returned.MessageFormatException
- If the value type is invalid.JMSException
public String getString(String name) throws JMSException
getString
in interface MapMessage
name
- the key whose associated value is to be returned.JMSException
- Actually never thrown.public boolean itemExists(String name) throws JMSException
itemExists
in interface MapMessage
JMSException
- Actually never thrown.public Enumeration getMapNames() throws JMSException
getMapNames
in interface MapMessage
JMSException
- Actually never thrown.protected void prepare() throws JMSException
prepare
in class Message
MessageFormatException
- If an error occurs while serializing.JMSException
protected <T> T getEffectiveBody(Class<T> c) throws JMSException
Message
getEffectiveBody
in class Message
JMSException
- if the JMS provider fails to return a value due to some internal error.Copyright © 2013 ScalAgent D.T.. All Rights Reserved.