PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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