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

http://mobicents.googlecode.com/ · Java · 130 lines · 45 code · 20 blank · 65 comment · 2 complexity · 0b6a4f493df3447ca53fb3a8d30f1717 MD5 · raw file

  1. package javax.megaco.message.descriptor;
  2. import java.io.Serializable;
  3. /**
  4. * Service state constants used in package javax.megaco.message.descriptor. This
  5. * defines the service state for the megaco package.
  6. */
  7. public class ServiceState implements Serializable {
  8. /**
  9. * Identifies service state to be out of service. Its value shall be set to
  10. * 0.
  11. */
  12. public static final int M_OOS = 0;
  13. /**
  14. * Identifies service state to be in-service. Its value shall be set to 1.
  15. */
  16. public static final int M_INS = 1;
  17. /**
  18. * Identifies service state to be "test". Its value shall be set to 2.
  19. */
  20. public static final int M_TEST = 2;
  21. /**
  22. * Identifies a ServiceState object that constructs the class with the
  23. * constant M_OOS. Since it is reference to static final
  24. * object, it prevents further instantiation of the same object in the
  25. * system.
  26. */
  27. public static final ServiceState OOS = new ServiceState(M_OOS);
  28. /**
  29. * Identifies a ServiceState object that constructs the class with the
  30. * constant M_INS. 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 ServiceState INS = new ServiceState(M_INS);
  35. /**
  36. * Identifies a ServiceState object that constructs the class with the
  37. * constant M_TEST. 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 ServiceState TEST = new ServiceState(M_TEST);
  42. private int serviceState = -1;
  43. /**
  44. * Constructs an class that specifies the service state in the termination
  45. * state descriptor.
  46. *
  47. * @param service_state
  48. */
  49. private ServiceState(int service_state) {
  50. this.serviceState = service_state;
  51. }
  52. /**
  53. * This method returns one of the static field constants defined in this
  54. * class.
  55. *
  56. * @return Returns an integer value that identifies the service state to be
  57. * one of out of service or in-service or test.
  58. */
  59. public int getServiceState() {
  60. return this.serviceState;
  61. }
  62. /**
  63. * Returns reference of the ServiceState object that identifies the service
  64. * state as value passed to this method.
  65. *
  66. * @param value
  67. * - It is one of the possible values of the static constant that
  68. * this class provides.
  69. * @return Returns reference of the ServiceState object.
  70. * @throws IllegalArgumentException
  71. * - If the value passed to this method is invalid, then this
  72. * exception is raised.
  73. */
  74. public static final ServiceState getObject(int value) throws IllegalArgumentException {
  75. switch (value) {
  76. case M_INS:
  77. return INS;
  78. case M_OOS:
  79. return OOS;
  80. case M_TEST:
  81. return TEST;
  82. default:
  83. throw new IllegalArgumentException("Wrong value of service state: " + value);
  84. }
  85. }
  86. /**
  87. * This method must be implemented to perform instance substitution during
  88. * serialization. This method is required for reference comparison. This
  89. * method if not implimented will simply fail each time we compare an
  90. * Enumeration value against a de-serialized Enumeration instance.
  91. *
  92. * @return
  93. */
  94. private Object readResolve() {
  95. return getObject(this.serviceState);
  96. }
  97. @Override
  98. public String toString() {
  99. switch (this.serviceState) {
  100. case M_INS:
  101. return "ServiceState[INS]";
  102. case M_OOS:
  103. return "ServiceState[OOS]";
  104. case M_TEST:
  105. return "ServiceState[TEST]";
  106. default:
  107. return "ServiceState["+this.serviceState+"]";
  108. }
  109. }
  110. }