/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/message/tlv/TLVTable.java

http://mobicents.googlecode.com/ · Java · 166 lines · 22 code · 16 blank · 128 comment · 0 complexity · 81c02080e9ff4048d691cff8d07a382a MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.smpp.message.tlv;
  23. import java.io.IOException;
  24. import java.util.BitSet;
  25. import java.util.Map;
  26. import org.mobicents.protocols.smpp.util.PacketDecoder;
  27. import org.mobicents.protocols.smpp.util.PacketEncoder;
  28. /**
  29. * Map of tag/length/value (TLV) parameters.
  30. * <p>
  31. * TLV stands for Tag/Length/Value and was a capability added to SMPP version
  32. * 3.4. It is an extensible means of adding new parameter types to SMPP packets.
  33. * Each optional parameter has a 2-byte tag, which is a unique identifier of
  34. * that parameter, a 2-byte length, which is an integer value representing the
  35. * length of the value of the parameter and a value. The value may be of various
  36. * types including integers, C Strings, octet strings, bit masks etc. The tag
  37. * defines the type of the value.
  38. * </p>
  39. * <p>
  40. * TLVs were originally called "optional parameters". SMPP v5 altered this
  41. * since it introduced the concept of required TLV parameters.
  42. * </p>
  43. * <p>
  44. * This class holds a mapping of tags to values. Each SMPP packet holds a TLV
  45. * table which holds that packet's set of current optional parameters. Upon
  46. * serializing the packet to an output stream or byte array, the format of the
  47. * serialized packet is:
  48. * </p>
  49. *
  50. * <pre>
  51. *
  52. * +-------------------------+
  53. * | SMPP Packet |
  54. * | +----------------------+|
  55. * | | SMPP Header ||
  56. * | +----------------------+|
  57. * | | ||
  58. * | | ||
  59. * | | Mandatory parameters ||
  60. * | | ||
  61. * | | ||
  62. * | +----------------------+|
  63. * | | Optional parameters ||
  64. * | | +------------------+ ||
  65. * | | | Tag/Length/Value | ||
  66. * | | +------------------+ ||
  67. * | | | ... | ||
  68. * | | +------------------+ ||
  69. * | +----------------------+|
  70. * +-------------------------+
  71. *
  72. * </pre>
  73. *
  74. * @version $Id: TLVTable.java 457 2009-01-15 17:37:42Z orank $
  75. */
  76. public interface TLVTable extends Map<Tag, Object> {
  77. // TODO docs
  78. void readFrom(PacketDecoder decoder, int length);
  79. void writeTo(PacketEncoder encoder) throws IOException;
  80. /**
  81. * Get the value for a tag. This is a convenience method to convert
  82. * the tag integer to its appropriate Tag object and then look that
  83. * tag up in the map.
  84. * @param tag The tag&apos;s integer value.
  85. */
  86. Object get(int tag);
  87. /**
  88. * Get the tag&apos;s value as a string.
  89. * @param tag The tag to retrieve the value for.
  90. * @return The value as a string, or <code>null</code> if the specified
  91. * tag is not set in this table.
  92. */
  93. String getString(Tag tag);
  94. /**
  95. * Get the tag&apos;s value as an int.
  96. * @param tag The tag to retrieve the value for.
  97. * @return The value as an integer, or <code>-1</code> if the specified
  98. * tag is not set in this table.
  99. * @throws ClassCastException If the value for the specified tag is not
  100. * a number (castable as a <code>java.lang.Number</code>).
  101. */
  102. int getInt(Tag tag);
  103. /**
  104. * Get the tag&apos;s value as a long.
  105. * @param tag The tag to retrieve the value for.
  106. * @return The value as a long, or <code>-1</code> if the specified
  107. * tag is not set in this table.
  108. * @throws ClassCastException If the value for the specified tag is not
  109. * a number (castable as a <code>java.lang.Number</code>).
  110. */
  111. long getLong(Tag tag);
  112. /**
  113. * Get the tag&apos;s value as a bit set.
  114. * @param tag The tag to retrieve the value for.
  115. * @return The value, cast as a <code>java.util.BitSet</code>, or
  116. * <code>null</code> if the specified tag is not set in this table.
  117. * @throws ClassCastException If the value for the specified tag is not
  118. * a bit mask.
  119. */
  120. BitSet getBitmask(Tag tag);
  121. /**
  122. * Get the tag&apos;s value as a byte array.
  123. * @param tag The tag to retrieve the value for.
  124. * @return The value, cast as a <code>byte[]</code>, or <code>null</code>
  125. * if the specified tag is not set in this table.
  126. * @throws ClassCastException If the value for the specified tag is not
  127. * a byte array.
  128. */
  129. byte[] getBytes(Tag tag);
  130. Object put(Tag tag, char value);
  131. Object put(Tag tag, short value);
  132. Object put(Tag tag, int value);
  133. Object put(Tag tag, long value);
  134. /**
  135. * Remove (or un-set) a tag/value from this table.
  136. * @param tag The tag to remove from the table.
  137. */
  138. void remove(int tag);
  139. /**
  140. * Get the length the parameters in the table would encode as. The length of
  141. * an SMPP packet is determined by: <br>
  142. * <code>sizeof (smpp_header) + sizeof (mandatory_parameters)
  143. * + sizeof (optional_parameters).</code>
  144. * <br>
  145. * The value returned for this method is the last clause in this equation.
  146. *
  147. * @return The full length that the optional parameters would encode as.
  148. */
  149. int getLength();
  150. }