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

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

http://mobicents.googlecode.com/
Java | 147 lines | 53 code | 22 blank | 72 comment | 13 complexity | a7cea7d95208975eeef42ca1b9e2d812 MD5 | raw file
  1package javax.megaco.message.descriptor;
  2
  3import java.io.Serializable;
  4
  5
  6import javax.megaco.MethodInvocationException;
  7import javax.megaco.message.Descriptor;
  8import javax.megaco.message.DescriptorType;
  9import javax.megaco.message.Termination;
 10
 11/**
 12 * The class extends JAIN MEGACO Descriptor. This class describes the mux
 13 * descriptor.
 14 */
 15public class MuxDescriptor extends Descriptor implements Serializable {
 16
 17	private MuxType muxType;
 18	private Termination[] termList;
 19	private String extMux;
 20
 21	/**
 22	 * Constructs a Mux Descriptor with the mux type and the termination id
 23	 * list.
 24	 * 
 25	 * @param muxType
 26	 *            - This specifies an object identifier of the mux type to be
 27	 *            specified for the mux descriptor.
 28	 * @param termList
 29	 *            - This specifies list of termination ids for the specified mux
 30	 *            type.
 31	 * @throws IllegalArgumentException
 32	 *             : This exception is raised if the reference of MuxType or
 33	 *             Termination Id list passed to this method is NULL.
 34	 */
 35	public MuxDescriptor(MuxType muxType, Termination[] termList) throws IllegalArgumentException {
 36
 37		super.descriptorId = DescriptorType.M_MUX_DESC;
 38
 39		if (muxType == null) {
 40			throw new IllegalArgumentException("MuxType must not be null");
 41		}
 42
 43		if (termList == null) {
 44			throw new IllegalArgumentException("Termination[] must not be null");
 45		}
 46
 47		if (termList.length == 0) {
 48			throw new IllegalArgumentException("Termination[] lmust not be empty");
 49		}
 50
 51		this.muxType = muxType;
 52		this.termList = termList;
 53	}
 54
 55	/**
 56	 * This method cannot be overridden by the derived class. This method
 57	 * returns that the descriptor identifier is of type Mux descriptor. This
 58	 * method overrides the corresponding method of the base class Descriptor.
 59	 * 
 60	 * @return Returns an integer value that identifies this object as the type
 61	 *         of Mux descriptor. It returns that it is Mux Descriptor i.e.,
 62	 *         M_MUX_DESC.
 63	 */
 64	public int getDescriptorId() {
 65		return super.descriptorId;
 66	}
 67
 68	/**
 69	 * This method cannot be overridden by the derived class. This method
 70	 * returns the identity of the mux type. The constants for the mux type are
 71	 * defined in MuxType.
 72	 * 
 73	 * @return Returns value that identifies Mux type. It returns one of the
 74	 *         values defined in, MuxType.
 75	 */
 76	public final MuxType getMuxType() {
 77		return this.muxType;
 78	}
 79
 80	/**
 81	 * This method returns the extension string of the mux type. The extension
 82	 * string should be prefixed with "X-" or "X+". The extension characters
 83	 * following the prefix should be at most of 6 characters. The extension
 84	 * string would be set only when the mux type specifies MUX_TYPE_EXTENSION.
 85	 * 
 86	 * @return Gets the string for the extension of the mux type. The extension
 87	 *         string would be set only when the mux type specifies
 88	 *         {@link MuxType.EXT}.
 89	 * @throws IllegalStateException
 90	 *             if the method has been called when the mux type denotes
 91	 *             anything other than {@link MuxType.EXT}.
 92	 */
 93	public java.lang.String getExtensionString() throws IllegalStateException {
 94		if (this.muxType.getMuxType() != muxType.M_EXT) {
 95			throw new IllegalStateException("MuxType must be: EXT");
 96		}
 97		return this.extMux;
 98	}
 99
100	/**
101	 * Sets the string for the extension of the mux type. Should be set only
102	 * when the mux type specifies MUX_TYPE_EXT.
103	 * 
104	 * @param extMux
105	 *            - Sets the string for the extension of the mux type. The
106	 *            extension string should be prefixed with "X-" or "X+". The
107	 *            extension characters following the prefix should be at most of
108	 *            6 characters. The extension string would be set only when the
109	 *            mux type specifies {@link MuxType.EXT}.
110	 * @throws IllegalArgumentException
111	 *             if the extension string is not in proper format. It should be
112	 *             prefixed with either "X+" or "X-" followed by at most 6
113	 *             characters.
114	 * @throws IllegalStateException
115	 *             if the method has been called when the mux type denotes
116	 *             anything other than {@link MuxType.EXT}.
117	 */
118	public void setExtensionString(java.lang.String extMux) throws IllegalArgumentException, IllegalStateException {
119
120		if (this.muxType.getMuxType() != muxType.M_EXT) {
121			throw new IllegalStateException("MuxType must be: EXT");
122		}
123
124		if (extMux == null) {
125			new IllegalArgumentException("ExtMux must not be null");
126		}
127
128		DescriptorUtils.checkMethodExtensionRules(extMux);
129
130		if (extMux.length() > 8) {
131			throw new IllegalArgumentException("ExtMux must not be longer than 8 characters.");
132		}
133		this.extMux = extMux;
134
135	}
136
137	/**
138	 * Gets the list of termination ids for which the mux type is specified.
139	 * 
140	 * @return Returns the list of termination ids for which the muxt type is
141	 *         specified.
142	 */
143	public final Termination[] getTerminationIdList() {
144		return this.termList;
145	}
146
147}