J2ME Wireless Toolkit WMA Bridge API

com.sun.kvem.midp.io.j2se.wma
Class Message

java.lang.Object
  |
  +--com.sun.kvem.midp.io.j2se.wma.Message

public class Message
extends java.lang.Object

A WMA Message. Represents a SMS or CBS message, or a fragment of one.

This message is sent and received via a WMAClient.

Message supports two kinds of text encodings: gsm-7bit and ucs-2.

You can construct a message with more data than will fit into one message fragment. When you send such a message (using WMAClient.send), the message will be broken up into the proper number of fragments.

You can also construct a message and specify its segments and which fragment number this message is. When you send such a message, the message will be sent as-is, without attempting to fragment it.

Messages have two addresses associated with them: the "from" address and the "to" address. The from address is the address from which the message originally was sent, and the to address is the address to which the message is destined. Each address obeys the form "protocol://[+]phoneNum[:port]", where protocol is either "sms" or "cbs". The addresses may or may not contain the port components. CBS messages do not contain from address information at all, and their to address contains no phone number - only a port.

In other words, here are examples of valid SMS "to" and "from" addresses:

- sms://+12345678

- sms://+12345678:910

and this is a valid CBS "to" address:

- cbs://:456


Field Summary
static java.lang.String GSM7BIT_ENCODING
          This text message has GSM-7bit encoding.
static java.lang.String UCS2_ENCODING
          This text message has UCS-2 encoding.
 
Constructor Summary
Message(byte[] data)
          Make a binary message or a text message with a text encoding that you performed already.
Message(com.sun.kvem.midp.io.j2se.wma.common.DatagramRecord rec)
           
Message(java.lang.String text)
          Make a text message.
 
Method Summary
 boolean addPreviousFragment(com.sun.kvem.midp.io.j2se.wma.Message previousFragment)
          Add a previous fragment to the beginning of this fragment.
 int getContentLength()
          Returns the content length in bytes of this message.
 byte[] getData()
          Returns the raw data of the message content.
 int getFragmentNum()
          Returns the fragment number of this message, -1 if it is not part of a segmented message.
 int getFragmentOffset()
          Returns the offset in bytes of this message fragment, or 0 if this is not part of a segmented message.
 int getFragmentSize()
          Returns the size in bytes of this message fragment, or 0 if this is not part of a segmented message.
 java.lang.String getFromAddress()
          Returns the from address of this message, which will be in the format "protocol://[+]phoneNum[:port]", or null if none was set.
 int getFromPort()
          Returns the from port of this message, or -1 if none was set.
 int getNumSegments()
          Returns the number of segments in this message.
 byte[] getRawData()
          Returns the raw data that would be sent to the WMA Server.
 long getSendTime()
          Returns the send time of the message, or 0 if none exists (as in CBS messages).
 java.lang.String getTextEncoding()
          Returns the text encoding of this message, null if it is a binary message.
 java.lang.String getToAddress()
          Returns the to address of this message, which will be in the format "protocol://[+][phoneNum][:port]"
 int getToPort()
          Returns the to port of this message, or -1 if none was set.
 boolean isFragmented()
          Returns true if this message has more than one fragment.
 boolean isSMS()
          Returns true if this is an SMS message, false otherwise.
 boolean isText()
          Returns true if this message contains text data.
 void setContentLength(int len)
          Set the content length of this message.
 void setFragmentNum(int num)
          Set the fragment number of this message.
 void setFragmentOffset(int offset)
          Set the fragment offset of this message.
 void setFragmentSize(int size)
          Set the fragment size of this message.
 void setFromAddress(java.lang.String url)
          Set the from address of the message.
 void setFromPort(int port)
          Set the from port of this message.
 void setNumSegments(int num)
          Set the number of segments in this message.
 void setSendTime(long time)
          Set the send time of the message.
 void setTextEncoding(java.lang.String encoding)
          Set the text encoding for this message.
 void setToAddress(java.lang.String url)
          Set the to address of the message.
 void setToPort(int port)
          Set the to port of this message.
 java.lang.String toString()
          Returns the text of this message if it is text, or a String representation of the payload if it is binary.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GSM7BIT_ENCODING

public static final java.lang.String GSM7BIT_ENCODING
This text message has GSM-7bit encoding.

See Also:
Constant Field Values

UCS2_ENCODING

public static final java.lang.String UCS2_ENCODING
This text message has UCS-2 encoding.

See Also:
Constant Field Values
Constructor Detail

Message

public Message(byte[] data)
Make a binary message or a text message with a text encoding that you performed already.

If it is text content, report the encoding via setTextEncoding.

Note that for GSM7BIT_ENCODING text data each GSM septet should be padded to occupy a full byte.

Parameters:
data - the raw content.
Throws:
java.lang.NullPointerException - the data was null.

Message

public Message(com.sun.kvem.midp.io.j2se.wma.common.DatagramRecord rec)

Message

public Message(java.lang.String text)
Make a text message. The encoding will be performed automatically, and it will attempt to use gsm-7bit first. If the message cannot be encoded with gsm-7bit, then the ucs-2 encoding will be used.

Parameters:
text - the text content.
Throws:
java.lang.NullPointerException - the text was null.
Method Detail

addPreviousFragment

public boolean addPreviousFragment(com.sun.kvem.midp.io.j2se.wma.Message previousFragment)
                            throws java.io.IOException
Add a previous fragment to the beginning of this fragment.

