/protocols/jain-megaco/megaco-api/src/main/java/javax/megaco/message/descriptor/ModemParam.java

http://mobicents.googlecode.com/ · Java · 104 lines · 36 code · 15 blank · 53 comment · 7 complexity · 2b24c95224a91dc86771faa5200f6614 MD5 · raw file

  1. package javax.megaco.message.descriptor;
  2. import java.io.Serializable;
  3. import javax.megaco.MethodInvocationException;
  4. import javax.megaco.message.Descriptor;
  5. /**
  6. * The class ModemParam shall be used to set the Modem Type in the Modem
  7. * Descriptor. This also takes the extension string if the modem type is set to
  8. * extension parameter.
  9. */
  10. public class ModemParam implements Serializable {
  11. private ModemType modemType = null;
  12. private String extModem;
  13. /**
  14. * Constructs a object of class ModemParam with ModemType. This constructor
  15. * can take all values of modem type except {@link ModemType.EXT}.
  16. *
  17. * @param modemType
  18. * @throws IllegalArgumentException
  19. * - If the object of class ModemType is set to NULL or the
  20. * modem type is set to {@link ModemType.EXT}.
  21. */
  22. public ModemParam(ModemType modemType)
  23. throws IllegalArgumentException {
  24. if (modemType == null) {
  25. throw new IllegalArgumentException("ModemType must not be null");
  26. }
  27. this.modemType = modemType;
  28. }
  29. /**
  30. *
  31. * Constructs a object of class ModemParam with extension string. This
  32. * implicitly sets the modem type to {@link ModemType.EXT}.
  33. *
  34. * @param extModem
  35. * - Sets the string for the extension of the modem type. The
  36. * extension string should be prefixed with "X-" or "X+". The
  37. * extension characters following the prefix should be at most of
  38. * 6 characters. The extension string would be set only when the
  39. * modem type specifies {@link ModemType.EXT}.
  40. * @throws IllegalArgumentException
  41. * - If the extension string passed to this method is NULL or if
  42. * the extension string is not in proper format. It should be
  43. * prefixed with either "X+" or "X-" followed by at most 6
  44. * characters.
  45. */
  46. public ModemParam(java.lang.String extModem)
  47. throws IllegalArgumentException {
  48. modemType = ModemType.EXT;
  49. if (extModem == null) {
  50. throw new IllegalArgumentException("ExtModem must not be null");
  51. }
  52. // FIXME??
  53. DescriptorUtils.checkMethodExtensionRules(extModem);
  54. if (extModem.length() > 8) {
  55. throw new IllegalArgumentException("ExtModem length must nto exceed 8 characters");
  56. }
  57. this.extModem = extModem;
  58. }
  59. /**
  60. * This method returns the identity of the modem type. The constants for the
  61. * modem type are defined in ModemType.
  62. *
  63. * @return Returns an integer value that identifies Modem type. It returns
  64. * one of the values defined in, ModemType.
  65. */
  66. public ModemType getModemType() {
  67. return this.modemType;
  68. }
  69. /**
  70. * This method returns the extension string of the modem type. The extension
  71. * string should be prefixed with "X-" or "X+". The extension characters
  72. * following the prefix should be at most of 6 characters. The extension
  73. * string would be set only when the modem type specifies
  74. * MODEM_TYPE_EXTENSION.
  75. *
  76. * @return Gets the string for the extension of the modem type. The
  77. * extension string would be set only when the modem type specifies
  78. * MODEM_TYPE_EXTENSION.
  79. * @throws IllegalStateException
  80. * if the method has been called when the modem type denotes
  81. * anything other than MODEM_TYPE_EXT
  82. */
  83. public java.lang.String getExtensionString() throws IllegalStateException {
  84. if (this.modemType.getModemType() != ModemType.M_EXT) {
  85. throw new IllegalStateException("ModemType must be: EXT");
  86. }
  87. return this.extModem;
  88. }
  89. }