org.mobicents.protocols.smpp.message.tlv
Class TLVTableImpl

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<Tag,Object>
              extended by org.mobicents.protocols.smpp.message.tlv.TLVTableImpl
All Implemented Interfaces:
Serializable, Cloneable, Map<Tag,Object>, TLVTable

public class TLVTableImpl
extends LinkedHashMap<Tag,Object>
implements TLVTable

Implementation of the TLVTable interface. This implementation will maintain the ordering of added parameters.

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

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
TLVTableImpl()
           
 
Method Summary
 Object get(int tag)
          Get the value for a tag.
 BitSet getBitmask(Tag tag)
          Get the tag's value as a bit set.
 byte[] getBytes(Tag tag)
          Get the tag's value as a byte array.
 int getInt(Tag tag)
          Get the tag's value as an int.
 int getLength()
          Get the length the parameters in the table would encode as.
 long getLong(Tag tag)
          Get the tag's value as a long.
 String getString(Tag tag)
          Get the tag's value as a string.
 Object put(Tag tag, char value)
           
 Object put(Tag tag, int value)
           
 Object put(Tag tag, long value)
           
 Object put(Tag tag, Object value)
          Set the value of a TLV.
 Object put(Tag tag, short value)
           
 void readFrom(PacketDecoder decoder, int length)
          Decode a full set of optional parameters from a byte array.
 void remove(int tag)
          Remove (or un-set) a tag/value from this table.
 String toString()
           
 void writeTo(PacketEncoder encoder)
          Encode all the optional parameters in this table to an output stream.
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get, removeEldestEntry
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, values
 

Constructor Detail

TLVTableImpl

public TLVTableImpl()
Method Detail

readFrom

public void readFrom(PacketDecoder decoder,
                     int length)
Decode a full set of optional parameters from a byte array.

Specified by:
readFrom in interface TLVTable

writeTo

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

Specified by:
writeTo in interface TLVTable
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(int tag)
Get the value for a tag. This is a convenience method to convert the tag integer to its appropriate Tag object and then look that tag up in the map.

Specified by:
get in interface TLVTable
Parameters:
tag - The tag's integer value.

getString

public String getString(Tag tag)
Get the tag's value as a string.

Specified by:
getString in interface TLVTable
Parameters:
tag - The tag to retrieve the value for.
Returns:
The value as a string, or null if the specified tag is not set in this table.

getInt

public int getInt(Tag tag)
Get the tag's value as an int.

Specified by:
getInt in interface TLVTable
Parameters:
tag - The tag to retrieve the value for.
Returns:
The value as an integer, or -1 if the specified tag is not set in this table.
Throws:
ClassCastException - If the value for the specified tag is not a number (castable as a java.lang.Number).

getLong

public long getLong(Tag tag)
Get the tag's value as a long.

Specified by:
getLong in interface TLVTable
Parameters:
tag - The tag to retrieve the value for.
Returns:
The value as a long, or -1 if the specified tag is not set in this table.
Throws:
ClassCastException - If the value for the specified tag is not a number (castable as a java.lang.Number).

getBitmask

public BitSet getBitmask(Tag tag)
Get the tag's value as a bit set.

Specified by:
getBitmask in interface TLVTable
Parameters:
tag - The tag to retrieve the value for.
Returns:
The value, cast as a java.util.BitSet, or null if the specified tag is not set in this table.
Throws:
ClassCastException - If the value for the specified tag is not a bit mask.

getBytes

public byte[] getBytes(Tag tag)
Get the tag's value as a byte array.

Specified by:
getBytes in interface TLVTable
Parameters:
tag - The tag to retrieve the value for.
Returns:
The value, cast as a byte[], or null if the specified tag is not set in this table.
Throws:
ClassCastException - If the value for the specified tag is not a byte array.

put

public Object put(Tag tag,
                  Object value)
           throws BadValueTypeException,
                  InvalidSizeForValueException
Set the value of a TLV.

Specified by:
put in interface Map<Tag,Object>
Overrides:
put in class HashMap<Tag,Object>
Parameters:
tag - The tag of the parameter to set.
value - The tag's value.
Throws:
BadValueTypeException - If tag does not accept the type that value is.
InvalidSizeForValueException - If value exceeds either the minimum or maximum size allowed by tag.

put

public Object put(Tag tag,
                  char value)
Specified by:
put in interface TLVTable

put

public Object put(Tag tag,
                  short value)
Specified by:
put in interface TLVTable

put

public Object put(Tag tag,
                  int value)
Specified by:
put in interface TLVTable

put

public Object put(Tag tag,
                  long value)
Specified by:
put in interface TLVTable

remove

public void remove(int tag)
Remove (or un-set) a tag/value from this table.

Specified by:
remove in interface TLVTable
Parameters:
tag - The tag to remove from the table.

toString

public String toString()
Overrides:
toString in class AbstractMap<Tag,Object>

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.

Specified by:
getLength in interface TLVTable
Returns:
The full length that the optional parameters would encode as.


Copyright © 2011 Mobicents. All Rights Reserved.