Parameters:
previousFragment - the previous message fragment. Can be null.
Returns:
true when the message is complete.
Throws:
java.io.IOException - the message has arrived out of sequence.

getContentLength

public int getContentLength()
Returns the content length in bytes of this message.

Returns:
the content length in bytes of this message.

getData

public byte[] getData()
Returns the raw data of the message content. If the content is text, it will have the text encoding indicated by getTextEncoding.

Returns:
the raw data of the message content. If the content is text, it will have the text encoding indicated by getTextEncoding.

getFragmentNum

public int getFragmentNum()
Returns the fragment number of this message, -1 if it is not part of a segmented message.

Returns:
the fragment number of this message, -1 if it is not part of a segmented message.

getFragmentOffset

public int getFragmentOffset()
Returns the offset in bytes of this message fragment, or 0 if this is not part of a segmented message.

Returns:
the offset in bytes of this message fragment, or 0 if this is not part of a segmented message.

getFragmentSize

public int getFragmentSize()
Returns the size in bytes of this message fragment, or 0 if this is not part of a segmented message.

Returns:
the size in bytes of this message fragment, or 0 if this is not part of a segmented message.

getFromAddress

public java.lang.String getFromAddress()
Returns the from address of this message, which will be in the format "protocol://[+]phoneNum[:port]", or null if none was set. CBS messages have no from address.

Returns:
the from address of this message, which will be in the format "protocol://[+]phoneNum[:port]", or null if none was set. CBS messages have no from address.

getFromPort

public int getFromPort()
Returns the from port of this message, or -1 if none was set.

Returns:
the from port of this message, or -1 if none was set.

getNumSegments

public int getNumSegments()
Returns the number of segments in this message.

Returns:
the number of segments in this message.

getRawData

public byte[] getRawData()
Returns the raw data that would be sent to the WMA Server.

Returns:
the raw data that would be sent to the WMA Server.

getSendTime

public long getSendTime()
Returns the send time of the message, or 0 if none exists (as in CBS messages).

Returns:
the send time of the message, or 0 if none exists (as in CBS messages).

getTextEncoding

public java.lang.String getTextEncoding()
Returns the text encoding of this message, null if it is a binary message.

Returns:
the text encoding of this message, null if it is a binary message.

getToAddress

public java.lang.String getToAddress()
Returns the to address of this message, which will be in the format "protocol://[+][phoneNum][:port]"

Returns:
the to address of this message, which will be in the format "protocol://[+][phoneNum][:port]"

getToPort

public int getToPort()
Returns the to port of this message, or -1 if none was set.

Returns:
the to port of this message, or -1 if none was set.

isFragmented

public boolean isFragmented()
Returns true if this message has more than one fragment.

Returns:
true if this message has more than one fragment, false otherwise.

isSMS

public boolean isSMS()
Returns true if this is an SMS message, false otherwise. This could be a CBS message.

Returns:
true if this is an SMS message, false otherwise.

isText

public boolean isText()
Returns true if this message contains text data.

Returns:
true if this message contains text data, false otherwise.

setContentLength

public void setContentLength(int len)
Set the content length of this message. You need to set this only if this a part of a multi-segment message.

Parameters:
len - the content length in bytes.

setFragmentNum

public void setFragmentNum(int num)
Set the fragment number of this message. You need to set this only if this message has more than one fragment.

Parameters:
num - the fragment number of this message.

setFragmentOffset

public void setFragmentOffset(int offset)
Set the fragment offset of this message. You need to set this only if this message has more than one segment.

Parameters:
offset - the offset in bytes of this message fragment.

setFragmentSize

public void setFragmentSize(int size)
Set the fragment size of this message. You need to set this only if this message has more than one segment.

Parameters:
size - the size in bytes of this message fragment.

setFromAddress

public void setFromAddress(java.lang.String url)
Set the from address of the message.

Parameters:
url - the to address. This must follow the format "protocol://[+]phoneNum[:port]".

setFromPort

public void setFromPort(int port)
Set the from port of this message. This method will replace the ":port" section of the from address.

Parameters:
port - the from port.

setNumSegments

public void setNumSegments(int num)
Set the number of segments in this message. You need to set this only if this is a part of a multi-segment message.

Parameters:
num - the number of segments in this message.

setSendTime

public void setSendTime(long time)
Set the send time of the message.

Parameters:
time - the send time

setTextEncoding

public void setTextEncoding(java.lang.String encoding)
Set the text encoding for this message.

Parameters:
encoding - the encoding. This must be either Message.GSM7BIT_ENCODING or Message.UCS2_ENCODING.
Throws:
java.lang.IllegalArgumentException - the requested encoding is not supported.
java.lang.NullPointerException - the encoding was null.

setToAddress

public void setToAddress(java.lang.String url)
Set the to address of the message.

Parameters:
url - the to address. This must follow the format "protocol://[+][phoneNum][:port]". CBS messages have no phoneNum component.

setToPort

public void setToPort(int port)
Set the to port of this message. This method will replace the ":port" section of the to address.

Parameters:
port - the to port.

toString

public java.lang.String toString()
Returns the text of this message if it is text, or a String representation of the payload if it is binary. Binary content is represented as a string of hexadecimal digits.

Overrides:
toString in class java.lang.Object
Returns:
the text of this message if it is text, or a String representation of the payload if it is binary

J2ME Wireless Toolkit WMA Bridge API

Submit feedback to j2mewtk-comments@sun.com.
Copyright © 2003 Sun Microsystems, Inc. All rights reserved.