com.objectxp.msg
Class SmsMessage

java.lang.Object
  extended by com.objectxp.msg.Message
      extended by com.objectxp.msg.SmsMessage
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
Cimd2Message, EMSMessage, MultipleRecipientMessage, OTAMessage, SEOMessage, SmartMessage, SmppMessage, StatusReportMessage, UcpMessage

public class SmsMessage
extends Message

This class extends the generic Message class with SMS specific attributes. It supports features like specifying the validity period or the Data Coding scheme (defines the character set, message class, etc.).

A SmsMessage consists of User Data (UD) and possibly may also contain a User Data Header (UDH). The User Data Header may be used for e.g. sending Multipart-Messages.

See the GSM 03.38 and GSM 03.40 specifications available at ETSI for further information.

See Also:
Message, Serialized Form

Field Summary
static short CLASS_0
          Message class 0
static short CLASS_1
          Message class 1 (default, ME-specific)
static short CLASS_2
          Message class 2 (SIM specific message)
static short CLASS_3
          Message class 3 (Default meaning: TE-specific)
static short DC_8BIT
          Data coding: 8bit data
static short DC_DEFAULT
          Data coding: 7bit default GSM alphabet
static short DC_GROUP_DATA
          Data Coding Group (default)
static short DC_GROUP_GENERAL
          General Coding Group
static short DC_GROUP_MSG_WAITING_DISCARD
          Message Waiting Indication Group: Discard Message
static short DC_GROUP_MSG_WAITING_STORE
          Message Waiting Indication Group: Store Message
static short DC_UCS2
          Data coding: Unicode (UCS2)
static short INDICATION_ACTIVE
          Message Waiting Indication Active (default)
static short INDICATION_INACTIVE
          Message Waiting Indication Inactive
static short INDICATION_TYPE_EMAIL
          Message Waiting Indication Type: Electronic Mail Message Waiting
static short INDICATION_TYPE_FAX
          Message Waiting Indication Type: Fax Message Waiting
static short INDICATION_TYPE_OTHER
          Message Waiting Indication Type: Other Message Waiting (default)
static short INDICATION_TYPE_VOICEMAIL
          Message Waiting Indication Type: Voicemail Message Waiting
static short NO_CLASS
          Message class undefined (no class indication)
 
Fields inherited from class com.objectxp.msg.Message
ACK_TIME, MT_BINARY, MT_STATUS, MT_TEXT, SENDER_TYPE_ALPHA, SENDER_TYPE_GUESS, SENDER_TYPE_NUMBER
 
Constructor Summary
SmsMessage()
          Construct a new SmsMessage.
SmsMessage(SmsService service)
          Deprecated. since jSMS 1.7, use SmsMessage()
 
