org.mobicents.protocols.smpp.message
Class SMPPPacket

java.lang.Object
  extended by org.mobicents.protocols.smpp.message.SMPPPacket
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
AlertNotification, Bind, BindResp, BroadcastSM, BroadcastSMResp, CancelBroadcastSM, CancelBroadcastSMResp, CancelSM, CancelSMResp, DataSM, DataSMResp, DeliverSMResp, EnquireLink, EnquireLinkResp, GenericNack, Outbind, ParamRetrieve, ParamRetrieveResp, QueryBroadcastSM, QueryBroadcastSMResp, QueryLastMsgs, QueryLastMsgsResp, QueryMsgDetails, QueryMsgDetailsResp, QuerySM, QuerySMResp, ReplaceSM, ReplaceSMResp, SubmitMulti, SubmitMultiResp, SubmitSM, SubmitSMResp, Unbind, UnbindResp

public abstract class SMPPPacket
extends Object
implements Serializable, Cloneable

This is the abstract class that all SMPP messages are inherited from.

Version:
$Id: SMPPPacket.java 457 2009-01-15 17:37:42Z orank $
See Also:
Serialized Form

Field Summary
protected  int commandId
          Command ID.
protected  int commandStatus
          Command status.
protected  long sequenceNum
          Packet sequence number.
protected  TLVTable tlvTable
          TLV table.
 
Constructor Summary
protected SMPPPacket(int commandId)
          Create a new SMPPPacket with the specified Id.
protected SMPPPacket(SMPPPacket request)
          Create a new SMPPPacket that represents a response to the specified packet.
 
Method Summary
 Object clone()
           
 boolean equals(Object obj)
           
 int getCommandId()
          Get the Command Id of this SMPP packet.
 int getCommandStatus()
          Get the status of this packet.
 int getLength()
          Get the length this packet encodes as.
protected  int getMandatorySize()
          Get the encoded size of the mandatory parameters of this packet.
 long getSequenceNum()
          Get the sequence number of this packet.
 Object getTLV(Tag tag)
          Get a TLV parameter.
 TLVTable getTLVTable()
          Get the optional parameter (TLV) table.
 int hashCode()
           
 boolean isRequest()
          Is this command a request packet.
 boolean isResponse()
          Is this command a response packet.
 boolean isSet(Tag tag)
          Check if a particular TLV parameter is set.
 void readFrom(PacketDecoder decoder)
          Decode an SMPP packet from a byte array.
protected  void readMandatory(PacketDecoder decoder)
          Read the mandatory parameters from a packet decoder.
 Object removeTLV(Tag tag)
          Remove a TLV parameter.
protected  boolean safeCompare(Object obj1, Object obj2)
          Utility method to compare two objects, even if one or both are null.
 void setCommandStatus(int commandStatus)
          Set the status of this packet.
 void setSequenceNum(long sequenceNum)
          Set the sequence number of this packet.
 Object setTLV(Tag tag, Object value)
          Set a TLV parameter.
 int sizeOf(Address address)
          Get the encoded size of an address, which may be null.
 int sizeOf(byte[] array)
          Get the encoded size of a byte array, which may be null.
 int sizeOf(SMPPDate date)
          Get the encoded size of a date, which may be null.
 int sizeOf(String string)
          Get the encoded size of a string, which may be null.
 String toString()
          Return a String representation of this packet.
protected  void toString(StringBuilder buffer)
          Get the mandatory parameters in string form (for display purposes only).
 void validate(SMPPVersion smppVersion)
          Validate this packet against an SMPP version.
protected  void validateMandatory(SMPPVersion smppVersion)
          Validate the mandatory parameters for this packet.
protected  boolean validateTLVTable(SMPPVersion smppVersion)
          Validate that the TLV table contains all required parameters.
protected  void writeMandatory(PacketEncoder encoder)
          Write the mandatory parameters to a packet encoder.
 void writeTo(PacketEncoder encoder)
          Write the byte representation of this SMPP packet to an OutputStream
 void writeTo(PacketEncoder encoder, boolean withOptional)
          Write the byte representation of this SMPP packet to an OutputStream
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

commandId

protected int commandId
Command ID.


commandStatus

protected int commandStatus
Command status.


sequenceNum

protected long sequenceNum
Packet sequence number.


tlvTable

protected TLVTable tlvTable
TLV table.

Constructor Detail

SMPPPacket

protected SMPPPacket(int commandId)
Create a new SMPPPacket with the specified Id. This version of the constructor is provided as an extension point for custom packets.

Parameters:
commandId - The command ID.

SMPPPacket

protected SMPPPacket(SMPPPacket request)
Create a new SMPPPacket that represents a response to the specified packet. This constructor will duplicate the sequence number and version from the request packet, and set the command id to the appropriate value representing the response packet.

Parameters:
request -
Method Detail

isRequest

public boolean isRequest()
Is this command a request packet.

Returns:
true if this packet is an SMPP request, false if it is a response.

isResponse

public boolean isResponse()
Is this command a response packet.

Returns:
true if this packet is an SMPP response, false if it is a request.

getCommandId

public int getCommandId()
Get the Command Id of this SMPP packet.

Returns:
The Command Id of this packet

getCommandStatus

public int getCommandStatus()
Get the status of this packet.

Returns:
The error status of this packet (only relevent to Response packets)

setCommandStatus

public void setCommandStatus(int commandStatus)
Set the status of this packet.

Parameters:
commandStatus -

getSequenceNum

public long getSequenceNum()
Get the sequence number of this packet.

Returns:
The sequence number of this SMPP packet

setSequenceNum

