PageRenderTime 25ms CodeModel.GetById 12ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 159 lines | 72 code | 13 blank | 74 comment | 2 complexity | 04cc88b64f21835746e998aa04e4c786 MD5 | raw file
  1package javax.megaco.association;
  2
  3import java.io.Serializable;
  4
  5/**
  6 * Constants used in package javax.megaco.association. This forms the class for
  7 * the association state of the Association package. The association here refers
  8 * to the association w.r.t the peer i.e., MG-MGC association. The state here
  9 * refers to the state of the control association between MG-MGC. These states
 10 * would assist the application in making decisions regarding when and what
 11 * commands to initiate towards the peer. For eg. untill the association is in
 12 * state M_REG_COMPL, the application should not send any commands to the stack.
 13 * Similarly, if the association is in M_GRACEFUL_SHUTDOWN_IN_PRGS state and if
 14 * the application is MGC, then it should refrain from establishing new calls,
 15 * therefore it should not send new ADD commands.
 16 * 
 17 */
 18public class AssocState implements Serializable {
 19
 20	/**
 21	 * Identifies association is in IDLE state. Its value shall be set to 1.
 22	 */
 23	public final static int M_IDLE = 1;
 24	/**
 25	 * Identifies association is in Registration state. Its value shall be set
 26	 * to 2.
 27	 */
 28	public final static int M_REG_IN_PRGS = 2;
 29	/**
 30	 * Identifies association is in Registration completed state. Its value
 31	 * shall be set to 3.
 32	 */
 33	public final static int M_REG_COMPL = 3;
 34	/**
 35	 * Identifies association is in Disconnected state. Its value shall be set
 36	 * to 4.
 37	 */
 38	public final static int M_DISCONNECTED = 4;
 39	/**
 40	 * Identifies association is in Handoff state. Its value shall be set to 5.
 41	 */
 42	public final static int M_HANDOFF_IN_PRGS = 5;
 43	/**
 44	 * Identifies association is in Handoff state. Its value shall be set to 6.
 45	 */
 46	public final static int M_FAILOVER_IN_PRGS = 6;
 47	/**
 48	 * Identifies association is in Forced shutdown state. Its value shall be
 49	 * set to 7.
 50	 */
 51	public final static int M_FORCED_SHUTDOWN_IN_PRGS = 7;
 52	/**
 53	 * Identifies association is in Registration state. Its value shall be set
 54	 * to 8.
 55	 */
 56	public final static int M_GRACEFUL_SHUTDOWN_IN_PRGS = 8;
 57	/**
 58	 * Identifies a AssocState object that constructs the class with the
 59	 * constant M_IDLE.
 60	 */
 61	public final static AssocState IDLE = new AssocState(M_IDLE);
 62	/**
 63	 * Identifies a AssocState object that constructs the class with the field
 64	 * constant M_REG_IN_PRGS.
 65	 */
 66	public final static AssocState REG_IN_PRGS = new AssocState(M_REG_IN_PRGS);
 67	/**
 68	 * Identifies a AssocState object that constructs the class with the field
 69	 * constant M_REG_COMPL.
 70	 */
 71	public final static AssocState REG_COMPL = new AssocState(M_REG_COMPL);
 72	/**
 73	 * Identifies a AssocState object that constructs the class with the field
 74	 * constant M_DISCONNECTED.
 75	 */
 76	public final static AssocState DISCONNECTED = new AssocState(M_DISCONNECTED);
 77	/**
 78	 * Identifies a AssocState object that constructs the class with the field
 79	 * constant M_HANDOFF_IN_PRGS.
 80	 */
 81	public final static AssocState HANDOFF_IN_PRGS = new AssocState(M_HANDOFF_IN_PRGS);
 82	/**
 83	 * Identifies a AssocState object that constructs the class with the field
 84	 * constant M_FAILOVER_IN_PRGS.
 85	 */
 86	public final static AssocState FAILOVER_IN_PRGS = new AssocState(M_FAILOVER_IN_PRGS);
 87	/**
 88	 * Identifies a AssocState object that constructs the class with the field
 89	 * constant M_FORCED_SHUTDOWN_IN_PRGS.
 90	 */
 91	public final static AssocState FORCED_SHUTDOWN_IN_PRGS = new AssocState(M_FORCED_SHUTDOWN_IN_PRGS);
 92	/**
 93	 * Identifies a AssocState object that constructs the class with the field
 94	 * constant M_GRACEFUL_SHUTDOWN_IN_PRGS.
 95	 */
 96	public final static AssocState GRACEFUL_SHUTDOWN_IN_PRGS = new AssocState(M_GRACEFUL_SHUTDOWN_IN_PRGS);
 97
 98	private int assocState = -1;
 99
100	private AssocState(int assocStateIdle) {
101		this.assocState = assocStateIdle;
102	}
103
104	public int getAssocState() {
105		return this.assocState;
106	}
107
108	public static final AssocState getObject(int value) {
109
110		switch (value) {
111		case M_IDLE:
112			return IDLE;
113		case M_REG_IN_PRGS:
114			return REG_IN_PRGS;
115		case M_REG_COMPL:
116			return REG_COMPL;
117		case M_DISCONNECTED:
118			return DISCONNECTED;
119		case M_HANDOFF_IN_PRGS:
120			return HANDOFF_IN_PRGS;
121		case M_FAILOVER_IN_PRGS:
122			return FAILOVER_IN_PRGS;
123		case M_FORCED_SHUTDOWN_IN_PRGS:
124			return FORCED_SHUTDOWN_IN_PRGS;
125		case M_GRACEFUL_SHUTDOWN_IN_PRGS:
126			return GRACEFUL_SHUTDOWN_IN_PRGS;
127		default:
128			throw new IllegalArgumentException("Wrogn value passed, there is no assoc state with code: " + value);
129
130		}
131
132	}
133
134	@Override
135	public String toString() {
136		switch (this.assocState) {
137		case M_IDLE:
138			return "AssocState[IDLE]";
139		case M_REG_IN_PRGS:
140			return "AssocState[REG_IN_PRGS";
141		case M_REG_COMPL:
142			return "AssocState[REG_COMPL";
143		case M_DISCONNECTED:
144			return "AssocState[DISCONNECTED";
145		case M_HANDOFF_IN_PRGS:
146			return "AssocState[HANDOFF_IN_PRGS";
147		case M_FAILOVER_IN_PRGS:
148			return "AssocState[FAILOVER_IN_PRGS";
149		case M_FORCED_SHUTDOWN_IN_PRGS:
150			return "AssocState[FORCED_SHUTDOWN_IN_PRGS";
151		case M_GRACEFUL_SHUTDOWN_IN_PRGS:
152			return "AssocState[GRACEFUL_SHUTDOWN_IN_PRGS";
153		default:
154			return "AssocState[" + this.assocState + "]";
155
156		}
157	}
158
159}