Class MapMessage
- java.lang.Object
-
- org.objectweb.joram.client.jms.Message
-
- org.objectweb.joram.client.jms.MapMessage
-
- All Implemented Interfaces:
MapMessage,Message
public final class MapMessage extends Message implements MapMessage
Implements thejavax.jms.MapMessageinterface.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.
-
-
Field Summary
Fields Modifier and Type Field Description private HashMap<String,Object>mapThe wrapped hashmap.-
Fields inherited from class org.objectweb.joram.client.jms.Message
jmsDest, logger, momMsg, propertiesRO, RObody, session
-
Fields inherited from interface javax.jms.Message
DEFAULT_DELIVERY_DELAY, DEFAULT_DELIVERY_MODE, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE
-
-
Constructor Summary
Constructors Constructor Description MapMessage()Instantiates a bright newMapMessage.MapMessage(Session session, org.objectweb.joram.shared.messages.Message momMsg)Instantiates aMapMessagewrapping a consumed MOM message containing an hashtable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearBody()API method.booleangetBoolean(String name)API method.bytegetByte(String name)API method.byte[]getBytes(String name)API method.chargetChar(String name)API method.doublegetDouble(String name)API method.protected <T> TgetEffectiveBody(Class<T> c)Get message bodyfloatgetFloat(String name)API method.intgetInt(String name)API method.longgetLong(String name)API method.EnumerationgetMapNames()API method.ObjectgetObject(String name)API method.shortgetShort(String name)API method.StringgetString(String name)API method.booleanitemExists(String name)API method.protected voidprepare()Method actually preparing the message for sending by transfering the local body into the wrapped MOM message.voidsetBoolean(String name, boolean value)API method.voidsetByte(String name, byte value)API method.voidsetBytes(String name, byte[] value)API method.voidsetBytes(String name, byte[] value, int offset, int length)API method.voidsetChar(String name, char value)API method.voidsetDouble(String name, double value)API method.voidsetFloat(String name, float value)API method.voidsetInt(String name, int value)API method.voidsetLong(String name, long value)API method.voidsetObject(String name, Object value)API method.voidsetShort(String name, short value)API method.voidsetString(String name, String value)API method.-
Methods inherited from class org.objectweb.joram.client.jms.Message
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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javax.jms.Message
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
-
-
-
-
Constructor Detail
-
MapMessage
MapMessage()
Instantiates a bright newMapMessage.
-
MapMessage
MapMessage(Session session, org.objectweb.joram.shared.messages.Message momMsg) throws MessageFormatException
Instantiates aMapMessagewrapping a consumed MOM message containing an hashtable.- Parameters:
sess- The consuming session.momMsg- The MOM message to wrap.- Throws:
MessageFormatException- In case of a problem when getting the MOM message data.
-
-
Method Detail
-
clearBody
public void clearBody() throws JMSExceptionAPI method. Clears out the message body.Calling this method leaves the message body in the same state as an empty body in a newly created message.
- Specified by:
clearBodyin interfaceMessage- Overrides:
clearBodyin classMessage- Throws:
JMSException- Actually never thrown.
-
setBoolean
public void setBoolean(String name, boolean value) throws JMSException
API method. Sets a boolean value with the specified name into the Map.- Specified by:
setBooleanin interfaceMapMessage- Parameters:
name- the name of the boolean.value- the boolean value to set in the Map- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException
-
setByte
public void setByte(String name, byte value) throws JMSException
API method. Sets a byte value with the specified name into the Map.- Specified by:
setBytein interfaceMapMessage- Parameters:
name- the name of the byte.value- the byte value to set in the Map- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException
-
setBytes
public void setBytes(String name, byte[] value) throws JMSException
API method. Sets a byte array value with the specified name into the Map.- Specified by:
setBytesin interfaceMapMessage- Parameters:
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- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException
-
setBytes
public void setBytes(String name, byte[] value, int offset, int length) throws JMSException
API method. Sets a portion of a byte array value with the specified name into the Map.- Specified by:
setBytesin interfaceMapMessage- Parameters:
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.- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException
-
setChar
public void setChar(String name, char value) throws JMSException
API method. Sets a char value with the specified name into the Map.- Specified by:
setCharin interfaceMapMessage- Parameters:
name- the name of the char.value- the char value to set in the Map- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException
-
setDouble
public void setDouble(String name, double value) throws JMSException
API method. Sets a double value with the specified name into the Map.- Specified by:
setDoublein interfaceMapMessage- Parameters:
name- the name of the double.value- the double value to set in the Map- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException
-
setFloat
public void setFloat(String name, float value) throws JMSException
API method. Sets a float value with the specified name into the Map.- Specified by:
setFloatin interfaceMapMessage- Parameters:
name- the name of the float.value- the float value to set in the Map- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException
-
setInt
public void setInt(String name, int value) throws JMSException
API method. Sets a int value with the specified name into the Map.- Specified by:
setIntin interfaceMapMessage- Parameters:
name- the name of the int.value- the int value to set in the Map- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException
-
setLong
public void setLong(String name, long value) throws JMSException
API method. Sets a long value with the specified name into the Map.- Specified by:
setLongin interfaceMapMessage- Parameters:
name- the name of the long.value- the long value to set in the Map- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException
-
setShort
public void setShort(String name, short value) throws JMSException
API method. Sets a short value with the specified name into the Map.- Specified by:
setShortin interfaceMapMessage- Parameters:
name- the name of the short.value- the short value to set in the Map- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException
-
setString
public void setString(String name, String value) throws JMSException
API method. Sets a String value with the specified name into the Map.- Specified by:
setStringin interfaceMapMessage- Parameters:
name- the name of the String.value- the String value to set in the Map- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException
-
setObject
public void setObject(String name, Object value) throws JMSException
API method. Sets an object alue with the specified name into the Map.This method works only for the objectified primitive object types (Integer, Double, Long ...), String objects, and byte arrays.
- Specified by:
setObjectin interfaceMapMessage- Parameters:
name- the name of the object.value- the Java object value to set in the Map- Throws:
MessageNotWriteableException- If the message body is read-only.MessageFormatException- If the value type is invalid.JMSException
-
getBoolean
public boolean getBoolean(String name) throws JMSException
API method. Returns the boolean value to which the specified key is mapped.- Specified by:
getBooleanin interfaceMapMessage- Parameters:
name- the key whose associated value is to be returned.- Returns:
- the boolean value associated with the specified name.
- Throws:
MessageFormatException- If the value type is invalid.JMSException
-
getByte
public byte getByte(String name) throws JMSException
API method. Returns the byte value to which the specified key is mapped.- Specified by:
getBytein interfaceMapMessage- Parameters:
name- the key whose associated value is to be returned.- Returns:
- the byte value associated with the specified name.
- Throws:
MessageFormatException- If the value type is invalid.JMSException
-
getBytes
public byte[] getBytes(String name) throws JMSException
API method. Returns the byte array value to which the specified key is mapped.- Specified by:
getBytesin interfaceMapMessage- Parameters:
name- the key whose associated value is to be returned.- Returns:
- a copy of the byte array value with the specified name; if there is no item by this name, a null value is returned.
- Throws:
MessageFormatException- If the value type is invalid.JMSException
-
getChar
public char getChar(String name) throws JMSException
API method. Returns the char value to which the specified key is mapped.- Specified by:
getCharin interfaceMapMessage- Parameters:
name- the key whose associated value is to be returned.- Returns:
- the char value associated with the specified name.
- Throws:
MessageFormatException- If the value type is invalid.JMSException
-
getDouble
public double getDouble(String name) throws JMSException
API method. Returns the double value to which the specified key is mapped.- Specified by:
getDoublein interfaceMapMessage- Parameters:
name- the key whose associated value is to be returned.- Returns:
- the double value associated with the specified name.
- Throws:
MessageFormatException- If the value type is invalid.JMSException
-
getFloat
public float getFloat(String name) throws JMSException
API method. Returns the float value to which the specified key is mapped.- Specified by:
getFloatin interfaceMapMessage- Parameters:
name- the key whose associated value is to be returned.- Returns:
- the float value associated with the specified name.
- Throws:
MessageFormatException- If the value type is invalid.JMSException
-
getInt
public int getInt(String name) throws JMSException
API method. Returns the int value to which the specified key is mapped.- Specified by:
getIntin interfaceMapMessage- Parameters:
name- the key whose associated value is to be returned.- Returns:
- the int value associated with the specified name.
- Throws:
MessageFormatException- If the value type is invalid.JMSException
-
getLong
public long getLong(String name) throws JMSException
API method. Returns the long value to which the specified key is mapped.- Specified by:
getLongin interfaceMapMessage- Parameters:
name- the key whose associated value is to be returned.- Returns:
- the long value associated with the specified name.
- Throws:
MessageFormatException- If the value type is invalid.JMSException
-
getObject
public Object getObject(String name) throws JMSException
API method. This method returns in objectified format a java primitive type that had been stored in the Map with the equivalent setObject method call, or its equivalent primitive settype method.- Specified by:
getObjectin interfaceMapMessage- Parameters:
name- the key whose associated value is to be returned.- Returns:
- a copy of the Java object value with the specified name, in objectified format (for example, if the object was set as an int, an Integer is returned); if there is no item by this name, a null value is returned.
- Throws:
JMSException- Actually never thrown.
-
getShort
public short getShort(String name) throws JMSException
API method. Returns the short value to which the specified key is mapped.- Specified by:
getShortin interfaceMapMessage- Parameters:
name- the key whose associated value is to be returned.- Returns:
- the short value associated with the specified name.
- Throws:
MessageFormatException- If the value type is invalid.JMSException
-
getString
public String getString(String name) throws JMSException
API method. Returns the String value to which the specified key is mapped.- Specified by:
getStringin interfaceMapMessage- Parameters:
name- the key whose associated value is to be returned.- Returns:
- the String value associated with the specified name; if there is no item by this name, a null value is returned..
- Throws:
JMSException- Actually never thrown.
-
itemExists
public boolean itemExists(String name) throws JMSException
API method.- Specified by:
itemExistsin interfaceMapMessage- Throws:
JMSException- Actually never thrown.
-
getMapNames
public Enumeration getMapNames() throws JMSException
API method. Returns an Enumeration of all the names in this MapMessage.- Specified by:
getMapNamesin interfaceMapMessage- Returns:
- an enumeration of all the names in this MapMessage.
- Throws:
JMSException- Actually never thrown.
-
prepare
protected void prepare() throws JMSExceptionMethod actually preparing the message for sending by transfering the local body into the wrapped MOM message.- Overrides:
preparein classMessage- Throws:
MessageFormatException- If an error occurs while serializing.JMSException
-
getEffectiveBody
protected <T> T getEffectiveBody(Class<T> c) throws JMSException
Description copied from class:MessageGet message body- Overrides:
getEffectiveBodyin classMessage- Parameters:
c- The type to which the message body will be assigned.- Returns:
- message body
- Throws:
JMSException- if the JMS provider fails to return a value due to some internal error.
-
-