PageRenderTime 141ms CodeModel.GetById 131ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 178 lines | 69 code | 20 blank | 89 comment | 2 complexity | e512e475dbd484d91881332318c541e2 MD5 | raw file
  1package javax.megaco.association;
  2
  3import java.io.Serializable;
  4
  5/**
  6 * Service change method constants used in package javax.megaco.association.
  7 * This forms the class for the Service change method parameters of the Jain
  8 * Megaco package.
  9 */
 10public class SrvChngMethod implements Serializable {
 11
 12	/**
 13	 * Identifies the service change method towards the peer shall be graceful.
 14	 */
 15	public final static int M_GRACEFUL = 1;
 16	/**
 17	 * Identifies the service change method towards the peer shall be forced.
 18	 */
 19	public final static int M_FORCED = 2;
 20	/**
 21	 * Identifies the service change method towards the peer shall be restart.
 22	 */
 23	public final static int M_RESTART = 3;
 24	/**
 25	 * Identifies the service change method towards the peer shall be
 26	 * disconnected.
 27	 */
 28	public final static int M_DISCONNECTED = 4;
 29	/**
 30	 * Identifies the service change method towards the peer shall be handoff.
 31	 */
 32	public final static int M_HANDOFF = 5;
 33	/**
 34	 * Identifies the service change method towards the peer shall be failover.
 35	 */
 36	public final static int M_FAILOVER = 6;
 37	/**
 38	 * Identifies the service change method towards the peer shall be an
 39	 * extended value.
 40	 */
 41	public final static int M_EXTENSION = 7;
 42
 43	/**
 44	 * Identifies a SrvChngMethod object that constructs the class with the
 45	 * constant M_GRACEFUL.
 46	 */
 47	public final static SrvChngMethod GRACEFUL = new SrvChngMethod(M_GRACEFUL);
 48	/**
 49	 * Identifies a SrvChngMethod object that constructs the class with the
 50	 * constant M_FORCED.
 51	 */
 52	public final static SrvChngMethod FORCED = new SrvChngMethod(M_FORCED);
 53	/**
 54	 * Identifies a SrvChngMethod object that constructs the class with the
 55	 * constant M_RESTART.
 56	 */
 57	public final static SrvChngMethod RESTART = new SrvChngMethod(M_RESTART);
 58	/**
 59	 * Identifies a SrvChngMethod object that constructs the class with the
 60	 * constant M_DISCONNECTED.
 61	 */
 62	public final static SrvChngMethod DISCONNECTED = new SrvChngMethod(M_DISCONNECTED);
 63	/**
 64	 * Identifies a SrvChngMethod object that constructs the class with the
 65	 * constant M_HANDOFF.
 66	 */
 67	public final static SrvChngMethod HANDOFF = new SrvChngMethod(M_HANDOFF);
 68	/**
 69	 * Identifies a SrvChngMethod object that constructs the class with the
 70	 * constant M_FAILOVER.
 71	 */
 72	public final static SrvChngMethod FAILOVER = new SrvChngMethod(M_FAILOVER);
 73	/**
 74	 * Identifies a SrvChngMethod object that constructs the class with the
 75	 * constant {@link javax.megaco.association.SrvChngMethod.M_EXTENSION}.
 76	 */
 77	public final static SrvChngMethod EXTENSION = new SrvChngMethod(M_EXTENSION);
 78
 79	private int srvChngMethodId = -1;
 80
 81	/**
 82	 * Constructs a class initialised with value service_change_method as passed
 83	 * to it in the constructor.
 84	 * 
 85	 * @param service_change_method
 86	 */
 87	private SrvChngMethod(int service_change_method) {
 88		this.srvChngMethodId = service_change_method;
 89	}
 90
 91	/**
 92	 * This method returns one of the static field constants defined in this
 93	 * class.
 94	 * 
 95	 * @return Returns an integer value that identifies the service change
 96	 *         method.
 97	 */
 98	public int getSrvChngMethodId() {
 99		return this.srvChngMethodId;
100	}
101
102	/**
103	 * Returns reference of the SrvChngMethod object that identifies the service
104	 * change method as value passed to this method.
105	 * 
106	 * @param value
107	 *            - It is one of the possible values of the static constant that
108	 *            this class provides.
109	 * @return Returns reference of the SrvChngMethod object.
110	 * @throws IllegalArgumentException
111	 *             - If the value passed to this method is invalid, then this
112	 *             exception is raised.
113	 */
114	public static SrvChngMethod getObject(int value) throws IllegalArgumentException {
115
116		switch (value) {
117		case M_GRACEFUL:
118			return GRACEFUL;
119		case M_FORCED:
120			return FORCED;
121		case M_RESTART:
122			return RESTART;
123		case M_DISCONNECTED:
124			return DISCONNECTED;
125		case M_HANDOFF:
126			return HANDOFF;
127		case M_FAILOVER:
128			return FAILOVER;
129		case M_EXTENSION:
130			return EXTENSION;
131
132		default:
133			throw new IllegalArgumentException("Wrogn value passed, there is no change method with code: " + value);
134		}
135
136	}
137
138	/**
139	 * This method must be implemented to perform instance substitution during
140	 * serialization. This method is required for reference comparison. This
141	 * method if not implimented will simply fail each time we compare an
142	 * Enumeration value against a de-serialized Enumeration instance.
143	 * 
144	 * @return
145	 */
146	private Object readResolve() {
147		return this.getObject(this.srvChngMethodId);
148	}
149
150	@Override
151	public String toString() {
152		switch (this.srvChngMethodId) {
153		case M_GRACEFUL:
154			return "SrvChngMethod[SVC_CHNG_METHOD_GRACEFUL]";
155		case M_FORCED:
156			return "SrvChngMethod[SVC_CHNG_METHOD_FORCED]";
157
158		case M_RESTART:
159			return "SrvChngMethod[SVC_CHNG_METHOD_RESTART]";
160
161		case M_DISCONNECTED:
162			return "SrvChngMethod[SVC_CHNG_METHOD_DISCONNECTED]";
163
164		case M_HANDOFF:
165			return "SrvChngMethod[SVC_CHNG_METHOD_HANDOFF]";
166
167		case M_FAILOVER:
168			return "SrvChngMethod[SVC_CHNG_METHOD_FAILOVER]";
169
170		case M_EXTENSION:
171			return "SrvChngMethod[SVC_CHNG_METHOD_EXTENSION]";
172
173		default:
174			return "SrvChngMethod[" + this.srvChngMethodId + "]";
175		}
176	}
177
178}