PageRenderTime 20ms CodeModel.GetById 2ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 130 lines | 45 code | 20 blank | 65 comment | 2 complexity | 0b6a4f493df3447ca53fb3a8d30f1717 MD5 | raw file
  1package javax.megaco.message.descriptor;
  2
  3import java.io.Serializable;
  4
  5/**
  6 * Service state constants used in package javax.megaco.message.descriptor. This
  7 * defines the service state for the megaco package.
  8 */
  9public class ServiceState implements Serializable {
 10
 11	/**
 12	 * Identifies service state to be out of service. Its value shall be set to
 13	 * 0.
 14	 */
 15	public static final int M_OOS = 0;
 16
 17	/**
 18	 * Identifies service state to be in-service. Its value shall be set to 1.
 19	 */
 20	public static final int M_INS = 1;
 21
 22	/**
 23	 * Identifies service state to be "test". Its value shall be set to 2.
 24	 */
 25	public static final int M_TEST = 2;
 26
 27	/**
 28	 * Identifies a ServiceState object that constructs the class with the
 29	 * constant M_OOS. Since it is reference to static final
 30	 * object, it prevents further instantiation of the same object in the
 31	 * system.
 32	 */
 33	public static final ServiceState OOS = new ServiceState(M_OOS);
 34
 35	/**
 36	 * Identifies a ServiceState object that constructs the class with the
 37	 * constant M_INS. Since it is reference to static final
 38	 * object, it prevents further instantiation of the same object in the
 39	 * system.
 40	 */
 41	public static final ServiceState INS = new ServiceState(M_INS);
 42
 43	/**
 44	 * Identifies a ServiceState object that constructs the class with the
 45	 * constant M_TEST. Since it is reference to static final
 46	 * object, it prevents further instantiation of the same object in the
 47	 * system.
 48	 */
 49	public static final ServiceState TEST = new ServiceState(M_TEST);
 50
 51	private int serviceState = -1;
 52
 53	/**
 54	 * Constructs an class that specifies the service state in the termination
 55	 * state descriptor.
 56	 * 
 57	 * @param service_state
 58	 */
 59	private ServiceState(int service_state) {
 60		this.serviceState = service_state;
 61	}
 62
 63	/**
 64	 * This method returns one of the static field constants defined in this
 65	 * class.
 66	 * 
 67	 * @return Returns an integer value that identifies the service state to be
 68	 *         one of out of service or in-service or test.
 69	 */
 70	public int getServiceState() {
 71		return this.serviceState;
 72	}
 73
 74	/**
 75	 * Returns reference of the ServiceState object that identifies the service
 76	 * state as value passed to this method.
 77	 * 
 78	 * @param value
 79	 *            - It is one of the possible values of the static constant that
 80	 *            this class provides.
 81	 * @return Returns reference of the ServiceState object.
 82	 * @throws IllegalArgumentException
 83	 *             - If the value passed to this method is invalid, then this
 84	 *             exception is raised.
 85	 */
 86	public static final ServiceState getObject(int value) throws IllegalArgumentException {
 87
 88		switch (value) {
 89		case M_INS:
 90			return INS;
 91		case M_OOS:
 92			return OOS;
 93		case M_TEST:
 94			return TEST;
 95		default:
 96			throw new IllegalArgumentException("Wrong value of service state: " + value);
 97
 98		}
 99
100	}
101
102	/**
103	 * This method must be implemented to perform instance substitution during
104	 * serialization. This method is required for reference comparison. This
105	 * method if not implimented will simply fail each time we compare an
106	 * Enumeration value against a de-serialized Enumeration instance.
107	 * 
108	 * @return
109	 */
110	private Object readResolve() {
111		return getObject(this.serviceState);
112	}
113
114	@Override
115	public String toString() {
116		switch (this.serviceState) {
117		case M_INS:
118			return "ServiceState[INS]";
119		case M_OOS:
120			return "ServiceState[OOS]";
121		case M_TEST:
122			return "ServiceState[TEST]";
123		default:
124			return "ServiceState["+this.serviceState+"]";
125
126		}
127
128	}
129
130}