com.objectxp.msg
Class Message

java.lang.Object
  extended bycom.objectxp.msg.Message
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
SmsMessage, SmtpMessage

public class Message
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

This class represents a generic Message. The message may be sent using various transport mechanisms (e.g. SMTP, GSM).

See Also:
SmtpMessage, SmsMessage, Serialized Form

Field Summary
static java.lang.String ACK_TIME
          See getProperty(String key) for more information
static int MT_BINARY
          Message type: binary data
static int MT_STATUS
          Message type: Status report.
static int MT_TEXT
          Message type: text (Default)
static int SENDER_TYPE_ALPHA
          Sender address is alphanumeric
static int SENDER_TYPE_GUESS
          Type (numeric/alphanumeric) of sender address will be guessed
static int SENDER_TYPE_NUMBER
          Sender address is a numeric
 
Constructor Summary
Message()
          Creates an empty message
 
Method Summary
 java.lang.Object clone()
          Returns an exact copy of the Message
 byte[] getBytes()
          Get the raw message data.
 java.lang.String getID()
          Returns the ID of this message.
 java.lang.String getMessage()
          Get the message body.
 java.lang.Object getProperty(java.lang.String key)
          Returns the value of the specified key that is associated with this message.
 java.lang.String getRecipient()
          Get the recipient of this message.
 java.lang.String getSender()
          Get the sender of this message.
 int getSenderType()
          Returns the Type of sender address.
 java.util.Date getTimestamp()
          Get the date where the message was sent / received.
 int getType()
          Returns the message type.
 void setID(java.lang.String id)
          Set the ID of the Message.
 void setMessage(byte[] bytes)
          Set the message data.
 void setMessage(java.lang.String message)
          Set the message body.
 java.lang.Object setProperty(java.lang.String key, java.lang.Object value)
          Associate a key/value pair with this message.
 void setRecipient(java.lang.String recipient)
          Set the recipient for this message.
 void setSender(java.lang.String sender)
          Set the sender of this message.
 void setSenderType(int type)
          Set the type of the sender address.
 void setType(int type)
          Set the message type.
 java.lang.String toString()
          Constructs a string representation of this Message
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MT_TEXT

public static final int MT_TEXT
Message type: text (Default)

See Also:
Constant Field Values

MT_BINARY

public static final int MT_BINARY
Message type: binary data

See Also:
Constant Field Values

MT_STATUS

public static final int MT_STATUS
Message type: Status report.

See Also:
Constant Field Values

SENDER_TYPE_ALPHA

public static final int SENDER_TYPE_ALPHA
Sender address is alphanumeric

See Also:
Constant Field Values

SENDER_TYPE_NUMBER

public static final int SENDER_TYPE_NUMBER
Sender address is a numeric

See Also:
Constant Field Values

SENDER_TYPE_GUESS

public static final int SENDER_TYPE_GUESS
Type (numeric/alphanumeric) of sender address will be guessed

See Also:
Constant Field Values

ACK_TIME

public static final java.lang.String ACK_TIME
See getProperty(String key) for more information

See Also:
Constant Field Values
Constructor Detail

Message

public Message()
Creates an empty message

Method Detail

getID

public java.lang.String getID()
Returns the ID of this message.

Returns:
the Message ID or null if the Message has no ID associated.
Since:
jSMS 1.6

setID

public void setID(java.lang.String id)
Set the ID of the Message. Please notice that most SmsService implementations override this ID after sending the Message with the ID received from the SMSC or GSM device.

Parameters:
id - the Message ID to set
Since:
jSMS 1.6

setType

public void setType(int type)
Set the message type. The type can be either MT_TEXT (default) or MT_BINARY. If the type is set to MT_BINARY, this insures that the message will be sent "as is" (e.g. no character conversion takes place).

Parameters:
type - the type of message (MT_TEXT or MT_BINARY)
Throws:
java.lang.IllegalArgumentException - if an invalid type is specified

getType

public int getType()
Returns the message type. For received messages, this method will always return MT_TEXT (The original (raw) data may be accessed by calling getBytes()).


setRecipient

public void setRecipient(java.lang.String recipient)
Set the recipient for this message. The recipient must be in a format useable by the transport mechanism.

Parameters:
recipient - address of the recipient

getRecipient

public java.lang.String getRecipient()
Get the recipient of this message.

Returns:
the recipient

getSender

public java.lang.String getSender()
Get the sender of this message.

Returns:
the adress of the sender

setSender

public void setSender(java.lang.String sender)
Set the sender of this message.


getMessage

public java.lang.String getMessage()
Get the message body.

Returns:
the message body.

getBytes

public byte[] getBytes()
Get the raw message data.


setMessage

public void setMessage(java.lang.String message)
Set the message body.

Parameters:
message - the message.

setMessage

public void setMessage(byte[] bytes)
Set the message data. When calling this method, the message type will be automatically set to MT_BINARY. To override this behaviour you have to subsequently call setType()

Parameters:
bytes - the raw message data.

getProperty

public java.lang.Object getProperty(java.lang.String key)
Returns the value of the specified key that is associated with this message.

Use the key ACK_TIME to get the time it took for the SMSC to acknowledge a sent SMS. The value returned for ACK_TIME is of type Long.

Since:
jSMS 1.5.6-8

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    java.lang.Object value)
Associate a key/value pair with this message. Notice that these properties have no influence at all on the way jSMS handles the message but could e.g. be used to attach a customer-specific ID to a message.

Returns:
the previous value for this key or null.
Since:
jSMS 1.5.6-8

getTimestamp

public java.util.Date getTimestamp()
Get the date where the message was sent / received.


clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns an exact copy of the Message

Throws:
java.lang.CloneNotSupportedException

toString

public java.lang.String toString()
Constructs a string representation of this Message


setSenderType

public void setSenderType(int type)
                   throws java.lang.IllegalArgumentException
Set the type of the sender address. For SmsService implementations supporting alphanumeric originators, you can specify how jSMS should interpret the sender address of this message. Possible types are alphanumeric, numeric or the special type "guess", where jSMS decides by itself if the sender address is numeric or alphanumeric. The default for new Messages is "guess".

Notice: The GsmSmsService does not support alphanumeric originators, therefore setting the sender type has no effect for Messages sent through GsmSmsService.

Parameters:
type - the address type. Allowed parameters are: SENDER_TYPE_ALPHA, SENDER_TYPE_NUMBER, SENDER_TYPE_GUESS.
Throws:
java.lang.IllegalArgumentException

getSenderType

public int getSenderType()
Returns the Type of sender address. Possible return values are SENDER_TYPE_ALPHA, SENDER_TYPE_NUMBER or SENDER_TYPE_GUESS.

Returns:
the sender type
Since:
jSMS 1.6


object XP, Inc. © 2000-2007. All rights reserved object XP