Method Summary
 boolean containsUserDataHeader()
          Test if the Message contains a User Data Header.
 void copyFields(SmsMessage message)
          Copy all public fields from a message.
 short getAlphabet()
          Returns the alphabet used for this message.
 byte[] getBytes()
          Get the message data.
 short getCodingGroup()
          Get the Coding Group for this Message.
 java.util.Date getDeferredDeliveryAsDate()
          Get the absolute deferred delivery date.
 int getDeferredDeliveryInMinutes()
          Return the deferred delivery date in minutes.
 java.lang.String getID()
          Returns the ID of this message.
 short getIndicationState()
          Get the Message Waiting Indication state.
 short getIndicationType()
          Get the Message Waiting Indication Type.
 java.lang.String getMessage()
          Get the Message (User Data) as String.
 short getMessageClass()
          Get the class of this message.
 SmsMessage getParent()
          Returns the parent (originating) message for this SMS.
 short getPID()
          Returns the protocol identifier (TP-PID) for this message.
 java.lang.String getRecipient()
          Get the recipient of this message.
 Address getRecipientAddress()
          Returns the recipient address or null if unset.
 java.lang.String getSender()
          Get the sender of this message.
 Address getSenderAddress()
          Returns the sender address or null if unset.
 int getType()
          Get the type of this message.
 byte[] getUserData()
          Get the User Data of this message.
 byte[] getUserDataHeader()
          Get the User Data Header for this message.
 java.util.Date getValidityPeriodAsDate()
          Get the absolute message validity period.
 int getValidityPeriodInMinutes()
          Return the Message validity period in minutes.
 boolean hasDeferredDelivery()
          Test if the Message has set a deferred delivery time.
 boolean hasMessageClass()
          Returns true if the Message has no Class associated, false otherwise.
 boolean hasValidityPeriod()
          Test if the Message contains a validity period
 boolean isCompressed()
          Test if the GSM compression flag is turned on
 boolean isMMS()
          Returns true if the More Messages to Send (MMS) flag ist set for this message.
 boolean isRejectDuplicates()
          Returns true if duplicate short messages should be rejected by the SMSC, false otherwise.
 boolean isRelativeDeferredDelivery()
          Test if the deferred delivery date is relative.
 boolean isRelativeValidityPeriod()
          Test if the Validity Period is relative.
 boolean isReplyPath()
          Returns the state of the reply path (TP-RP) bit field.
 boolean requestStatusReport()
          Test if a status report will be requested.
 void requestStatusReport(boolean value)
          Request a status report (notification).
 void setAlphabet(short alpha)
          Set the alphabet for this message.
 void setCodingGroup(short group)
          Set the Coding Group to use (see GSM 03.38).
 void setCompression(boolean c)
          Enable / disable the GSM Compression flag.
 void setDeferredDelivery(java.util.Date deferredDelivery)
          Set a deferred delivery date for this message.
 void setDeferredDelivery(int minutes)
          Set a deferred delivery date for this message.
 void setIndicationState(short indication)
          Set Message Waiting Indication state (active/inactive).
 void setIndicationType(short type)
          Set the Message Waiting Indication Type.
 void setMessage(byte[] bytes)
          Convenience method for setting the User Data.
 void setMessage(java.lang.String msg)
          Convenience method for setting the User Data.
 void setMessageClass(short cls)
          Set the class of this message.
 void setMMS(boolean mms)
          Set the More Messages to Send (MMS) flag.
 void setParent(SmsMessage parent)
          Used by MultiPartMessage implementations to link this SMS with the originating MultiPartMessage.
 void setPID(short pid)
          Set the GSM TP-PID (Protocol Identifier) octet.
 void setRecipient(java.lang.String recipient)
          Set the recipient for this message.
 void setRecipientAddress(Address addr)
          Set/clear the recipient address of this message.
 void setRejectDuplicates(boolean rd)
          Instruct the SMSC to accept or reject a short message (SM) still held in the SMSC which has the same message ID and the same destination address as a previously submitted SM from the same OA.
 void setReplyPath(boolean rp)
          Set/Clear the reply path (TP-RP) bit field for this message.
 void setSender(java.lang.String sender)
          Set the sender of this message.
 void setSenderAddress(Address addr)
          Set/clear the sender of this message.
 void setType(int type)
          Set the type of message.
 void setUserData(byte[] data)
          Set or clear the User Data for this message.
 void setUserDataHeader(boolean u)
          Use this method for controlling the User Data Header Indication (UDHI).
 void setUserDataHeader(byte[] header)
          Set or clear the User Data Header (UDH).
 void setValidityPeriod(java.util.Date validTill)
          Set the absolute validity period for this message.
 void setValidityPeriod(int minutes)
          Set the relative validity period for this message.
 java.lang.String toString()
          Constructs a string representation of this Message
 
Methods inherited from class com.objectxp.msg.Message
clone, getProperty, getSenderType, getTimestamp, setID, setProperty, setSenderType
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_CLASS

public static final short NO_CLASS
Message class undefined (no class indication)

See Also:
Constant Field Values

CLASS_0

public static final short CLASS_0
Message class 0

See Also:
Constant Field Values

CLASS_1

public static final short CLASS_1
Message class 1 (default, ME-specific)

See Also:
Constant Field Values

CLASS_2

public static final short CLASS_2
Message class 2 (SIM specific message)

See Also:
Constant Field Values

CLASS_3

public static final short CLASS_3
Message class 3 (Default meaning: TE-specific)

See Also:
Constant Field Values

DC_DEFAULT

public static final short DC_DEFAULT
Data coding: 7bit default GSM alphabet

See Also:
Constant Field Values

