PageRenderTime 102ms CodeModel.GetById 34ms app.highlight 7ms RepoModel.GetById 57ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 163 lines | 57 code | 22 blank | 84 comment | 2 complexity | c2d49a7a98e395f4ceeca0feae035cee MD5 | raw file
  1package javax.megaco.message.descriptor;
  2
  3import java.io.Serializable;
  4
  5/**
  6 * Stream mode constants used in package javax.megaco.message.descriptor. This
  7 * defines the stream modes for the megaco package.
  8 */
  9public class StreamMode implements Serializable {
 10
 11	/**
 12	 * Identifies stream mode to be send only. Its value shall be set to 0.
 13	 */
 14	public static final int M_SEND_ONLY = 0;
 15
 16	/**
 17	 * Identifies stream mode to be receive only. Its value shall be set to 1.
 18	 */
 19	public static final int M_RECV_ONLY = 1;
 20
 21	/**
 22	 * Identifies stream mode to be "send receive". Its value shall be set to 2.
 23	 */
 24	public static final int M_SEND_RECV = 2;
 25
 26	/**
 27	 * Identifies stream mode to be "inactive". Its value shall be set to 3.
 28	 */
 29	public static final int M_INACTIVE = 3;
 30
 31	/**
 32	 * Identifies stream mode to be "loopback". Its value shall be set to 4.
 33	 */
 34	public static final int M_LOOPBACK = 4;
 35
 36	/**
 37	 * Identifies a StreamMode object that constructs the class with the
 38	 * constant M_SEND_ONLY. Since it is reference to static final
 39	 * object, it prevents further instantiation of the same object in the
 40	 * system.
 41	 */
 42	public static final StreamMode SEND_ONLY = new StreamMode(M_SEND_ONLY);
 43
 44	/**
 45	 * Identifies a StreamMode object that constructs the class with the
 46	 * constant M_SEND_RECV. Since it is reference to static final
 47	 * object, it prevents further instantiation of the same object in the
 48	 * system.
 49	 */
 50	public static final StreamMode SEND_RECV = new StreamMode(M_SEND_RECV);
 51
 52	/**
 53	 * Identifies a StreamMode object that constructs the class with the
 54	 * constant M_RECV_ONLY. Since it is reference to static final
 55	 * object, it prevents further instantiation of the same object in the
 56	 * system.
 57	 */
 58	public static final StreamMode RECV_ONLY = new StreamMode(M_RECV_ONLY);
 59
 60	/**
 61	 * Identifies a StreamMode object that constructs the class with the
 62	 * constant M_INACTIVE. Since it is reference to static final
 63	 * object, it prevents further instantiation of the same object in the
 64	 * system.
 65	 */
 66	public static final StreamMode INACTIVE = new StreamMode(M_INACTIVE);
 67
 68	/**
 69	 * Identifies a StreamMode object that constructs the class with the
 70	 * constant M_LOOPBACK. Since it is reference to static final
 71	 * object, it prevents further instantiation of the same object in the
 72	 * system.
 73	 */
 74	public static final StreamMode LOOPBACK = new StreamMode(M_LOOPBACK);
 75
 76	private int streamMode = -1;
 77
 78	/**
 79	 * 
 80	 * Constructs an class that specifies the stream mode in the local control
 81	 * descriptor.
 82	 * 
 83	 * @param stream_mode
 84	 */
 85	private StreamMode(int stream_mode) {
 86		this.streamMode = stream_mode;
 87	}
 88
 89	/**
 90	 * This method returns one of the static field constants defined in this
 91	 * class.
 92	 * 
 93	 * @return Returns an integer value that identifies the stream mode to be
 94	 *         one of send only or receive only or send receive or inactive or
 95	 *         loopback.
 96	 */
 97	public int getStreamMode() {
 98		return this.streamMode;
 99	}
100
101	/**
102	 * Returns reference of the StreamMode object that identifies the stream
103	 * mode as value passed to this method.
104	 * 
105	 * @param value
106	 *            - It is one of the possible values of the static constant that
107	 *            this class provides.
108	 * @return Returns reference of the StreamMode object.
109	 * @throws IllegalArgumentException
110	 *             - If the value passed to this method is invalid, then this
111	 *             exception is raised.
112	 */
113	public static final StreamMode getObject(int value) throws IllegalArgumentException {
114
115		switch (value) {
116		case M_INACTIVE:
117			return INACTIVE;
118		case M_LOOPBACK:
119			return LOOPBACK;
120		case M_RECV_ONLY:
121			return RECV_ONLY;
122		case M_SEND_ONLY:
123			return SEND_ONLY;
124		case M_SEND_RECV:
125			return SEND_RECV;
126
127		default:
128			throw new IllegalArgumentException("Wrong value passed as StreamMode: " + value);
129		}
130	}
131
132	/**
133	 * This method must be implemented to perform instance substitution during
134	 * serialization. This method is required for reference comparison. This
135	 * method if not implimented will simply fail each time we compare an
136	 * Enumeration value against a de-serialized Enumeration instance.
137	 * 
138	 * @return
139	 */
140	private Object readResolve() {
141		return getObject(this.streamMode);
142	}
143
144	@Override
145	public String toString() {
146		switch (this.streamMode) {
147		case M_INACTIVE:
148			return "StreamMode[INACTIVE]";
149		case M_LOOPBACK:
150			return "StreamMode[LOOPBACK]";
151		case M_RECV_ONLY:
152			return "StreamMode[RECV_ONLY]";
153		case M_SEND_ONLY:
154			return "StreamMode[SEND_ONLY]";
155		case M_SEND_RECV:
156			return "StreamMode[SEND_RECV]";
157
158		default:
159			return "StreamMode[" + this.streamMode + "]";
160		}
161	}
162
163}