PageRenderTime 24ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 173 lines | 56 code | 24 blank | 93 comment | 9 complexity | 939c2722e03a65980ca24c6db976cad4 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 java.io.Serializable;
  3. import javax.megaco.MethodInvocationException;
  4. import javax.megaco.pkg.PkgEventItem;
  5. import javax.megaco.pkg.PkgItemStr;
  6. /**
  7. * The ObservedEvent object is a class that shall be used to set the observed
  8. * events and the stream id in which it was observed along with optionally the
  9. * time at which it was detected. The class optionally provides interface to
  10. * specify the package name, item name and the associated parameters in the
  11. * string format. This is an independent class derived from java.util.Object and
  12. * shall not have any derived classes.
  13. */
  14. public class ObservedEvent implements Serializable {
  15. private PkgEventItem eventItem;
  16. private PkgItemStr eventItemStr;
  17. private TimeStamp timeStamp;
  18. private Integer streamId;
  19. /**
  20. * Constructs Observed Event parameter Object. This is to be set within an
  21. * observed event descriptor.
  22. *
  23. * @param eventItem
  24. * @throws IllegalArgumentException
  25. * - Thrown if an invalid event id is set.
  26. */
  27. public ObservedEvent(PkgEventItem eventItem) throws IllegalArgumentException {
  28. // FIXME: add error check on invalid event?
  29. if (eventItem == null) {
  30. throw new IllegalArgumentException("PkgEventItem must not be null");
  31. }
  32. this.eventItem = eventItem;
  33. }
  34. /**
  35. *
  36. * Constructs Observed Event parameter object with the PkgItemStr object.
  37. * This method would be used if the package parameters are to be conveyed in
  38. * the string format. This is to be set within an event buffer descriptor.
  39. *
  40. * @param eventItemStr
  41. * @throws IllegalArgumentException
  42. * - Thrown if an invalid eventItemStr object reference is set.
  43. */
  44. public ObservedEvent(PkgItemStr eventItemStr) throws IllegalArgumentException {
  45. if (eventItemStr == null) {
  46. throw new IllegalArgumentException("PkgItemStr must not be null");
  47. }
  48. this.eventItemStr = eventItemStr;
  49. }
  50. /**
  51. * The method can be used to get the pkdgName as set in the observed event
  52. * descriptor. This method gives the package information, the attached event
  53. * information and the parameter name and value for the event id.
  54. *
  55. * @return The object reference for the megaco package, which has the object
  56. * reference for megaco package event and which in turn has the
  57. * reference for the parameter info. If the parameter has not been
  58. * set, then this method shall return NULL.
  59. */
  60. public PkgEventItem getMegacoPkgEvtItem() {
  61. return this.eventItem;
  62. }
  63. /**
  64. * The method can be used to get the pkdgName as set in the observed event
  65. * descriptor. This method gives the package information, the attached event
  66. * information and the parameter name and value. As compares to the
  67. * getMegacoPkgEvtItem() method, this method returns the package parameters
  68. * in the string format.
  69. *
  70. * @return The object reference for the megaco package item. This class
  71. * holds information about package name, item name and the
  72. * parameters in the string format. If the parameter has not been
  73. * set, then this method shall return NULL.
  74. */
  75. public PkgItemStr getMegacoPkgItemStr() {
  76. return this.eventItemStr;
  77. }
  78. /**
  79. * The method can be used to get stream id in the event descriptor.
  80. *
  81. * @return streamId - The integer value of the stream id shall be returned.
  82. * This shall be returned only if the streamId is present in the
  83. * event parameter of the event descriptor.
  84. * @throws IllegalStateException
  85. * - Thrown if streamId has not been set. Thus this method
  86. * should be called only after verifying that the streamId is
  87. * set using isStreamIdPresent
  88. */
  89. public int getStreamId() throws IllegalStateException {
  90. if (!isStreamIdPresent()) {
  91. throw new IllegalStateException("StreamId must be present");
  92. }
  93. return this.streamId.intValue();
  94. }
  95. /**
  96. * The method can be used to set stream id in the event descriptor. This
  97. * automatically sets the value of stream id present in the event parameter
  98. * object to true.
  99. *
  100. * @param streamId
  101. * - The integer value of the stream id shall be set.
  102. * @throws IllegalArgumentException
  103. * - Thrown if streamId is set with an invalid value.
  104. */
  105. public void setStreamId(int streamId) throws IllegalArgumentException {
  106. if (streamId <= 0) {
  107. throw new IllegalArgumentException("StreamId must be greater than zero.");
  108. }
  109. this.streamId = new Integer(streamId);
  110. }
  111. /**
  112. * The method can be used to find if the stream id is present in the current
  113. * object.
  114. *
  115. * @return Returns true if the stream id is present. This needs to be
  116. * checked before getting the stream id from this object.
  117. */
  118. public boolean isStreamIdPresent() {
  119. return this.streamId != null;
  120. }
  121. /**
  122. * The method is used to retrieve the time stamp at which the event was
  123. * detected.
  124. *
  125. * @return timeStamp - The object reference for the timestamp. It returns a
  126. * NULL value when not set.
  127. */
  128. public TimeStamp getTimeStamp() {
  129. return this.timeStamp;
  130. }
  131. /**
  132. * The method is used to set the time stamp at which the event was detected.
  133. *
  134. * @param timeStamp
  135. * - The object reference for the timestamp.
  136. * @throws IllegalArgumentException
  137. * - Thrown if timestamp is set with an invalid value.
  138. */
  139. public void setTimeStamp(TimeStamp timeStamp) throws IllegalArgumentException {
  140. // FIXME: add checks for invalid value?
  141. if (timeStamp == null) {
  142. throw new IllegalArgumentException("TimeStamp must not be null");
  143. }
  144. this.timeStamp = timeStamp;
  145. }
  146. public java.lang.String toString() {
  147. return super.toString();
  148. }
  149. }