com.nmt.mgp
Class Message

java.lang.Object
  extended by com.nmt.mgp.Message

public class Message
extends java.lang.Object

A message with a list of options, to be sent via MGP to the EMG Server. The message text is hex encoded for safe transportation.


Constructor Summary
Message()
          Create a new message.
Message(java.io.BufferedReader in)
          Create a new message.
Message(OptionHolder options)
          Create a new message.
Message(java.lang.String destaddr)
          Create a basic message with destaddr.
Message(java.lang.String destaddr, char[] data)
          Create a basic text message with binary data.
Message(java.lang.String destaddr, java.lang.String text)
          Create a basic text message.
 
Method Summary
 void addHex(java.lang.String hex)
          Add message data which is already hex encoded.
 void addOption(MgpOption option)
          Add an option to this message.
 void addText(char[] data)
          Add binary message data to this message.
 void addText(java.lang.String text)
          Adds message text to this message.
 void addUdh(char[] udh)
          Add a UDH (User Data Header) to message.
 void deleteOption(MgpOption option)
          Delete a specific MGP option from message.
 boolean equals(Message msg)
          Compare this messge with another.
 int getId()
          Gets the message id.
 OptionHolder getOptions()
          Returns the message options.
 void load(java.io.BufferedReader in)
          Loads the message options from an input stream.
 void save(java.io.BufferedWriter out)
          Saves the message options to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Message

public Message()
Create a new message.


Message

public Message(OptionHolder options)
Create a new message.


Message

public Message(java.io.BufferedReader in)
        throws java.io.IOException
Create a new message.

Throws:
java.io.IOException

Message

public Message(java.lang.String destaddr,
               java.lang.String text)
Create a basic text message.

Parameters:
destaddr - the destination address, stored as the option Mgp.MGP_OPTION_DESTADDR
text - the message text, stored as the option Mgp.MGP_OPTION_MESSAGE

Message

public Message(java.lang.String destaddr,
               char[] data)
Create a basic text message with binary data.

Parameters:
destaddr - the destination address, stored as the option Mgp.MGP_OPTION_DESTADDR
data - the message text, stored as the option Mgp.MGP_OPTION_MESSAGE

Message

public Message(java.lang.String destaddr)
Create a basic message with destaddr.

Parameters:
destaddr - the destination address, stored as the option Mgp.MGP_OPTION_DESTADDR
Method Detail

getOptions

public OptionHolder getOptions()
Returns the message options.


addOption

public void addOption(MgpOption option)
Add an option to this message.


addText

public void addText(java.lang.String text)
Adds message text to this message. Sets the character code for the message to MGP_CHARCODE_DEFAULT.


addText

public void addText(char[] data)
Add binary message data to this message. Sets the character code for message to MGP_CHARCODE_8BIT.


addHex

public void addHex(java.lang.String hex)
Add message data which is already hex encoded. Sets the character code for this message to MGP_CHARCODE_8BIT.


addUdh

public void addUdh(char[] udh)
Add a UDH (User Data Header) to message.


deleteOption

public void deleteOption(MgpOption option)
Delete a specific MGP option from message.


getId

public int getId()
Gets the message id. The MGP option MGP_OPTION_ID is located and converted to an integer.

Returns:
The integer value, or -1 if the option isn't found or can't be converted to an integer.

equals

public boolean equals(Message msg)
Compare this messge with another. Only the message id's are compared.

Returns:
true if and only if the message id's are equal and not equal to -1.
See Also:
getId()

load

public void load(java.io.BufferedReader in)
          throws java.io.IOException
Loads the message options from an input stream.

Parameters:
in - the input stream, already opened
Throws:
java.io.IOException - if an error occurs while reading

save

public void save(java.io.BufferedWriter out)
          throws java.io.IOException
Saves the message options to an output stream.

Parameters:
out - the output stream, already initiated
Throws:
java.io.IOException - if an error occurs while writing