PageRenderTime 33ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 89 lines | 39 code | 13 blank | 37 comment | 2 complexity | 836beb227c63064339933e85c0a7ffe8 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. package javax.megaco.association;
  2. import java.io.Serializable;
  3. public class EncodingFormat implements Serializable {
  4. /**
  5. * Identifies the encoding format to the peer messages from the stack shall
  6. * be text (ABNF format).
  7. */
  8. public static final int M_TEXT = 0;
  9. /**
  10. * Identifies the encoding format to the peer messages from the stack shall
  11. * be binary (ASN.1 with BER format).
  12. */
  13. public static final int M_ASN = 1;
  14. /**
  15. * Identifies a EncodingFormat object that constructs the class with the
  16. * constant M_TEXT. Since it is reference to static final object, it
  17. * prevents further instantiation of the same object in the system.
  18. */
  19. public static final EncodingFormat TEXT = new EncodingFormat(M_TEXT);
  20. /**
  21. * Identifies a EncodingFormat object that constructs the class with the
  22. * constant M_ASN. Since it is reference to static final object, it prevents
  23. * further instantiation of the same object in the system.
  24. */
  25. public static final EncodingFormat ASN = new EncodingFormat(M_ASN);
  26. private int encodingFormat = -1;
  27. private EncodingFormat(int encoding_format) {
  28. encodingFormat = encoding_format;
  29. }
  30. private Object readResolve() {
  31. return this.getObject(this.encodingFormat);
  32. }
  33. /**
  34. * Returns reference of the EncodingFormat object that identifies the
  35. * encoding format as value passed to this method.
  36. *
  37. * @param value
  38. * - It is one of the possible values of the static constant that
  39. * this class provides.
  40. * @return Returns reference of the EncodingFormat object.
  41. * @throws IllegalArgumentException
  42. * - If the value passed to this method is invalid, then this
  43. * exception is raised.
  44. */
  45. public static Object getObject(int value) throws IllegalArgumentException {
  46. switch (value) {
  47. case M_TEXT:
  48. return TEXT;
  49. case M_ASN:
  50. return ASN;
  51. default:
  52. throw new IllegalArgumentException("Wrogn value passed, there is no encoding with code: " + value);
  53. }
  54. }
  55. /**
  56. * This method returns one of the static field constants defined in this
  57. * class.
  58. *
  59. * @return Returns an integer value that identifies the encoding format of
  60. * the association, which could to be one of ASN or TEXT.
  61. */
  62. public int getEncodingFormat() {
  63. return this.encodingFormat;
  64. }
  65. @Override
  66. public String toString() {
  67. switch (this.encodingFormat) {
  68. case M_TEXT:
  69. return "EncodingFormat[TEXT]";
  70. case M_ASN:
  71. return "EncodingFormat[ASN]";
  72. default:
  73. return "EncodingFormat[" + this.encodingFormat + "]";
  74. }
  75. }
  76. }