FileDocCategorySizeDatePackage
MessageObject.javaAPI DocphoneME MR2 API (J2ME)5520Wed May 02 18:00:32 BST 2007com.sun.midp.io.j2me.sms

MessageObject

public class MessageObject extends Object implements Message
Implements a SMS message for the SMS message connection.

This class contains methods for manipulating message objects and their contents. Messages can be composed of data and an address. MessageObject contains methods that can get and set the data and the address parts of a message separately. The data part can be either text or binary format. The address part has the format:

sms://[phone_number:][port_number]

and represents the address of a port that can accept or receive SMS messages.

Port numbers are used to designate a specific application or communication channel for messages. When the port number is omitted from the address, then the message is targeted at the end user and their normal mailbox handling application. In this case, the JSR120 MessageConnection cannot be used to receive an inbound message to the user mailbox.

A well-written application would always check the number of segments that would be used before sending a message, since the user is paying for each SMS message transferred and not just the fixed rate per high-level message sent.

Instantiating and Freeing MessageObjects

MessageObjects are instantiated when they are received from the {@link javax.wireless.messaging.MessageConnection MessageConnection} or by using the {@link MessageConnection#newMessage(String type) MessageConnection.newMessage} message factory. Instances are freed when they are garbage collected or when they go out of scope.

Fields Summary
String
messtype
High level message type.
String
messaddr
High level message address.
long
sentAt
Timestamp when the message was sent.
Constructors Summary
public MessageObject(String type, String addr)
Creates a Message object without a buffer.

param
type text or binary message type.
param
addr the destination address of the message.

	messtype = type;
	messaddr = addr;


    
Methods Summary
public java.lang.StringgetAddress()
Gets the address from the message object as a String. If no address is found in the message, this method returns null. If the method is applied to an inbound message, the source address is returned. If it is applied to an outbound message, the destination addess is returned.

The following code sample retrieves the address from a received message.

...
Message msg = conn.receive();
String addr = msg.getAddress();
...

return
the address in string form, or null if no address was set
see
#setAddress

	return messaddr;
    
public java.util.DategetTimestamp()
Returns the timestamp indicating when this message has been sent.

return
the date indicating the timestamp in the message or null if the timestamp is not set
see
#setTimeStamp

        if (sentAt == 0) {
            return null;
        }
	return new Date(sentAt); 
    
public voidsetAddress(java.lang.String addr)
Sets the address part of the message object. The address is a String and should be in the format:

sms://[phone_number:][port]

The following code sample assigns an SMS URL address to the Message object.

...
String addr = "sms://+358401234567";
Message msg = newMessage(TEXT_MESSAGE);
msg.setAddress(addr);
...

param
addr the address of the target device
see
#getAddress


	messaddr = addr;
    
public voidsetTimeStamp(long timestamp)
Sets the timestamp for inbound SMS messages.

param
timestamp the date indicating the timestamp in the message
see
#getTimestamp

	sentAt = timestamp;