DC_8BIT

public static final short DC_8BIT
Data coding: 8bit data

See Also:
Constant Field Values

DC_UCS2

public static final short DC_UCS2
Data coding: Unicode (UCS2)

See Also:
Constant Field Values

DC_GROUP_GENERAL

public static final short DC_GROUP_GENERAL
General Coding Group

See Also:
Constant Field Values

DC_GROUP_DATA

public static final short DC_GROUP_DATA
Data Coding Group (default)

See Also:
Constant Field Values

DC_GROUP_MSG_WAITING_DISCARD

public static final short DC_GROUP_MSG_WAITING_DISCARD
Message Waiting Indication Group: Discard Message

See Also:
Constant Field Values

DC_GROUP_MSG_WAITING_STORE

public static final short DC_GROUP_MSG_WAITING_STORE
Message Waiting Indication Group: Store Message

See Also:
Constant Field Values

INDICATION_ACTIVE

public static final short INDICATION_ACTIVE
Message Waiting Indication Active (default)

See Also:
Constant Field Values

INDICATION_INACTIVE

public static final short INDICATION_INACTIVE
Message Waiting Indication Inactive

See Also:
Constant Field Values

INDICATION_TYPE_VOICEMAIL

public static final short INDICATION_TYPE_VOICEMAIL
Message Waiting Indication Type: Voicemail Message Waiting

See Also:
Constant Field Values

INDICATION_TYPE_FAX

public static final short INDICATION_TYPE_FAX
Message Waiting Indication Type: Fax Message Waiting

See Also:
Constant Field Values

INDICATION_TYPE_EMAIL

public static final short INDICATION_TYPE_EMAIL
Message Waiting Indication Type: Electronic Mail Message Waiting

See Also:
Constant Field Values

INDICATION_TYPE_OTHER

public static final short INDICATION_TYPE_OTHER
Message Waiting Indication Type: Other Message Waiting (default)

See Also:
Constant Field Values
Constructor Detail

SmsMessage

public SmsMessage(SmsService service)
           throws java.lang.IllegalArgumentException
Deprecated. since jSMS 1.7, use SmsMessage()

Construct a new SmsMessage.

Parameters:
service - the SmsService used to send this message
Throws:
java.lang.IllegalArgumentException - if the service is null

SmsMessage

public SmsMessage()
Construct a new SmsMessage.

Method Detail

setMessageClass

public void setMessageClass(short cls)
                     throws java.lang.IllegalArgumentException
Set the class of this message. The message class only has meaning for messages using either the General Coding Group or the Data Coding Group.

Parameters:
cls - the message class (NO_CLASS, CLASS_0, CLASS_1, CLASS_2, CLASS_3)
Throws:
java.lang.IllegalArgumentException - if an invalid class is used
See Also:
setCodingGroup(short)

getMessageClass

public short getMessageClass()
Get the class of this message.

Returns:
the message class (NO_CLASS, CLASS_0, CLASS_1, CLASS_2, CLASS_3)

hasMessageClass

public boolean hasMessageClass()
Returns true if the Message has no Class associated, false otherwise.

See Also:
setMessageClass(short)

setAlphabet

public void setAlphabet(short alpha)
                 throws java.lang.IllegalArgumentException
Set the alphabet for this message. When the alphabet is set to DC_DEFAULT, jSMS will perform SMS Point-to-Point (7 bit) packing of the user data before sending the message.

Notice
The alphabet allowed for sending the message depends on the current coding group:

If you specify Unicode Alphabet (DC_UCS2) and the current coding group is set to DC_GROUP_DATA, setAlphabet() will automatically set the coding group to DC_GROUP_GENERAL since Unicode is not applicable for the DATA coding group.

If you try to use an alphabet not allowed for the message coding group, you may get unexpected results.

Parameters:
alpha - the alphabet (DC_DEFAULT,DC_8BIT, DC_UCS2)
Throws:
java.lang.IllegalArgumentException - if an invalid alphabet has been specified
See Also:
setCodingGroup(short)

getAlphabet

public short getAlphabet()
Returns the alphabet used for this message.

See Also:
DC_DEFAULT, DC_8BIT, DC_UCS2

getUserDataHeader

