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

http://mobicents.googlecode.com/ · Java · 466 lines · 150 code · 62 blank · 254 comment · 34 complexity · 42523ba667881216bc753dc8fc56aa84 MD5 · raw file

  1. package javax.megaco.message.descriptor;
  2. import java.io.Serializable;
  3. import javax.megaco.ParameterNotSetException;
  4. import javax.megaco.association.LocalAddr;
  5. import javax.megaco.association.MethodExtensionException;
  6. import javax.megaco.association.SrvChngMethod;
  7. import javax.megaco.association.SrvChngReason;
  8. import javax.megaco.message.Descriptor;
  9. import javax.megaco.message.DescriptorType;
  10. /**
  11. * The class extends JAIN MEGACO Descriptor. This class represents the service
  12. * change descriptor defined in the MEGACO protocol. This descriptor describes
  13. * the service change method, reason, delay, address, profile, mgcid, version,
  14. * the timestamp and any extension to it. Among these the service change method
  15. * is mandatory.
  16. */
  17. public class SrvChngDescriptor extends Descriptor implements Serializable {
  18. private SrvChngMethod srvChngMethod;
  19. private String svcChngMethodExtension;
  20. private SrvChngReason srvChngReason;
  21. private Integer srvChngDelay;
  22. private LocalAddr srvChngAddress;
  23. private String srvChngProfile;
  24. private LocalAddr handOffMGCId;
  25. private Integer protocolVersion;
  26. private String dateValue;
  27. private String timeValue;
  28. private String parameterExtension;
  29. /**
  30. * Constructs a SrvChng Descriptor. The service change descriptor class
  31. * contain service change method and atleast one of service change method,
  32. * reason, delay, address, profile, mgcid, version, the timestamp and any
  33. * extension parameter.
  34. */
  35. public SrvChngDescriptor() {
  36. super.descriptorId = DescriptorType.M_SERVICE_CHANGE_DESC;
  37. }
  38. /**
  39. * This method cannot be overridden by the derived class. This method
  40. * returns that the descriptor identifier is of type descriptor SrvChng.
  41. * This method overrides the corresponding method of the base class
  42. * Descriptor.
  43. *
  44. * @return Returns an integer value that identifies this service change
  45. * object as the type of service change descriptor. It returns the
  46. * the value M_SERVICE_CHANGE_DESC of a Service Change Descriptor.
  47. */
  48. public int getDescriptorId() {
  49. return super.descriptorId;
  50. }
  51. /**
  52. * Gets the integer value which identifies the service change method.
  53. *
  54. * @return Returns the integer value of service change method. The values of
  55. * the service change method are defined in SrvChngMethod. The
  56. * service change method is to be mandatorily set. If Service Change
  57. * method is not set then this method would return null.
  58. */
  59. public SrvChngMethod getSrvChngMethod() {
  60. return this.srvChngMethod;
  61. }
  62. /**
  63. * This method sets the service change method. The values of the service
  64. * change method are defined in SrvChngMethod. The service change method is
  65. * to be mandatorily set.
  66. *
  67. * @param method
  68. * The object reference of service change method.
  69. * @throws IllegalArgumentException
  70. * : This exception is raised if the reference of Service Change
  71. * Method passed to this method is NULL.
  72. */
  73. public void setSrvChngMethod(SrvChngMethod method) throws IllegalArgumentException {
  74. if (method == null) {
  75. throw new IllegalArgumentException("SrvChngMethod must not be null.");
  76. }
  77. this.srvChngMethod = method;
  78. }
  79. /**
  80. * Gets the string value of the extended service change method.
  81. *
  82. * @return Returns string value of the extended service change method. This
  83. * is to be set only if the service change method is set to
  84. * {@link javax.megaco.association.SrvChngMethod.M_EXTENSION}.
  85. * @throws javax.megaco.association.MethodExtensionException
  86. * - Thrown if service change method has not been set to
  87. * {@link javax.megaco.association.SrvChngMethod.M_EXTENSION}.
  88. */
  89. public java.lang.String getSvcChngMethodExtension() throws javax.megaco.association.MethodExtensionException {
  90. if (this.srvChngMethod == null || this.srvChngMethod.getSrvChngMethodId() != srvChngMethod.M_EXTENSION) {
  91. throw new MethodExtensionException("SrvChngMethod must be set to: SVC_CHNG_METHOD_EXTENSION");
  92. }
  93. return this.svcChngMethodExtension;
  94. }
  95. /**
  96. * This method sets the extended service change method. This needs to be set
  97. * if and only if the service change method is {@link javax.megaco.association.SrvChngMethod.M_EXTENSION}.
  98. *
  99. * @param extMethod
  100. * - The string value of the extended service change method.
  101. * @throws javax.megaco.association.MethodExtensionException
  102. * - Thrown if service change method has not been set to
  103. * {@link javax.megaco.association.SrvChngMethod.M_EXTENSION}.
  104. * @throws IllegalArgumentException
  105. * - Thrown if extension string does not follow the rules of the
  106. * extension parameter, e.g, should start with X+ or X- etc.
  107. */
  108. public void setSvcChngMethodExtension(java.lang.String extMethod) throws javax.megaco.association.MethodExtensionException, IllegalArgumentException {
  109. if (this.srvChngMethod == null || this.srvChngMethod.getSrvChngMethodId() != srvChngMethod.M_EXTENSION) {
  110. throw new MethodExtensionException("SrvChngMethod must be set to: SVC_CHNG_METHOD_EXTENSION");
  111. }
  112. DescriptorUtils.checkMethodExtensionRules(extMethod);
  113. this.svcChngMethodExtension = extMethod;
  114. }
  115. /**
  116. * Gets the integer value which identifies the service change reason.
  117. *
  118. * @return Returns the object reference corresponding to the service change
  119. * reason. The values of the service change reason are defined in
  120. * SrvChngReason. If the ServiceChangeReason is not set, then this
  121. * method would return value null.
  122. */
  123. public SrvChngReason getSrvChngReason() {
  124. return this.srvChngReason;
  125. }
  126. /**
  127. * This method sets the service change reason. The values of the service
  128. * change reason are defined in SrvChngReason.
  129. *
  130. * @param reasonCode
  131. * The object reference to the corresponding service change
  132. * reason.
  133. * @throws IllegalArgumentException
  134. * - Thrown if the reference of ServiceChange reason passed to
  135. * this method is NULL.
  136. */
  137. public void setSrvChngReason(SrvChngReason reasonCode) throws IllegalArgumentException {
  138. if (reasonCode == null) {
  139. throw new IllegalArgumentException("SrvChngReason must not be null.");
  140. }
  141. this.srvChngReason = reasonCode;
  142. }
  143. /**
  144. * Gets the service change delay value received from peer in the service
  145. * change.
  146. *
  147. * @return Returns the service change delay parameter as an integer value.
  148. * @throws javax.megaco.ParameterNotSetException
  149. * - Thrown if service change delay parameter has not been set.
  150. */
  151. public int getSrvChngDelay() throws javax.megaco.ParameterNotSetException {
  152. if (!isSrvChngDelayPresent()) {
  153. throw new ParameterNotSetException("SrvChngDelay is not present.");
  154. }
  155. return this.srvChngDelay.intValue();
  156. }
  157. /**
  158. *
  159. This method sets the service change delay value.
  160. *
  161. * @param delay
  162. * The service change delay as an integer value.
  163. * @throws IllegalArgumentException
  164. * : This exception is raised if the value of service change
  165. * delay passed to this method is less than 0.
  166. */
  167. public void setSrvChngDelay(int delay) throws IllegalArgumentException {
  168. if (delay <= 0) {
  169. throw new IllegalArgumentException("Delay must be greater than zero.");
  170. }
  171. this.srvChngDelay = new Integer(delay);
  172. }
  173. /**
  174. * Identifies whether the service change delay is present.
  175. *
  176. * @return Returns true if the service change delay is present.
  177. */
  178. public boolean isSrvChngDelayPresent() {
  179. return this.srvChngDelay != null;
  180. }
  181. /**
  182. * Gets the service change address. If the service change command has been
  183. * received from peer, then it refers to the the new transport address the
  184. * peer intends to use subsequently.
  185. *
  186. * @return Returns the service change address. If the service change address
  187. * is missing, then the method would return NULL.
  188. */
  189. public LocalAddr getSrvChngAddress() {
  190. return this.srvChngAddress;
  191. }
  192. /**
  193. * This method sets the service change address. This is not a mandatory
  194. * parameter.
  195. *
  196. * @param LocalAddr
  197. * The object reference of service change address.
  198. * @throws IllegalArgumentException
  199. * - Thrown if a parameter in service change address is set such
  200. * that it is invalid.
  201. */
  202. public void setSrvChngAddress(LocalAddr localAddr) throws IllegalArgumentException {
  203. // FIXME: not present in jdoc
  204. if (localAddr == null) {
  205. throw new IllegalArgumentException("LocalAddr must not be null.");
  206. }
  207. // FIXME: add error checks?
  208. this.srvChngAddress = localAddr;
  209. }
  210. /**
  211. * Gets the service change profile value received from peer in the service
  212. * change.
  213. *
  214. * @return Returns the service change profile parameter as a string value.
  215. * If the service change profile is not set then it returns a NULL
  216. * value.
  217. */
  218. public java.lang.String getSrvChngProfile() {
  219. return this.srvChngProfile;
  220. }
  221. /**
  222. * This method sets the service change profile value.
  223. *
  224. * @param profile
  225. * The service change profile as a string value.
  226. * @throws IllegalArgumentException
  227. * - Thrown if service change profile parameter has invalid
  228. * format.
  229. */
  230. public void setSrvChngProfile(java.lang.String profile) throws IllegalArgumentException {
  231. if (profile == null) {
  232. throw new IllegalArgumentException("profile must not be null.");
  233. }
  234. DescriptorUtils.checkSrvcChngProfileRules(profile);
  235. this.srvChngProfile = profile;
  236. }
  237. /**
  238. * Gets the identity of the MGC to which the association is to be handoffed.
  239. * As specified in the protocol, in case of failure of MGC, it would handoff
  240. * the control of the MG to the new MGC. This is conveyed using service
  241. * change command on ROOT termination, with service change method set to
  242. * M_HANDOFF and transport parameters of the new MGC
  243. * specified in the mgcidToTry field of the service change descriptor. This
  244. * mgcidToTry field of the service change descriptor is represented using
  245. * HandedOffMGCId field on this class.
  246. *
  247. * @return Returns the identity of the MGC to which the association is to be
  248. * handoffed.
  249. */
  250. public LocalAddr getHandOffMGCId() {
  251. return this.handOffMGCId;
  252. }
  253. /**
  254. * This method sets the identity of the MGC to which the association is to
  255. * be handoffed.
  256. *
  257. * As specified in the protocol, in case of failure of MGC, it would handoff
  258. * the control of the MG to the new MGC. This is conveyed using service
  259. * change command on ROOT termination, with service change method set to
  260. * M_HANDOFF and transport parameters of the new MGC
  261. * specified in the mgcidToTry field of the service change descriptor. This
  262. * mgcidToTry field of the service change descriptor is represented using
  263. * HandedOffMGCId field on this class.
  264. *
  265. * @param mgcidToTry
  266. * The identity of the MGC to which the association is to be
  267. * handoffed.
  268. * @throws IllegalArgumentException
  269. * - Thrown if a parameter in mgc Id is set such that it is
  270. * invalid.
  271. */
  272. public void setHandOffMGCId(LocalAddr mgcidToTry) throws IllegalArgumentException {
  273. // FIXME: not present in jdoc
  274. if (mgcidToTry == null) {
  275. throw new IllegalArgumentException("LocalAddr must not be null.");
  276. }
  277. if (srvChngMethod == null || srvChngMethod.getSrvChngMethodId() != srvChngMethod.M_HANDOFF) {
  278. throw new IllegalArgumentException("SrvChngMethodId must be set to: SVC_CHNG_METHOD_HANDOFF.");
  279. }
  280. // FIXME: add error checks?
  281. this.handOffMGCId = mgcidToTry;
  282. }
  283. /**
  284. * Gets the protocol version value received from peer in the service change.
  285. * This is ther protocol version after negotiation.
  286. *
  287. * @return Returns the protocol version parameter as an integer value.
  288. * @throws javax.megaco.ParameterNotSetException
  289. * - Thrown if protocol version has not been set.
  290. */
  291. public int getProtocolVersion() throws javax.megaco.ParameterNotSetException {
  292. if (!isProtocolVersionPresent()) {
  293. throw new ParameterNotSetException("Protocol Version has not been set.");
  294. }
  295. return this.protocolVersion.intValue();
  296. }
  297. /**
  298. * This method sets the protocol version value.
  299. *
  300. * @param version
  301. * The protocol version as an integer value.
  302. * @throws IllegalArgumentException
  303. * - Thrown if service change version parameter is less than or
  304. * equal to 0.
  305. */
  306. public void setProtocolVersion(int version) throws IllegalArgumentException {
  307. if (version <= 0) {
  308. throw new IllegalArgumentException("Protocol Version must be greater than zero.");
  309. }
  310. this.protocolVersion = new Integer(version);
  311. }
  312. /**
  313. * Identifies whether the protocol version is present.
  314. *
  315. * @return Returns true if the protocol version is present.
  316. */
  317. public boolean isProtocolVersionPresent() {
  318. return this.protocolVersion != null;
  319. }
  320. /**
  321. * Gets the string value of the date value of timestamp in service change
  322. * descriptor.
  323. *
  324. * @return Returns string value of the date value of timestamp in service
  325. * change. If the date value of timestamp in service change is not
  326. * set then a NULL value is returned.
  327. */
  328. public java.lang.String getDateValue() {
  329. return this.dateValue;
  330. }
  331. /**
  332. * This method sets the date value of timestamp in service change
  333. * descriptor.
  334. *
  335. * @param dateValue
  336. * The string value of the date value of timestamp in service
  337. * change descriptor.
  338. * @throws IllegalArgumentException
  339. * - Thrown if date value of timestamp in service change
  340. * descriptor is not of 8 digit length.
  341. */
  342. public void setDateValue(java.lang.String dateValue) throws IllegalArgumentException {
  343. if (dateValue == null) {
  344. new IllegalArgumentException("DateValue must nto be null.");
  345. }
  346. DescriptorUtils.checkTimeStampRules(dateValue);
  347. this.dateValue = dateValue;
  348. }
  349. /**
  350. * Gets the string value of the time value of timestamp in service change
  351. * descriptor.
  352. *
  353. * @return Returns string value of the time value of timestamp in service
  354. * change descriptor. If the time value of timestamp in service
  355. * change descriptor is not set then a NULL value is returned.
  356. */
  357. public java.lang.String getTimeValue() {
  358. return this.timeValue;
  359. }
  360. /**
  361. * This method sets the time value of timestamp in service change
  362. * descriptor.
  363. *
  364. * @param timeValue
  365. * The string value of the time value of timestamp in service
  366. * change descriptor.
  367. * @throws IllegalArgumentException
  368. * - Thrown if time value of timestamp in service change
  369. * descriptor is not of 8 digit length.
  370. */
  371. public void setTimeValue(java.lang.String timeValue) throws IllegalArgumentException {
  372. if (timeValue == null) {
  373. new IllegalArgumentException("TimeValue must nto be null.");
  374. }
  375. DescriptorUtils.checkTimeStampRules(timeValue);
  376. this.timeValue = timeValue;
  377. }
  378. /**
  379. * Gets the string value of the extended service change parameter.
  380. *
  381. * @return Returns string value of the extended service change parameter. If
  382. * the service change parameter is not set then this a NULL value is
  383. * returned.
  384. */
  385. public java.lang.String getParameterExtension() {
  386. return this.parameterExtension;
  387. }
  388. /**
  389. * This method sets the extended service change parameter.
  390. *
  391. * @param extMethod
  392. * The string value of the extended service change parameter.
  393. * @throws IllegalArgumentException
  394. * - Thrown if extension string does not follow the rules of the
  395. * extension parameter, e.g, should start with X+ or X- etc.
  396. */
  397. public void setParameterExtention(java.lang.String extMethod) throws IllegalArgumentException {
  398. if (extMethod == null) {
  399. new IllegalArgumentException("ExtMethod must nto be null.");
  400. }
  401. DescriptorUtils.checkMethodExtensionRules(extMethod);
  402. this.parameterExtension = extMethod;
  403. }
  404. }