public void setSequenceNum(long sequenceNum)
Set the sequence number of this packet.


getTLVTable

public TLVTable getTLVTable()
Get the optional parameter (TLV) table.

See Also:
TLVTable

setTLV

public Object setTLV(Tag tag,
                     Object value)
Set a TLV parameter. This is a convenience method and is equivalent to getTLVTable().put(tag, value).

Parameters:
tag - The tag of the parameter to set.
value - The value object to set.
Returns:
The previous value of the parameter, or null if it was unset.
Throws:
BadValueTypeException - If the type of value is incorrect for the tag.
See Also:
TLVTable.put(org.mobicents.protocols.smpp.message.tlv.Tag, char)

getTLV

public Object getTLV(Tag tag)
Get a TLV parameter. This is a convenience method and is equivalent to getTLVTable().get(tag).

Parameters:
tag - the tag of the TLV parameter to get.

removeTLV

public Object removeTLV(Tag tag)
Remove a TLV parameter. This is a convenience method and is equivalent to getTLVTable().remove(tag).

Parameters:
tag - The TLV to remove.
Returns:
The TLV, if it was set or null if it wasn't.

isSet

public boolean isSet(Tag tag)
Check if a particular TLV parameter is set. This is a convenience method and is equivalent to getTLVTable().containsKey(tag) .

Parameters:
tag - the tag of the parameter to check.
Returns:
true if the parameter is set, false if it is not.

getLength

public final int getLength()
Get the length this packet encodes as.

Returns:
The size, in bytes, of this packet as it would encode on the network.

writeTo

public void writeTo(PacketEncoder encoder)
             throws IOException
Write the byte representation of this SMPP packet to an OutputStream

Parameters:
out - The OutputStream to use
Throws:
IOException - if there's an error writing to the output stream.

writeTo

public final void writeTo(PacketEncoder encoder,
                          boolean withOptional)
                   throws IOException
Write the byte representation of this SMPP packet to an OutputStream

Parameters:
out - The OutputStream to use
withOptional - true to send optional parameters over the link, false to only write the mandatory parameters.
Throws:
IOException - if there's an error writing to the output stream.

readFrom

public void readFrom(PacketDecoder decoder)
              throws SMPPProtocolException
Decode an SMPP packet from a byte array.

Parameters:
data - the byte array to read the SMPP packet's fields from.
offset - the offset into b to begin reading the packet fields from.
Throws:
SMPPProtocolException - if there is an error parsing the packet fields.
SMPPRuntimeException - If an attempt is made to parse a different type of packet than this class supports (for example, trying to use a BindTransmitter object to parse data that contains a BindTransceiver packet).

validate

public final void validate(SMPPVersion smppVersion)
Validate this packet against an SMPP version. If any part of this packet is in violation of smppVersion, a VersionException will be thrown. Examples of violations are:

Parameters:
smppVersion - The version to validate against.
Throws:
VersionException - If the package fails validation.

toString

public String toString()
Return a String representation of this packet. This is provided for debugging/display purposes only and is not intended to be used programatically.

Overrides:
toString in class Object
Returns:
A string representation of this packet.

sizeOf

public int sizeOf(Address address)
Get the encoded size of an address, which may be null.

Parameters:
address - A (possibly null) address object.
Returns:
The encoded size of the address.

sizeOf

public int sizeOf(SMPPDate date)
Get the encoded size of a date, which may be null.

Parameters:
date - A (possibly null) date object.
Returns:
The encoded size of the address.

sizeOf

public int sizeOf(byte[] array)
Get the encoded size of a byte array, which may be null.

Parameters:
array - A (possibly null) byte array.
Returns:
The encoded size of the array.

sizeOf

public int sizeOf(String string)
Get the encoded size of a string, which may be null.

Parameters:
string - A (possibly null) string object.
Returns:
The length of the string.

clone

public Object clone()
             throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

safeCompare

protected boolean safeCompare(Object obj1,
                              Object obj2)
Utility method to compare two objects, even if one or both are null.

Parameters:
obj1 - The first object to compare.
obj2 - The second object to compare.
Returns:
true if the objects are equal, or if they are both null. false otherwise.

toString

protected void toString(StringBuilder buffer)
Get the mandatory parameters in string form (for display purposes only).

Parameters:
buffer -

validateMandatory

protected void validateMandatory(SMPPVersion smppVersion)
Validate the mandatory parameters for this packet. If any mandatory parameter fails validation, a org.mobicents.smpp.version.VersionException should be thrown.

Parameters:
smppVersion - The version to validate against.

validateTLVTable

protected boolean validateTLVTable(SMPPVersion smppVersion)
Validate that the TLV table contains all required parameters.

Parameters:
smppVersion - The version to validate against. Since required TLVs were only introduced in SMPP version 5.0, this method will only ever be called when using a version that is equivalent to or newer than that.
Returns:
true if all required TLVs are set, false otherwise.

readMandatory

protected void readMandatory(PacketDecoder decoder)
Read the mandatory parameters from a packet decoder. This default implementation is empty, parsing no mandatory parameters. Sub-classes may override this as they wish.

Parameters:
decoder - The decoder to read fields from.

writeMandatory

protected void writeMandatory(PacketEncoder encoder)
                       throws IOException
Write the mandatory parameters to a packet encoder.

Parameters:
encoder - The encoder to write mandatory parameters to.
Throws:
IOException - If an problem occurs while writing.

getMandatorySize

protected int getMandatorySize()
Get the encoded size of the mandatory parameters of this packet.

Returns:
The number of bytes the mandatory parameters will encode to.


Copyright © 2011 Mobicents. All Rights Reserved.