public byte[] getUserDataHeader()
Get the User Data Header for this message.

Returns:
the User Data header or null if the header is not present

setUserDataHeader

public void setUserDataHeader(byte[] header)
Set or clear the User Data Header (UDH). The User Data Header Indication (see setUserDataHeader(boolean) will set set / cleared as well.

The header must be formatted according to the GSM 03.40 specification. It may contain 1-n header elements. The first octet of the array must contain the length of the header excluding the first octet (length of byte array minus one).

A Header element has the following structure:

FIELDLENGTH
Information-Element-Identifier "A"1 octet
Length of Information-Element "A"1 octet
Information-Element "A" Data0 to "n" octets

See the GSM 03.40 specification for more information about the UDH.

Parameters:
header - the header data as byte array or null to clear the header

getUserData

public byte[] getUserData()
Get the User Data of this message.

Returns:
the user data or null if the message contains no user data

setMessage

public void setMessage(byte[] bytes)
Convenience method for setting the User Data. Calling this method will also set the alphabet to DC_8BIT.

Overrides:
setMessage in class Message
Parameters:
bytes - the user data as byte array
See Also:
setUserData(byte[])

getType

public int getType()
Get the type of this message.

Overrides:
getType in class Message
Returns:

setMessage

public void setMessage(java.lang.String msg)
Convenience method for setting the User Data. Calling this method will also set the alphabet to DC_DEFAULT.

Overrides:
setMessage in class Message
Parameters:
msg - the message text.

getMessage

public java.lang.String getMessage()
Get the Message (User Data) as String.

Overrides:
getMessage in class Message
Returns:
the User Data converted to a String object.
See Also:
getUserData()

getBytes

public byte[] getBytes()
Get the message data. This method is a synonym for getUserData().

Overrides:
getBytes in class Message
Returns:
a byte array containing the user data or null if no user data is present.
See Also:
getUserData()

setUserData

public void setUserData(byte[] data)
Set or clear the User Data for this message.

Parameters:
data - the user data as byte array or null to clear the user data.

setCompression

public void setCompression(boolean c)
Enable / disable the GSM Compression flag.
jSMS currently doesn't contain GSM compression algorithms,therefore you have to compress the user data yourself.

Notice: This flag only has a meaning if you set the Coding Group to DC_GROUP_GENERAL.

See Also:
setCodingGroup(short)

isCompressed

public boolean isCompressed()
Test if the GSM compression flag is turned on


setIndicationState

public void setIndicationState(short indication)
                        throws java.lang.IllegalArgumentException
Set Message Waiting Indication state (active/inactive). This property only has meaning if the Coding Group is set to either DC_GROUP_MSG_WAITING_DISCARD or DC_GROUP_MSG_WAITING_STORE.

Parameters:
indication - the indication state (either INDICATION_ACTIVE or INDICATION_INACTIVE)
Throws:
java.lang.IllegalArgumentException
See Also:
setCodingGroup(short)

getIndicationState

public short getIndicationState()
Get the Message Waiting Indication state.

See Also:
setIndicationState(short)

setIndicationType

public void setIndicationType(short type)
                       throws java.lang.IllegalArgumentException
Set the Message Waiting Indication Type. This property only has meaning if the Coding Group is set to either DC_GROUP_MSG_WAITING_DISCARD or DC_GROUP_MSG_WAITING_STORE.

Parameters:
type - the indication type (INDICATION_TYPE_VOICEMAIL, INDICATION_TYPE_FAX, INDICATION_TYPE_EMAIL, INDICATION_TYPE_OTHER)
Throws:
java.lang.IllegalArgumentException
See Also:
setCodingGroup(short)

getIndicationType

public short getIndicationType()
Get the Message Waiting Indication Type.

See Also:
setIndicationType(short)

setCodingGroup

public void setCodingGroup(short group)
Set the Coding Group to use (see GSM 03.38). Possible values are:

Parameters:
group - the Coding Group

getCodingGroup

public short getCodingGroup()
Get the Coding Group for this Message.

Returns:
the Coding Group
See Also:
setCodingGroup(short)

setType

public void setType(int type)
Set the type of message. Calling this method will set the message class to CLASS_1. When passing MT_BINARY, the alphabet will be set to DC_8BIT. When passing MT_TEXT, the data coding scheme will be set to DC_DEFAULT (7bit).

Overrides:
setType in class Message
Parameters:
type - the type of message (MT_TEXT or MT_BINARY)
See Also:
setAlphabet(short), setMessageClass(short), setUserDataHeader(boolean)

setUserDataHeader

public void setUserDataHeader(boolean u)
Use this method for controlling the User Data Header Indication (UDHI). Invoking setUserDataHeader(true) ensures that the UDHI bit is set when submitting the SMS.

Please note that the UDHI bit is automatically turned on when you pass the User Data Header (UDH) using setUserDataHeader(byte[]). Therefore, it is only necessary to invoke this method when you pass both UD and UDH using setUserData(byte[]).


containsUserDataHeader

public boolean containsUserDataHeader()
Test if the Message contains a User Data Header.


setValidityPeriod

public void setValidityPeriod(int minutes)
                       throws java.lang.IllegalArgumentException
Set the relative validity period for this message. If the message cannot be delivered within the specified time, it will be discarded by the SMSC.

Parameters:
minutes - message validity in minutes or 0 to clear the validity period.
Throws:
java.lang.IllegalArgumentException - if a negative value has been specified.

setValidityPeriod

public void setValidityPeriod(java.util.Date validTill)
Set the absolute validity period for this message. When the message cannot be successfully delivered until this date, it will be discarded by the SMSC.


hasValidityPeriod

public boolean hasValidityPeriod()
Test if the Message contains a validity period


isRelativeValidityPeriod

public boolean isRelativeValidityPeriod()
Test if the Validity Period is relative.

Returns:
true if a relative validity period has been set, false if its absolute or unset.
Since:
jSMS 1.6

getValidityPeriodAsDate

public java.util.Date getValidityPeriodAsDate()
Get the absolute message validity period. If the validity period has previously been specified in minutes, this method will convert it into an absolute value.

Returns:
the validity period as date or null if no validity has been defined.

getValidityPeriodInMinutes

public int getValidityPeriodInMinutes()
Return the Message validity period in minutes.

Returns:
the validity period in minutes or 0 if no validity has been defined.

setDeferredDelivery

public void setDeferredDelivery(int minutes)
                         throws java.lang.IllegalArgumentException
Set a deferred delivery date for this message. Although the Message will immediately be delivered to the SMSC upon calling SmsService.sendMessage(Message), the SMSC will hold back the message until the given date has been reached. Please note that SMS-Services not capable of setting a deferred delivery date will silently ignore this setting.

Parameters:
minutes - the deferred delivery time in minutes relative to the time when the message has been accepted by the SMSC.
Throws:
java.lang.IllegalArgumentException - if minutes < 0.
Since:
jSMS 1.6

setDeferredDelivery

public void setDeferredDelivery(java.util.Date deferredDelivery)
Set a deferred delivery date for this message. Although the Message will immediately be delivered to the SMSC upon calling SmsService.sendMessage(Message), the SMSC will hold back the message until the given date has been reached.

Please note that SMS-Services not capable of setting a deferred delivery date will silently ignore this setting.

Parameters:
deferredDelivery - the delivery date (absolute) or null to remove deferred delivery.
Since:
jSMS 1.6

hasDeferredDelivery

public boolean hasDeferredDelivery()
Test if the Message has set a deferred delivery time.

Since:
jSMS 1.6

isRelativeDeferredDelivery

public boolean isRelativeDeferredDelivery()
Test if the deferred delivery date is relative.

Returns:
true if a relative deferred delivery date has been set, false if its absolute or unset.
Since:
jSMS 1.6

getDeferredDeliveryAsDate

public java.util.Date getDeferredDeliveryAsDate()
Get the absolute deferred delivery date. If the delivery date has previously been specified in minutes, this method will convert it into an absolute value.

Returns:
the deferred delivery date or null if no deferred delivery has been set.
Since:
jSMS 1.6

getDeferredDeliveryInMinutes

public int getDeferredDeliveryInMinutes()
Return the deferred delivery date in minutes.

Returns:
the deferred delivery in minutes or 0 if not defined.
Since:
jSMS 1.6

requestStatusReport

public void requestStatusReport(boolean value)
Request a status report (notification). If set to true, the SMSC will send back a status report (e.g. message delivered). This parameter currently only has a meaning with the GSM, CIMD2 and UCP services, for other services it will be ignored.

See Also:
StatusReportMessage

requestStatusReport

public boolean requestStatusReport()
Test if a status report will be requested.


setPID

public void setPID(short pid)
            throws java.lang.IllegalArgumentException
Set the GSM TP-PID (Protocol Identifier) octet. Refer to ETSI GSM 03.40 Specification for further details about this field. Per default, the PID is set to 0.

Parameters:
pid - the protocol identifier octet
Throws:
java.lang.IllegalArgumentException - if the specified value is lower than 0 or higher than 255.

getPID

public short getPID()
Returns the protocol identifier (TP-PID) for this message.

See Also:
setPID(short)

setRejectDuplicates

public void setRejectDuplicates(boolean rd)
Instruct the SMSC to accept or reject a short message (SM) still held in the SMSC which has the same message ID and the same destination address as a previously submitted SM from the same OA.


isRejectDuplicates

public boolean isRejectDuplicates()
Returns true if duplicate short messages should be rejected by the SMSC, false otherwise.


setReplyPath

public void setReplyPath(boolean rp)
Set/Clear the reply path (TP-RP) bit field for this message. See GSM 03.40 - Annex D for more information about the TP-RP field.


isReplyPath

public boolean isReplyPath()
Returns the state of the reply path (TP-RP) bit field.


setMMS

public void setMMS(boolean mms)
Set the More Messages to Send (MMS) flag. This parameter indicates if there will be more messages to the same destination immediately after this message. This will allow faster delivery of many messages to the same destination.

Since:
jSMS 1.6

isMMS

public boolean isMMS()
Returns true if the More Messages to Send (MMS) flag ist set for this message.

Since:
jSMS 1.6

setParent

public void setParent(SmsMessage parent)
Used by MultiPartMessage implementations to link this SMS with the originating MultiPartMessage.

Since:
jSMS 1.7

getParent

public SmsMessage getParent()
Returns the parent (originating) message for this SMS. For Messages consisting of multiple parts (SmartMessage, EMSMessage), this will return the SmartMessage/EMSMEssage that created this SMS.

Since:
jSMS 1.7

toString

public java.lang.String toString()
Description copied from class: Message
Constructs a string representation of this Message

Overrides:
toString in class Message

setSenderAddress

public void setSenderAddress(Address addr)
Set/clear the sender of this message.

Parameters:
addr - the sender address or null to clear the sender address
Since:
jSMS 1.6.2

setRecipientAddress

public void setRecipientAddress(Address addr)
Set/clear the recipient address of this message.

Parameters:
addr - the recipient address
Since:
jSMS 1.6.2

getSenderAddress

public Address getSenderAddress()
Returns the sender address or null if unset.

Since:
jSMS 1.6.2

getRecipientAddress

public Address getRecipientAddress()
Returns the recipient address or null if unset.

Since:
jSMS 1.6.2

setSender

public void setSender(java.lang.String sender)
Set the sender of this message. Please note that not all SMS transport facilities support setting the sender address.

For fine-grained control over the sender address, consider using setSenderAddress(Address) with a GsmAddress object.

Overrides:
setSender in class Message

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.

For fine-grained control over the recipient address, consider using setRecipientAddress(Address) with a GsmAddress object.

Overrides:
setRecipient in class Message
Parameters:
recipient - address of the recipient

getSender

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

Overrides:
getSender in class Message
Returns:
the adress of the sender
See Also:
getSenderAddress()

getRecipient

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

Overrides:
getRecipient in class Message
Returns:
the recipient
See Also:
getRecipientAddress()

copyFields

public void copyFields(SmsMessage message)
Copy all public fields from a message. This method initializes all its fields with exactly the contents of the corresponding fields of the message, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy".

Parameters:
message - the message to copy from

getID

public java.lang.String getID()
Returns the ID of this message. For MultiPartMessage objects, the ID of the first part is returned.

Overrides:
getID in class Message
Returns:
the Message ID or null if the message has no ID


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