/protocols/jain-megaco/megaco-api/src/main/java/javax/megaco/association/SrvChngMethod.java

http://mobicents.googlecode.com/ · Java · 178 lines · 69 code · 20 blank · 89 comment · 2 complexity · e512e475dbd484d91881332318c541e2 MD5 · raw file

  1. package javax.megaco.association;
  2. import java.io.Serializable;
  3. /**
  4. * Service change method constants used in package javax.megaco.association.
  5. * This forms the class for the Service change method parameters of the Jain
  6. * Megaco package.
  7. */
  8. public class SrvChngMethod implements Serializable {
  9. /**
  10. * Identifies the service change method towards the peer shall be graceful.
  11. */
  12. public final static int M_GRACEFUL = 1;
  13. /**
  14. * Identifies the service change method towards the peer shall be forced.
  15. */
  16. public final static int M_FORCED = 2;
  17. /**
  18. * Identifies the service change method towards the peer shall be restart.
  19. */
  20. public final static int M_RESTART = 3;
  21. /**
  22. * Identifies the service change method towards the peer shall be
  23. * disconnected.
  24. */
  25. public final static int M_DISCONNECTED = 4;
  26. /**
  27. * Identifies the service change method towards the peer shall be handoff.
  28. */
  29. public final static int M_HANDOFF = 5;
  30. /**
  31. * Identifies the service change method towards the peer shall be failover.
  32. */
  33. public final static int M_FAILOVER = 6;
  34. /**
  35. * Identifies the service change method towards the peer shall be an
  36. * extended value.
  37. */
  38. public final static int M_EXTENSION = 7;
  39. /**
  40. * Identifies a SrvChngMethod object that constructs the class with the
  41. * constant M_GRACEFUL.
  42. */
  43. public final static SrvChngMethod GRACEFUL = new SrvChngMethod(M_GRACEFUL);
  44. /**
  45. * Identifies a SrvChngMethod object that constructs the class with the
  46. * constant M_FORCED.
  47. */
  48. public final static SrvChngMethod FORCED = new SrvChngMethod(M_FORCED);
  49. /**
  50. * Identifies a SrvChngMethod object that constructs the class with the
  51. * constant M_RESTART.
  52. */
  53. public final static SrvChngMethod RESTART = new SrvChngMethod(M_RESTART);
  54. /**
  55. * Identifies a SrvChngMethod object that constructs the class with the
  56. * constant M_DISCONNECTED.
  57. */
  58. public final static SrvChngMethod DISCONNECTED = new SrvChngMethod(M_DISCONNECTED);
  59. /**
  60. * Identifies a SrvChngMethod object that constructs the class with the
  61. * constant M_HANDOFF.
  62. */
  63. public final static SrvChngMethod HANDOFF = new SrvChngMethod(M_HANDOFF);
  64. /**
  65. * Identifies a SrvChngMethod object that constructs the class with the
  66. * constant M_FAILOVER.
  67. */
  68. public final static SrvChngMethod FAILOVER = new SrvChngMethod(M_FAILOVER);
  69. /**
  70. * Identifies a SrvChngMethod object that constructs the class with the
  71. * constant {@link javax.megaco.association.SrvChngMethod.M_EXTENSION}.
  72. */
  73. public final static SrvChngMethod EXTENSION = new SrvChngMethod(M_EXTENSION);
  74. private int srvChngMethodId = -1;
  75. /**
  76. * Constructs a class initialised with value service_change_method as passed
  77. * to it in the constructor.
  78. *
  79. * @param service_change_method
  80. */
  81. private SrvChngMethod(int service_change_method) {
  82. this.srvChngMethodId = service_change_method;
  83. }
  84. /**
  85. * This method returns one of the static field constants defined in this
  86. * class.
  87. *
  88. * @return Returns an integer value that identifies the service change
  89. * method.
  90. */
  91. public int getSrvChngMethodId() {
  92. return this.srvChngMethodId;
  93. }
  94. /**
  95. * Returns reference of the SrvChngMethod object that identifies the service
  96. * change method as value passed to this method.
  97. *
  98. * @param value
  99. * - It is one of the possible values of the static constant that
  100. * this class provides.
  101. * @return Returns reference of the SrvChngMethod object.
  102. * @throws IllegalArgumentException
  103. * - If the value passed to this method is invalid, then this
  104. * exception is raised.
  105. */
  106. public static SrvChngMethod getObject(int value) throws IllegalArgumentException {
  107. switch (value) {
  108. case M_GRACEFUL:
  109. return GRACEFUL;
  110. case M_FORCED:
  111. return FORCED;
  112. case M_RESTART:
  113. return RESTART;
  114. case M_DISCONNECTED:
  115. return DISCONNECTED;
  116. case M_HANDOFF:
  117. return HANDOFF;
  118. case M_FAILOVER:
  119. return FAILOVER;
  120. case M_EXTENSION:
  121. return EXTENSION;
  122. default:
  123. throw new IllegalArgumentException("Wrogn value passed, there is no change method with code: " + value);
  124. }
  125. }
  126. /**
  127. * This method must be implemented to perform instance substitution during
  128. * serialization. This method is required for reference comparison. This
  129. * method if not implimented will simply fail each time we compare an
  130. * Enumeration value against a de-serialized Enumeration instance.
  131. *
  132. * @return
  133. */
  134. private Object readResolve() {
  135. return this.getObject(this.srvChngMethodId);
  136. }
  137. @Override
  138. public String toString() {
  139. switch (this.srvChngMethodId) {
  140. case M_GRACEFUL:
  141. return "SrvChngMethod[SVC_CHNG_METHOD_GRACEFUL]";
  142. case M_FORCED:
  143. return "SrvChngMethod[SVC_CHNG_METHOD_FORCED]";
  144. case M_RESTART:
  145. return "SrvChngMethod[SVC_CHNG_METHOD_RESTART]";
  146. case M_DISCONNECTED:
  147. return "SrvChngMethod[SVC_CHNG_METHOD_DISCONNECTED]";
  148. case M_HANDOFF:
  149. return "SrvChngMethod[SVC_CHNG_METHOD_HANDOFF]";
  150. case M_FAILOVER:
  151. return "SrvChngMethod[SVC_CHNG_METHOD_FAILOVER]";
  152. case M_EXTENSION:
  153. return "SrvChngMethod[SVC_CHNG_METHOD_EXTENSION]";
  154. default:
  155. return "SrvChngMethod[" + this.srvChngMethodId + "]";
  156. }
  157. }
  158. }