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