ie.omk.smpp.message.tlv
Class TLVTable

java.lang.Object
  extended by ie.omk.smpp.message.tlv.TLVTable
All Implemented Interfaces:
Serializable

public class TLVTable
extends Object
implements Serializable

Table of optional parameters (TLVs).

TLV stands for Tag/Length/Value and was a capability added to SMPP version 3.4. It is an extensible means of adding new parameter types to SMPP packets. Each optional parameter has a 2-byte tag, which is a unique identifier of that parameter, a 2-byte length, which is an integer value representing the length of the value of the parameter and a value. The value may be of various types including integers, C Strings, octet strings, bit masks etc. The tag defines the type of the value.

This class holds a mapping of tags to values. Each SMPP packet holds a TLV table which holds that packet's set of current optional parameters. Upon serializing the packet to an output stream or byte array, the format of the serialized packet is:

 
    +-------------------------+
    | SMPP Packet             |
    | +----------------------+|
    | | SMPP Header          ||
    | +----------------------+|
    | |                      ||
    | |                      ||
    | | Mandatory parameters ||
    | |                      ||
    | |                      ||
    | +----------------------+|
    | | Optional parameters  ||
    | | +------------------+ ||
    | | | Tag/Length/Value | ||
    | | +------------------+ ||
    | | |     ...          | ||
    | | +------------------+ ||
    | +----------------------+|
    +-------------------------+
  
 

Version:
$Id: TLVTable.java 466 2009-06-16 12:26:57Z orank $
Author:
Oran Kelly
See Also:
Serialized Form

Constructor Summary
TLVTable()
          Create a new, empty, TLVTable.
 
Method Summary
 void clear()
          Clear all optional parameters out of this table.
 Object get(int tag)
          Get the value for a tag.
 Object get(Tag tag)
          Get the value for a tag.
 int getLength()
          Get the length the parameters in the table would encode as.
 boolean isSet(Tag tag)
          Check if an optional parameter currently has a value set.
 void parseAllOpts()
          Force the TLVTable to parse all the optional parameters from the internal byte array and place them in the map.
 void readFrom(byte[] b, int offset, int len)
          Decode a full set of optional parameters from a byte array.
 Object set(Tag tag, Object value)
          Set a value for an optional parameter.
 Set tagSet()
          Get the set of tags in this TLVTable.
 Collection values()
          Get a Collection view of the set of values in this TLVTable.
 void writeTo(OutputStream out)
          Encode all the optional parameters in this table to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TLVTable

public TLVTable()
Create a new, empty, TLVTable.

Method Detail

readFrom

public void readFrom(byte[] b,
                     int offset,
                     int len)
Decode a full set of optional parameters from a byte array.

Parameters:
b - The byte array to decode from.
offset - The first byte of the tag of the first optional parameter.
len - The length in the byte array of all the optional parameters.

writeTo

public void writeTo(OutputStream out)
             throws IOException
Encode all the optional parameters in this table to an output stream.

Parameters:
out - The output stream to encode the parameters to.
Throws:
IOException - If an error occurs writing to the output stream.

get

public Object get(Tag tag)
Get the value for a tag. Note that this method can return null in two cases: if the parameter is not set or if the value is null, which can occur if the particular tag type has no value. To check if a parameter which has no value is set, use isSet(ie.omk.smpp.message.tlv.Tag).

Parameters:
tag - The tag to get the value for.
Returns:
The currently set value for tag, or null if it is not set.

get

public Object get(int tag)
Get the value for a tag.

See Also:
get(ie.omk.smpp.message.tlv.Tag)

isSet

public boolean isSet(Tag tag)
Check if an optional parameter currently has a value set.

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

set

public Object set(Tag tag,
                  Object value)
           throws BadValueTypeException,
                  InvalidSizeForValueException
Set a value for an optional parameter.

Parameters:
tag - The tag of the parameter to set.
value - The value of the parameter to set.
Returns:
The previous value for the parameter, or null if there was none.
Throws:
BadValueTypeException - if an attempt is made to set a value using a Java type that is not allowed for that parameter type.
InvalidSizeForValueException - if the value's encoded length is outside the bounds allowed for that parameter.

clear

public void clear()
Clear all optional parameters out of this table.


parseAllOpts

public final void parseAllOpts()
Force the TLVTable to parse all the optional parameters from the internal byte array and place them in the map. Normally, TLVTable is lazy about parsing parameters. It will only decode them and place them in the internal map when they are requested using get(ie.omk.smpp.message.tlv.Tag). Calling this method causes all the parameters to be parsed and placed in the internal map and the byte array containing the parameter's bytes to be released for garbage collection.

It is not normally needed for an application to call this method. TLVTable uses it internally when necessary to ensure there is no loss of synchronization between the internal map and the byte array.


getLength

public int getLength()
Get the length the parameters in the table would encode as. The length of an SMPP packet is determined by:
sizeof (smpp_header) + sizeof (mandatory_parameters) + sizeof (optional_parameters).
The value returned for this method is the last clause in this equation.

Returns:
The full length that the optional parameters would encode as.

tagSet

public Set tagSet()
Get the set of tags in this TLVTable.

Returns:
A java.util.Set containing all the Tags in this TLVTable.

values

public Collection values()
Get a Collection view of the set of values in this TLVTable.

Returns:
A java.util.Collection view of all the values in this TLVTable.


Copyright © 2011 smppapi at Sourceforge. All Rights Reserved.