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

http://mobicents.googlecode.com/ · Java · 163 lines · 57 code · 22 blank · 84 comment · 2 complexity · c2d49a7a98e395f4ceeca0feae035cee MD5 · raw file

  1. package javax.megaco.message.descriptor;
  2. import java.io.Serializable;
  3. /**
  4. * Stream mode constants used in package javax.megaco.message.descriptor. This
  5. * defines the stream modes for the megaco package.
  6. */
  7. public class StreamMode implements Serializable {
  8. /**
  9. * Identifies stream mode to be send only. Its value shall be set to 0.
  10. */
  11. public static final int M_SEND_ONLY = 0;
  12. /**
  13. * Identifies stream mode to be receive only. Its value shall be set to 1.
  14. */
  15. public static final int M_RECV_ONLY = 1;
  16. /**
  17. * Identifies stream mode to be "send receive". Its value shall be set to 2.
  18. */
  19. public static final int M_SEND_RECV = 2;
  20. /**
  21. * Identifies stream mode to be "inactive". Its value shall be set to 3.
  22. */
  23. public static final int M_INACTIVE = 3;
  24. /**
  25. * Identifies stream mode to be "loopback". Its value shall be set to 4.
  26. */
  27. public static final int M_LOOPBACK = 4;
  28. /**
  29. * Identifies a StreamMode object that constructs the class with the
  30. * constant M_SEND_ONLY. Since it is reference to static final
  31. * object, it prevents further instantiation of the same object in the
  32. * system.
  33. */
  34. public static final StreamMode SEND_ONLY = new StreamMode(M_SEND_ONLY);
  35. /**
  36. * Identifies a StreamMode object that constructs the class with the
  37. * constant M_SEND_RECV. Since it is reference to static final
  38. * object, it prevents further instantiation of the same object in the
  39. * system.
  40. */
  41. public static final StreamMode SEND_RECV = new StreamMode(M_SEND_RECV);
  42. /**
  43. * Identifies a StreamMode object that constructs the class with the
  44. * constant M_RECV_ONLY. Since it is reference to static final
  45. * object, it prevents further instantiation of the same object in the
  46. * system.
  47. */
  48. public static final StreamMode RECV_ONLY = new StreamMode(M_RECV_ONLY);
  49. /**
  50. * Identifies a StreamMode object that constructs the class with the
  51. * constant M_INACTIVE. Since it is reference to static final
  52. * object, it prevents further instantiation of the same object in the
  53. * system.
  54. */
  55. public static final StreamMode INACTIVE = new StreamMode(M_INACTIVE);
  56. /**
  57. * Identifies a StreamMode object that constructs the class with the
  58. * constant M_LOOPBACK. Since it is reference to static final
  59. * object, it prevents further instantiation of the same object in the
  60. * system.
  61. */
  62. public static final StreamMode LOOPBACK = new StreamMode(M_LOOPBACK);
  63. private int streamMode = -1;
  64. /**
  65. *
  66. * Constructs an class that specifies the stream mode in the local control
  67. * descriptor.
  68. *
  69. * @param stream_mode
  70. */
  71. private StreamMode(int stream_mode) {
  72. this.streamMode = stream_mode;
  73. }
  74. /**
  75. * This method returns one of the static field constants defined in this
  76. * class.
  77. *
  78. * @return Returns an integer value that identifies the stream mode to be
  79. * one of send only or receive only or send receive or inactive or
  80. * loopback.
  81. */
  82. public int getStreamMode() {
  83. return this.streamMode;
  84. }
  85. /**
  86. * Returns reference of the StreamMode object that identifies the stream
  87. * mode as value passed to this method.
  88. *
  89. * @param value
  90. * - It is one of the possible values of the static constant that
  91. * this class provides.
  92. * @return Returns reference of the StreamMode object.
  93. * @throws IllegalArgumentException
  94. * - If the value passed to this method is invalid, then this
  95. * exception is raised.
  96. */
  97. public static final StreamMode getObject(int value) throws IllegalArgumentException {
  98. switch (value) {
  99. case M_INACTIVE:
  100. return INACTIVE;
  101. case M_LOOPBACK:
  102. return LOOPBACK;
  103. case M_RECV_ONLY:
  104. return RECV_ONLY;
  105. case M_SEND_ONLY:
  106. return SEND_ONLY;
  107. case M_SEND_RECV:
  108. return SEND_RECV;
  109. default:
  110. throw new IllegalArgumentException("Wrong value passed as StreamMode: " + value);
  111. }
  112. }
  113. /**
  114. * This method must be implemented to perform instance substitution during
  115. * serialization. This method is required for reference comparison. This
  116. * method if not implimented will simply fail each time we compare an
  117. * Enumeration value against a de-serialized Enumeration instance.
  118. *
  119. * @return
  120. */
  121. private Object readResolve() {
  122. return getObject(this.streamMode);
  123. }
  124. @Override
  125. public String toString() {
  126. switch (this.streamMode) {
  127. case M_INACTIVE:
  128. return "StreamMode[INACTIVE]";
  129. case M_LOOPBACK:
  130. return "StreamMode[LOOPBACK]";
  131. case M_RECV_ONLY:
  132. return "StreamMode[RECV_ONLY]";
  133. case M_SEND_ONLY:
  134. return "StreamMode[SEND_ONLY]";
  135. case M_SEND_RECV:
  136. return "StreamMode[SEND_RECV]";
  137. default:
  138. return "StreamMode[" + this.streamMode + "]";
  139. }
  140. }
  141. }