public final class MapMessage extends Message implements jakarta.jms.MapMessage
jakarta.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.
|
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, dumpBody, dumpBody, 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, getRawBody, 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, getBody, getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDeliveryTime, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getObjectProperty, getPropertyNames, getShortProperty, getStringProperty, isBodyAssignableTo, propertyExists, setBooleanProperty, setByteProperty, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDeliveryTime, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setShortProperty, setStringProperty
private transient HashMap map
MapMessage()
MapMessage
.MapMessage(Session session, Message momMsg) throws jakarta.jms.MessageFormatException
MapMessage
wrapping a consumed MOM
message containing an hashtable.sess
- The consuming session.momMsg
- The MOM message to wrap.jakarta.jms.MessageFormatException
- In case of a problem when getting the
MOM message data.public void clearBody() throws jakarta.jms.JMSException
Calling this method leaves the message body in the same state as an empty body in a newly created message.
public void setBoolean(String name, boolean value) throws jakarta.jms.JMSException
setBoolean
in interface jakarta.jms.MapMessage
name
- the name of the boolean.value
- the boolean value to set in the Mapjakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.JMSException
public void setByte(String name, byte value) throws jakarta.jms.JMSException
setByte
in interface jakarta.jms.MapMessage
name
- the name of the byte.value
- the byte value to set in the Mapjakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.JMSException
public void setBytes(String name, byte[] value) throws jakarta.jms.JMSException
setBytes
in interface jakarta.jms.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 modificationsjakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.JMSException
public void setBytes(String name, byte[] value, int offset, int length) throws jakarta.jms.JMSException
setBytes
in interface jakarta.jms.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.jakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.JMSException
public void setChar(String name, char value) throws jakarta.jms.JMSException
setChar
in interface jakarta.jms.MapMessage
name
- the name of the char.value
- the char value to set in the Mapjakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.JMSException
public void setDouble(String name, double value) throws jakarta.jms.JMSException
setDouble
in interface jakarta.jms.MapMessage
name
- the name of the double.value
- the double value to set in the Mapjakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.JMSException
public void setFloat(String name, float value) throws jakarta.jms.JMSException
setFloat
in interface jakarta.jms.MapMessage
name
- the name of the float.value
- the float value to set in the Mapjakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.JMSException
public void setInt(String name, int value) throws jakarta.jms.JMSException
setInt
in interface jakarta.jms.MapMessage
name
- the name of the int.value
- the int value to set in the Mapjakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.JMSException
public void setLong(String name, long value) throws jakarta.jms.JMSException
setLong
in interface jakarta.jms.MapMessage
name
- the name of the long.value
- the long value to set in the Mapjakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.JMSException
public void setShort(String name, short value) throws jakarta.jms.JMSException
setShort
in interface jakarta.jms.MapMessage
name
- the name of the short.value
- the short value to set in the Mapjakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.JMSException
public void setString(String name, String value) throws jakarta.jms.JMSException
setString
in interface jakarta.jms.MapMessage
name
- the name of the String.value
- the String value to set in the Mapjakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.JMSException
public void setObject(String name, Object value) throws jakarta.jms.JMSException
This method works only for the objectified primitive object types (Integer, Double, Long ...), String objects, and byte arrays.
setObject
in interface jakarta.jms.MapMessage
name
- the name of the object.value
- the Java object value to set in the Mapjakarta.jms.MessageNotWriteableException
- If the message body is read-only.jakarta.jms.MessageFormatException
- If the value type is invalid.jakarta.jms.JMSException
public boolean getBoolean(String name) throws jakarta.jms.JMSException
getBoolean
in interface jakarta.jms.MapMessage
name
- the key whose associated value is to be returned.jakarta.jms.MessageFormatException
- If the value type is invalid.jakarta.jms.JMSException
public byte getByte(String name) throws jakarta.jms.JMSException
getByte
in interface jakarta.jms.MapMessage
name
- the key whose associated value is to be returned.jakarta.jms.MessageFormatException
- If the value type is invalid.jakarta.jms.JMSException
public byte[] getBytes(String name) throws jakarta.jms.JMSException
getBytes
in interface jakarta.jms.MapMessage
name
- the key whose associated value is to be returned.jakarta.jms.MessageFormatException
- If the value type is invalid.jakarta.jms.JMSException
public char getChar(String name) throws jakarta.jms.JMSException
getChar
in interface jakarta.jms.MapMessage
name
- the key whose associated value is to be returned.jakarta.jms.MessageFormatException
- If the value type is invalid.jakarta.jms.JMSException
public double getDouble(String name) throws jakarta.jms.JMSException
getDouble
in interface jakarta.jms.MapMessage
name
- the key whose associated value is to be returned.jakarta.jms.MessageFormatException
- If the value type is invalid.jakarta.jms.JMSException
public float getFloat(String name) throws jakarta.jms.JMSException
getFloat
in interface jakarta.jms.MapMessage
name
- the key whose associated value is to be returned.jakarta.jms.MessageFormatException
- If the value type is invalid.jakarta.jms.JMSException
public int getInt(String name) throws jakarta.jms.JMSException
getInt
in interface jakarta.jms.MapMessage
name
- the key whose associated value is to be returned.jakarta.jms.MessageFormatException
- If the value type is invalid.jakarta.jms.JMSException
public long getLong(String name) throws jakarta.jms.JMSException
getLong
in interface jakarta.jms.MapMessage
name
- the key whose associated value is to be returned.jakarta.jms.MessageFormatException
- If the value type is invalid.jakarta.jms.JMSException
public Object getObject(String name) throws jakarta.jms.JMSException
getObject
in interface jakarta.jms.MapMessage
name
- the key whose associated value is to be returned.jakarta.jms.JMSException
- Actually never thrown.public short getShort(String name) throws jakarta.jms.JMSException
getShort
in interface jakarta.jms.MapMessage
name
- the key whose associated value is to be returned.jakarta.jms.MessageFormatException
- If the value type is invalid.jakarta.jms.JMSException
public String getString(String name) throws jakarta.jms.JMSException
getString
in interface jakarta.jms.MapMessage
name
- the key whose associated value is to be returned.jakarta.jms.JMSException
- Actually never thrown.public boolean itemExists(String name) throws jakarta.jms.JMSException
itemExists
in interface jakarta.jms.MapMessage
jakarta.jms.JMSException
- Actually never thrown.public Enumeration getMapNames() throws jakarta.jms.JMSException
getMapNames
in interface jakarta.jms.MapMessage
jakarta.jms.JMSException
- Actually never thrown.protected void prepare() throws jakarta.jms.JMSException
protected <T> T getEffectiveBody(Class<T> c) throws jakarta.jms.JMSException
Message
getEffectiveBody
in class Message
c
- The type to which the message body will be assigned.jakarta.jms.JMSException
- if the JMS provider fails to return a value due to some internal error.Copyright © 2023 ScalAgent D.T.. All rights reserved.