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

http://mobicents.googlecode.com/ · Java · 92 lines · 64 code · 22 blank · 6 comment · 2 complexity · e48e6fb37c2efb4fd92c4dc48384d9d9 MD5 · raw file

  1. package javax.megaco.message;
  2. import java.io.Serializable;
  3. /**
  4. * Constants used in package javax.megaco.message for defining the type of the
  5. * command, i.e whether a command request or a command response.
  6. *
  7. *
  8. */
  9. public class CommandType implements Serializable {
  10. public static final int M_COMMAND_REQ = 1;
  11. public static final int M_COMMAND_RESP = 2;
  12. public static final int M_ACTION_REQ = 3;
  13. public static final int M_ACTION_RESP = 4;
  14. public static final CommandType COMMAND_REQ = new CommandType(M_COMMAND_REQ);
  15. public static final CommandType COMMAND_RESP = new CommandType(M_COMMAND_RESP);
  16. public static final CommandType ACTION_REQ = new CommandType(M_ACTION_REQ);
  17. public static final CommandType ACTION_RESP = new CommandType(M_ACTION_RESP);
  18. private int cmd_type;
  19. private CommandType(int cmd_type) {
  20. this.cmd_type = cmd_type;
  21. }
  22. public int getCommandType() {
  23. return this.cmd_type;
  24. }
  25. public static final CommandType getObject(int value) throws IllegalArgumentException {
  26. CommandType c = null;
  27. switch (value) {
  28. case M_COMMAND_REQ:
  29. c = COMMAND_REQ;
  30. break;
  31. case M_COMMAND_RESP:
  32. c = COMMAND_RESP;
  33. break;
  34. case M_ACTION_REQ:
  35. c = ACTION_REQ;
  36. break;
  37. case M_ACTION_RESP:
  38. c = ACTION_RESP;
  39. break;
  40. default:
  41. IllegalArgumentException illegalArgumentException = new IllegalArgumentException("No CommandType for value = " + value);
  42. throw illegalArgumentException;
  43. }
  44. return c;
  45. }
  46. private Object readResolve() {
  47. return this.getObject(this.cmd_type);
  48. }
  49. @Override
  50. public String toString() {
  51. String c = null;
  52. switch (this.cmd_type) {
  53. case M_COMMAND_REQ:
  54. c = "CommandType[COMMAND_REQ]";
  55. break;
  56. case M_COMMAND_RESP:
  57. c = "CommandType[COMMAND_RESP]";
  58. break;
  59. case M_ACTION_REQ:
  60. c = "CommandType[ACTION_REQ]";
  61. break;
  62. case M_ACTION_RESP:
  63. c = "CommandType[ACTION_RESP]";
  64. break;
  65. default:
  66. c = "CommandType[" + this.cmd_type + "]";
  67. }
  68. return c;
  69. }
  70. }