PageRenderTime 64ms CodeModel.GetById 52ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 267 lines | 91 code | 25 blank | 151 comment | 13 complexity | 0b29f4879f399831e81e3fd4a38ce01f MD5 | raw file
  1package javax.megaco.association;
  2
  3import java.io.Serializable;
  4
  5import javax.megaco.AssociationEvent;
  6
  7import javax.megaco.ParameterNotSetException;
  8
  9/**
 10 * The class extends JAIN MEGACO Association Events. This represents the delete
 11 * association request event. The event causes the stack initiate assoiation
 12 * teardown procedures with the peer. This would case the stack to send a
 13 * ServiceChange command with specified ServiceChangeMethod (e.g. Forced or
 14 * Graceful) and ServiceChangeReason. After completion of the protocol
 15 * procedure, the association is deleted with the peer and can no more be used
 16 * for exchaging commands with the peer.
 17 */
 18public class DeleteAssocReq extends AssociationEvent implements Serializable {
 19
 20	protected SrvChngReason srvChangeReason = null;
 21	protected SrvChngReason srvChngMethod = null;
 22	protected LocalAddr srvChngAddress = null;
 23	protected LocalAddr handOffMGCId = null;
 24	protected String srvChngMethodExtension = null;
 25	protected int srvChngDelay = -1;
 26
 27	public DeleteAssocReq(Object source, int assocHandle)
 28			throws IllegalArgumentException {
 29		super(source, assocHandle);
 30		// TODO Auto-generated constructor stub
 31	}
 32
 33	@Override
 34	public int getAssocOperIdentifier() {
 35		return AssocEventType.M_DELETE_ASSOC_REQ;
 36	}
 37
 38	/**
 39	 * Gets the integer value which identifies the service change reason. The
 40	 * stack would use the same ServiceChange Reason in the ServiceChange
 41	 * command request sent to peer.
 42	 * 
 43	 * @return Returns the integer value corresponding to the service change
 44	 *         reason. If the ServiceChangeReason is not set, then this method
 45	 *         would return value 0. The possible values are field constants
 46	 *         defined for the class SrvChngReason.
 47	 */
 48	public int getSrvChangeReason() {
 49		return srvChangeReason == null ? 0 : srvChangeReason
 50				.getSrvChngReasonId();
 51	}
 52
 53	/**
 54	 * This method sets the service change reason. This parameter is required on
 55	 * if the application is MG. The MG stack would use the same ServiceChange
 56	 * Reason in the ServiceChange command request sent to peer MGC.
 57	 * 
 58	 * @param reason
 59	 *            - The object reference to ServiceChange Reason.
 60	 * @throws IllegalArgumentException
 61	 *             This exception is raised if the reference of Service Change
 62	 *             Reason passed to this method is NULL.
 63	 */
 64	public void setSrvChangeReason(SrvChngReason reason)
 65			throws IllegalArgumentException {
 66		if (reason == null) {
 67			throw new IllegalArgumentException("Change reason can not be null");
 68		}
 69		this.srvChangeReason = reason;
 70	}
 71
 72	/**
 73	 * Gets the integer value which identifies the service change method. This
 74	 * parameter is required on if the application is MG. The MG stack would use
 75	 * the same ServiceChange Method in ServiceChange command request sent to
 76	 * peer MGC.
 77	 * 
 78	 * @return Returns the integer value corresponding to the service change
 79	 *         method. If the ServiceChangeMethod is not set, then this method
 80	 *         would return value 0. The possible values are field constants
 81	 *         defined for the class SrvChngMethod.
 82	 */
 83	public int getSrvChngMethod() {
 84		return srvChngMethod == null ? 0 : srvChngMethod.getSrvChngReasonId();
 85	}
 86
 87	/**
 88	 * This method sets the service change method. This parameter is required on
 89	 * if the application is MG. The MG stack would use the same ServiceChange
 90	 * Method in ServiceChange command request sent to peer MGC.
 91	 * 
 92	 * @param method
 93	 *            - The object reference to ServiceChange Method.
 94	 * @throws IllegalArgumentException
 95	 *             This exception is raised if the reference of Service Change
 96	 *             Reason passed to this method is NULL.
 97	 */
 98	public void setSrvChngMethod(SrvChngReason method)
 99			throws IllegalArgumentException {
100		if (method == null) {
101			throw new IllegalArgumentException("Change method can not be null");
102		}
103		this.srvChngMethod = method;
104	}
105
106	/**
107	 * Gets the object reference corresponding to the service change address.
108	 * The stack would use the same ServiceChange Address in the ServiceChange
109	 * command request sent to peer.
110	 * 
111	 * @return Returns the service change address. If the service change address
112	 *         has not been specified for this class, then this method returns
113	 *         NULL.
114	 */
115	public LocalAddr getSrvChngAddress() {
116		return srvChngAddress;
117	}
118
119	/**
120	 * This method sets the service change address. The stack would use the same
121	 * ServiceChange Address in the ServiceChange command request sent to peer.
122	 * 
123	 * @param srvChngAddress
124	 *            - The service change address.
125	 * @throws IllegalArgumentException
126	 *             This exception is raised if the service change address
127	 *             specified is invalid.
128	 */
129	public void setSrvChngAddress(LocalAddr srvChngAddress)
130			throws IllegalArgumentException {
131		// FIXME: IllegalArgumentException
132		this.srvChngAddress = srvChngAddress;
133	}
134
135	/**
136	 * Gets the identity of the MGC to which the association is to be handoffed.
137	 * The stack would use the same ServiceChangeMGCId in the ServiceChange
138	 * command request sent to peer.
139	 * 
140	 * @return Returns the identity of the MGC to which the association is to be
141	 *         handoffed. If HandedOffMGCId is not specified for this class,
142	 *         then this method returns NULL.
143	 */
144	public LocalAddr getHandOffMGCId() {
145		return handOffMGCId;
146	}
147
148	/**
149	 * This method sets the identity of the MGC to which the association is to
150	 * be handoffed. This method is valid only if the application is MGC. The
151	 * stack would use the same ServiceChangeMGCId in the ServiceChange command
152	 * request sent to peer.
153	 * 
154	 * 
155	 * 
156	 * @param handOffMGCId
157	 *            The identity of the MGC to which the association is to be
158	 *            handoffed.
159	 * @throws IllegalArgumentException
160	 *             This exception is raised if the HandedOffMGCId specified is
161	 *             invalid.
162	 */
163	public void setHandOffMGCId(LocalAddr handOffMGCId)
164			throws IllegalArgumentException {
165		// FIXME: IllegalArgumentException
166		this.handOffMGCId = handOffMGCId;
167	}
168
169	/**
170	 * Gets the string value of the extended service change method.
171	 * 
172	 * 
173	 * @return Returns string value of the extended service change method. This
174	 *         is to be set only if the service change method is set to
175	 *         {@link javax.megaco.association.SrvChngMethod.M_EXTENSION}.
176	 * @throws javax.megaco.association.MethodExtensionException
177	 *             javax.megaco.association.MethodExtensionException - Thrown if
178	 *             service change method has not been set to
179	 *             {@link javax.megaco.association.SrvChngMethod.M_EXTENSION}
180	 */
181	public java.lang.String getSrvChngMethodExtension()
182			throws javax.megaco.association.MethodExtensionException,
183			IllegalArgumentException {
184		if (getSrvChngMethod() != SrvChngMethod.M_EXTENSION) {
185			throw new MethodExtensionException(
186					"Changed Method is not equal to SrvChngMethod.{@link javax.megaco.association.SrvChngMethod.M_EXTENSION}");
187		}
188
189		return this.srvChngMethodExtension;
190	}
191
192	/**
193	 * This method sets the extended service change method. This needs to be set
194	 * if and only if the service change method is {@link javax.megaco.association.SrvChngMethod.M_EXTENSION}.
195	 * 
196	 * @param extMethod
197	 *            - The string value of the extended service change method.
198	 * @throws javax.megaco.association.MethodExtensionException
199	 *             - Thrown if service change method has not been set to
200	 *             {@link javax.megaco.association.SrvChngMethod.M_EXTENSION}.
201	 * @throws IllegalArgumentException
202	 *             - Thrown if extension string does not follow the rules of the
203	 *             extension parameter, e.g, should start with X+ or X- etc.
204	 */
205	public void setSrvChngMethod(java.lang.String extMethod)
206			throws javax.megaco.association.MethodExtensionException,
207			IllegalArgumentException {
208		if (getSrvChngMethod() != SrvChngMethod.M_EXTENSION) {
209			throw new MethodExtensionException(
210					"Changed Method is not equal to SrvChngMethod.{@link javax.megaco.association.SrvChngMethod.M_EXTENSION}");
211		}
212		// FIXME IllegalArgumentException - Thrown if extension
213		// string does not follow the rules of the extension parameter, e.g,
214		// should start with X+ or X- etc.
215
216		this.srvChngMethodExtension = extMethod;
217	}
218
219	/**
220	 * Gets the integer value of the delay parameter for the service change.
221	 * This is in milliseconds. This method must be invoked after invoking the
222	 * isSrvChngdelayPresent() method. The stack would use the same as the
223	 * ServiceChangeDelay in the ServiceChange command request sent to peer.
224	 * 
225	 * @return Returns the integer value of the delay value in milliseconds.
226	 * @throws javax.megaco.ParameterNotSetException
227	 *             This exception is raised if the service change delay
228	 *             parameter has not been set.
229	 */
230	public int getSrvChngDelay() throws javax.megaco.ParameterNotSetException {
231		if (this.srvChngDelay == -1) {
232			throw new ParameterNotSetException();
233		}
234
235		return this.srvChngDelay;
236	}
237
238	/**
239	 * Sets the integer value of the delay parameter for the service change.
240	 * This is in milliseconds. This automatically sets the service change delay
241	 * value to be present. The stack would use the same as the
242	 * ServiceChangeDelay in the ServiceChange command request sent to peer.
243	 * 
244	 * 
245	 * @param delay - The integer value of the delay value in milliseconds.
246	 * @throws IllegalArgumentException This exception is raised if the value of service change delay passed to this method is less than 0.
247	 */
248	public void setSrvChngDelay(int delay)
249			throws IllegalArgumentException {
250		if(delay<0)
251		{
252			throw new IllegalArgumentException("Delay can not be less than zero");
253		}
254		
255		
256		this.srvChngDelay=delay;
257		
258	}
259	/**
260	 * Returns TRUE if the service change delay parameter is present.
261	 * @return TRUE if service change delay parameter has been set, else returns FALSE.
262	 */
263	public boolean isSrvChngDelayPresent()
264	{
265		return this.srvChngDelay!=-1;
266	}
267}