FileDocCategorySizeDatePackage
MessageObject.javaAPI DocphoneME MR2 API (J2ME)5259Wed May 02 18:00:32 BST 2007com.sun.tck.wma.sms

MessageObject

public class MessageObject extends Object implements com.sun.tck.wma.Message
A message for a message connection, composed of an address and data. There are get and set methods for manipulating the address and data components of the message. The data part can be the text, binary or multipart format. The address part assumes this format:

protocol://[phone_number:][port_number/ID]

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

MessageObjects are instantiated when they are received from the {@link com.sun.tck.wma.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
protected String
msgType
High-level message type.
protected String
msgAddress
High-level message address.
protected long
sentAt
The time stamp, indicating when the message was sent.
Constructors Summary
public MessageObject(String type, String address)
Creates a Message object without a buffer.

param
type The message type: TEXT, BINARY or MULTIPART.
param
address The destination address of the message.


                                 
         
	setType(type);
	setAddress(address);
    
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 address 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 msgAddress;
    
public java.util.DategetTimestamp()
Returns the timestamp indicating when this message has been sent.

return
Date indicating the time stamp in the message or null if the time stamp was not set.
see
#setTimeStamp

        return new Date(sentAt);
    
public java.lang.StringgetType()
Gets the message type.

return
The current message type or null if no message type has been set.

        return msgType;
    
public voidsetAddress(java.lang.String address)
Sets the address part of the message object. The address is a String and must be in the format: protocol://phone_number:[port] The following code sample assigns an address to the Message object.
...
String addr = "protocol://+123456789";
Message msg = newMessage(MessageConnection.TEXT_MESSAGE);
msg.setAddress(addr);
...

param
address The address of the target device.
throws
IllegalArgumentException if the address is not valid.
see
#getAddress


        msgAddress = address;
    
public voidsetTimeStamp(long timestamp)
Sets the timestamp for inbound SMS messages.

param
timestamp The time stamp in the message.
see
#getTimeStamp

	sentAt = timestamp;
    
public voidsetType(java.lang.String type)
Sets the message type.

param
type The message type: TEXT, BINARY or MULTIPART.
exception
IllegalArgumentException if the type is not valid.

        if (type == null) {
            throw new IllegalArgumentException("Null message type.");
        }
        msgType = type;