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

http://mobicents.googlecode.com/ · Java · 107 lines · 63 code · 15 blank · 29 comment · 2 complexity · 2926737b33f01d94fe4004014e18f6b2 MD5 · raw file

  1. package javax.megaco.message;
  2. import java.io.Serializable;
  3. /**
  4. * Termination type constants for the termination type for the megaco package.
  5. *
  6. *
  7. */
  8. public class TermType implements Serializable {
  9. public static final int M_NORMAL = 1;
  10. public static final int M_CHOOSE = 2;
  11. public static final int M_ROOT = 3;
  12. public static final int M_WILDCARD = 4;
  13. public static final TermType NORMAL = new TermType(M_NORMAL);
  14. public static final TermType CHOOSE = new TermType(M_CHOOSE);
  15. public static final TermType ROOT = new TermType(M_ROOT);
  16. public static final TermType WILDCARD = new TermType(M_WILDCARD);
  17. private int term_type;
  18. /**
  19. * Constructs an abstract class that specifies the termination type in the
  20. * command.
  21. *
  22. * @param term_type
  23. */
  24. private TermType(int term_type) {
  25. this.term_type = term_type;
  26. }
  27. /**
  28. * This method returns one of the static field constants defined in this
  29. * class. This method is overriden by the derived class, which shall return
  30. * an hard coded value depending on the class.
  31. *
  32. * @return Returns an integer value that identifies the termination type to
  33. * be one of normal, or choose or root or wildcarded.
  34. */
  35. public int getTermType() {
  36. return this.term_type;
  37. }
  38. /**
  39. * Returns reference of the TermType object that identifies the termination
  40. * type as value passed to this method.
  41. *
  42. * @param value
  43. * It is one of the possible values of the static constant that
  44. * this class provides.
  45. * @return Returns reference of the TermType object.
  46. * @throws IllegalArgumentException
  47. */
  48. public static final TermType getObject(int value) throws IllegalArgumentException {
  49. TermType t = null;
  50. switch (value) {
  51. case M_NORMAL:
  52. t = NORMAL;
  53. break;
  54. case M_CHOOSE:
  55. t = CHOOSE;
  56. break;
  57. case M_ROOT:
  58. t = ROOT;
  59. break;
  60. case M_WILDCARD:
  61. t = WILDCARD;
  62. break;
  63. default:
  64. throw new IllegalArgumentException("TermType not found for value " + value);
  65. }
  66. return t;
  67. }
  68. private Object readResolve() {
  69. return this.getObject(this.term_type);
  70. }
  71. @Override
  72. public String toString() {
  73. String t = null;
  74. switch (this.term_type) {
  75. case M_NORMAL:
  76. t = "TermType[NORMAL]";
  77. break;
  78. case M_CHOOSE:
  79. t = "TermType[CHOOSE]";
  80. break;
  81. case M_ROOT:
  82. t = "TermType[ROOT]";
  83. break;
  84. case M_WILDCARD:
  85. t = "TermType[WILDCARD]";
  86. break;
  87. default:
  88. t = "TermType[" + this.term_type + "]";
  89. }
  90. return t;
  91. }
  92. }