PageRenderTime 19ms CodeModel.GetById 1ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

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