PageRenderTime 39ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 221 lines | 67 code | 22 blank | 132 comment | 9 complexity | 186ce1c33c70efb8dc9e98c5d117f186 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. package javax.megaco.message.descriptor;
  2. import javax.megaco.MethodInvocationException;
  3. /**
  4. * The EventParam object is a class that shall be used to set the signal
  5. * descriptor, digitMap descriptor, stream id, whether keep alive is active or
  6. * not, package name, event id and the associated parameter names and values.
  7. * The class optionally provides interface to specify the package name, item
  8. * name and the associated parameters in the string format. This is an
  9. * independent class derived from java.util.Object and shall not have any
  10. * derived classes.
  11. */
  12. public class EventParam {
  13. private SignalDescriptor signalDescriptor = null;
  14. private Integer streamId = null;
  15. private Boolean keepActive = new Boolean(false);
  16. private DigitMapDescriptor digitMapDescriptor = new DigitMapDescriptor();
  17. /**
  18. * Constructs an object of type event parameter which shall be used within
  19. * the event descriptor.
  20. */
  21. public EventParam() {
  22. super();
  23. // TODO Auto-generated constructor stub
  24. }
  25. /**
  26. * The method can be used to get the signal descriptor.
  27. *
  28. * @return signalDesc - The reference to the object corresponding to the
  29. * signal descriptor. This shall be returned only if the signal
  30. * descriptor is present in the event parameter of the event
  31. * descriptor.
  32. */
  33. public SignalDescriptor getSignalDescriptor() {
  34. return this.signalDescriptor;
  35. }
  36. /**
  37. * The method can be used to get the embedded digit map name in the event
  38. * descriptor. Only one of digit map name or digit map value shall be set.
  39. *
  40. * @return The reference to the embedded digitMap name. If this value is not
  41. * set, then this method would return NULL.
  42. */
  43. public java.lang.String getDigitMapName() {
  44. return this.digitMapDescriptor.getDigitMapName();
  45. }
  46. /**
  47. * The method can be used to get the embedded digit map value in the event
  48. * descriptor. Only one of digit map name or digit map value shall be set.
  49. *
  50. * @return The reference to the embedded digitMap value. If this value is
  51. * not set, then this method would return NULL.
  52. */
  53. public DigitMapValue getDigitMapValue() {
  54. return this.digitMapDescriptor.getDigitMapValue();
  55. }
  56. /**
  57. * The method can be used to get the embedded digit map value in the event
  58. * descriptor. Only one of digit map name or digit map value shall be set.
  59. *
  60. * @return The reference to the embedded digitMap value. If this value is
  61. * not set, then this method would return NULL.
  62. */
  63. public java.lang.String getDigitMapValueStr() {
  64. return this.digitMapDescriptor.getDigitMapValueStr();
  65. }
  66. /**
  67. * The method can be used to get stream id in the event descriptor.
  68. *
  69. * @return streamId - The integer value of the stream id shall be returned.
  70. * This shall be returned only if the streamId is present in the
  71. * event parameter of the event descriptor.
  72. * @throws IllegalStateException
  73. * - Thrown if streamId has not been set. Thus this method
  74. * should be called only after verifying that the streamId is
  75. * set using isStreamIdPresent()
  76. */
  77. public int getStreamId() throws IllegalStateException {
  78. if (streamId == null) {
  79. throw new IllegalStateException("StreamId must be set.");
  80. }
  81. return this.streamId.intValue();
  82. }
  83. /**
  84. * The method can be used to set the signal descriptor within the event
  85. * descriptor.
  86. *
  87. * @param signalDesc
  88. * - The reference to the object corresponding to the signal
  89. * descriptor.
  90. * @throws IllegalArgumentException
  91. * - Thrown if parameters set in the signal descriptor are such
  92. * that the object cannot be set for the event descriptor.
  93. */
  94. public void setSignalDescriptor(SignalDescriptor signalDesc) throws IllegalArgumentException {
  95. // FIXME: add checks
  96. this.signalDescriptor = signalDesc;
  97. }
  98. /**
  99. * The method can be used to set the digit map name. Only one of digit map
  100. * name or digit map value shall be set. This automatically sets the value
  101. * of digitMap descriptor present in the event parameter object to true. If
  102. * digitmap value is already set, then this method would raise an exception.
  103. *
  104. * @param digitMapName
  105. * - The reference to the object corresponding to the digitMap
  106. * name.
  107. * @throws IllegalArgumentException
  108. * - Thrown if digit Map value has already been set. The
  109. * protocol allows only either of them but not both.
  110. */
  111. public void setDigitMapName(java.lang.String digitMapName) throws IllegalArgumentException {
  112. if (this.digitMapDescriptor.getDigitMapValue() != null) {
  113. throw new IllegalArgumentException("Digit map value must not be present when name is set.");
  114. }
  115. this.digitMapDescriptor.setDigitMapName(digitMapName);
  116. }
  117. /**
  118. * The method can be used to set the digit map value. Only one of digit map
  119. * name or digit map value shall be set. This automatically sets the value
  120. * of digitMap descriptor present in the event parameter object to true. If
  121. * digitmap name is already set, then this method would raise an exception.
  122. *
  123. * @param digitMapValue
  124. * - The reference to the object corresponding to the digitMap
  125. * value.
  126. * @throws IllegalArgumentException
  127. * - Thrown if digit Map name has already been set. The protocol
  128. * allows only either of them but not both.
  129. */
  130. public void setDigitMapValue(DigitMapValue digitMapValue) throws IllegalArgumentException {
  131. if (this.digitMapDescriptor.getDigitMapName() != null) {
  132. throw new IllegalArgumentException("Digit map name must not be present when value is set.");
  133. }
  134. this.digitMapDescriptor.setDigitMapValue(digitMapValue);
  135. }
  136. /**
  137. * The method can be used to set the digit map value. Only one of digit map
  138. * name or digit map value shall be set. This automatically sets the value
  139. * of digitMap descriptor present in the event parameter object to true. If
  140. * digitmap name is already set, then this method would raise an exception.
  141. *
  142. * @param digitMapValue
  143. * - The reference to the object corresponding to the digitMap
  144. * value.
  145. * @throws IllegalArgumentException
  146. * - Thrown if digit Map name has already been set. The protocol
  147. * allows only either of them but not both.
  148. */
  149. public void setDigitMapValueStr(java.lang.String digitMapValue) throws IllegalArgumentException {
  150. if (this.digitMapDescriptor.getDigitMapName() != null) {
  151. throw new IllegalArgumentException("Digit map name must not be present when digit map string is set.");
  152. }
  153. this.digitMapDescriptor.setDigitMapValueStr(digitMapValue);
  154. }
  155. /**
  156. * The method can be used to set stream id in the event descriptor. This
  157. * automatically sets the value of stream id present in the event parameter
  158. * object to true.
  159. *
  160. * @param streamId
  161. * - The integer value of the stream id shall be set.
  162. * @throws IllegalArgumentException
  163. * - Thrown if streamId is set with an invalid value.
  164. */
  165. public void setStreamId(int streamId) throws IllegalArgumentException {
  166. // FIXME: what invalid value?
  167. this.streamId = new Integer(streamId);
  168. }
  169. /**
  170. * The method can be used to find if the stream id is present in the current
  171. * object.
  172. *
  173. * @return Returns true if the stream id is present. This needs to be
  174. * checked before getting the stream id from this object.
  175. */
  176. public boolean isStreamIdPresent() {
  177. return this.streamId != null;
  178. }
  179. /**
  180. * The method can be used to set Keep Active flag in the event descriptor.
  181. */
  182. public void setKeepActive() {
  183. this.keepActive = new Boolean(true);
  184. }
  185. /**
  186. * The method can be used to find if the Keep Active is present in the
  187. * current object.
  188. *
  189. * @return Returns true if the Keep Active is present.
  190. */
  191. public boolean isKeepActivePresent() {
  192. return this.keepActive.booleanValue();
  193. }
  194. @Override
  195. public java.lang.String toString() {
  196. return this.getClass().getSimpleName() + " : StreamId = " + this.streamId + " : KeepActive = " + this.keepActive + " : SignalDesc[ " + this.signalDescriptor + " ] : DigitMapDescriptor[ "
  197. + this.digitMapDescriptor + " ]";
  198. }
  199. }