Class MapMessage

  • All Implemented Interfaces:
    MapMessage, Message

    public final class MapMessage
    extends Message
    implements MapMessage
    Implements the 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.

    • Constructor Detail

      • MapMessage

        MapMessage()
        Instantiates a bright new MapMessage.
      • MapMessage

        MapMessage​(Session session,
                   org.objectweb.joram.shared.messages.Message momMsg)
            throws MessageFormatException
        Instantiates a MapMessage wrapping 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 JMSException
        API 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:
        clearBody in interface Message
        Overrides:
        clearBody in class Message
        Throws:
        JMSException - Actually never thrown.
      • 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:
        setBytes in interface MapMessage
        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:
        setBytes in interface MapMessage
        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
      • 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:
        setObject in interface MapMessage
        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:
        getBoolean in interface MapMessage
        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:
        getByte in interface MapMessage
        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:
        getBytes in interface MapMessage
        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:
        getChar in interface MapMessage
        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:
        getDouble in interface MapMessage
        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:
        getFloat in interface MapMessage
        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:
        getInt in interface MapMessage
        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:
        getLong in interface MapMessage
        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:
        getObject in interface MapMessage
        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:
        getShort in interface MapMessage
        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:
        getString in interface MapMessage
        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.
      • getMapNames

        public Enumeration getMapNames()
                                throws JMSException
        API method. Returns an Enumeration of all the names in this MapMessage.
        Specified by:
        getMapNames in interface MapMessage
        Returns:
        an enumeration of all the names in this MapMessage.
        Throws:
        JMSException - Actually never thrown.
      • getEffectiveBody

        protected <T> T getEffectiveBody​(Class<T> c)
                                  throws JMSException
        Description copied from class: Message
        Get message body
        Overrides:
        getEffectiveBody in class Message
        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.