/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/dialog/MAPUserAbortInfoImpl.java

http://mobicents.googlecode.com/ · Java · 276 lines · 170 code · 44 blank · 62 comment · 22 complexity · 4daae1629052f6970714172c7675a07c MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.ss7.map.dialog;
  23. import java.io.IOException;
  24. import org.mobicents.protocols.asn.AsnException;
  25. import org.mobicents.protocols.asn.AsnInputStream;
  26. import org.mobicents.protocols.asn.AsnOutputStream;
  27. import org.mobicents.protocols.asn.Tag;
  28. import org.mobicents.protocols.ss7.map.api.MAPException;
  29. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
  30. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason;
  31. import org.mobicents.protocols.ss7.map.api.dialog.MAPUserAbortChoice;
  32. import org.mobicents.protocols.ss7.map.api.dialog.ProcedureCancellationReason;
  33. import org.mobicents.protocols.ss7.map.api.dialog.ResourceUnavailableReason;
  34. import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
  35. import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
  36. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  37. /**
  38. * MAP-UserAbortInfo ::= SEQUENCE { map-UserAbortChoice MAP-UserAbortChoice, ...
  39. * extensionContainer ExtensionContainer OPTIONAL }
  40. *
  41. * MAP-UserAbortChoice ::= CHOICE { userSpecificReason [0] NULL,
  42. * userResourceLimitation [1] NULL, resourceUnavailable [2]
  43. * ResourceUnavailableReason, applicationProcedureCancellation [3]
  44. * ProcedureCancellationReason}
  45. *
  46. * @author amit bhayani
  47. * @author sergey vetyutnev
  48. *
  49. */
  50. public class MAPUserAbortInfoImpl implements MAPAsnPrimitive {
  51. public static final int MAP_USER_ABORT_INFO_TAG = 0x04;
  52. protected static final int USER_ABORT_TAG_CLASS = Tag.CLASS_CONTEXT_SPECIFIC;
  53. protected static final boolean USER_ABORT_TAG_PC_CONSTRUCTED = false;
  54. private MAPUserAbortChoice mapUserAbortChoice = null;
  55. private MAPExtensionContainer extensionContainer;
  56. public MAPUserAbortChoice getMAPUserAbortChoice() {
  57. return this.mapUserAbortChoice;
  58. }
  59. public MAPExtensionContainer getExtensionContainer() {
  60. return extensionContainer;
  61. }
  62. public void setMAPUserAbortChoice(MAPUserAbortChoice mapUsrAbrtChoice) {
  63. this.mapUserAbortChoice = mapUsrAbrtChoice;
  64. }
  65. public void setExtensionContainer(MAPExtensionContainer extensionContainer) {
  66. this.extensionContainer = extensionContainer;
  67. }
  68. @Override
  69. public int getTag() throws MAPException {
  70. return MAP_USER_ABORT_INFO_TAG;
  71. }
  72. @Override
  73. public int getTagClass() {
  74. return Tag.CLASS_CONTEXT_SPECIFIC;
  75. }
  76. @Override
  77. public boolean getIsPrimitive() {
  78. return false;
  79. }
  80. @Override
  81. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  82. try {
  83. int length = ansIS.readLength();
  84. this._decode(ansIS, length);
  85. } catch (IOException e) {
  86. throw new MAPParsingComponentException("IOException when decoding MAPUserAbortInfo: " + e.getMessage(), e,
  87. MAPParsingComponentExceptionReason.MistypedParameter);
  88. } catch (AsnException e) {
  89. throw new MAPParsingComponentException("AsnException when decoding MAPUserAbortInfo: " + e.getMessage(), e,
  90. MAPParsingComponentExceptionReason.MistypedParameter);
  91. }
  92. }
  93. @Override
  94. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  95. try {
  96. this._decode(ansIS, length);
  97. } catch (IOException e) {
  98. throw new MAPParsingComponentException("IOException when decoding MAPUserAbortInfo: " + e.getMessage(), e,
  99. MAPParsingComponentExceptionReason.MistypedParameter);
  100. } catch (AsnException e) {
  101. throw new MAPParsingComponentException("AsnException when decoding MAPUserAbortInfo: " + e.getMessage(), e,
  102. MAPParsingComponentExceptionReason.MistypedParameter);
  103. }
  104. }
  105. private void _decode(AsnInputStream ais, int length) throws MAPParsingComponentException, IOException, AsnException {
  106. // MAP-UserAbortInfo ::= SEQUENCE {
  107. // map-UserAbortChoice CHOICE {
  108. // userSpecificReason [0] IMPLICIT NULL,
  109. // userResourceLimitation [1] IMPLICIT NULL,
  110. // resourceUnavailable [2] IMPLICIT ENUMERATED {
  111. // shortTermResourceLimitation ( 0 ),
  112. // longTermResourceLimitation ( 1 ) },
  113. // applicationProcedureCancellation [3] IMPLICIT ENUMERATED {
  114. // handoverCancellation ( 0 ),
  115. // radioChannelRelease ( 1 ),
  116. // networkPathRelease ( 2 ),
  117. // callRelease ( 3 ),
  118. // associatedProcedureFailure ( 4 ),
  119. // tandemDialogueRelease ( 5 ),
  120. // remoteOperationsFailure ( 6 ) }},
  121. // ... ,
  122. // extensionContainer SEQUENCE {
  123. // privateExtensionList [0] IMPLICIT SEQUENCE ( SIZE( 1 .. 10 ) ) OF
  124. // SEQUENCE {
  125. // extId MAP-EXTENSION .&extensionId ( {
  126. // ,
  127. // ...} ) ,
  128. // extType MAP-EXTENSION .&ExtensionType ( {
  129. // ,
  130. // ...} { @extId } ) OPTIONAL} OPTIONAL,
  131. // pcs-Extensions [1] IMPLICIT SEQUENCE {
  132. // ... } OPTIONAL,
  133. // ... } OPTIONAL}
  134. this.mapUserAbortChoice = null;
  135. this.extensionContainer = null;
  136. AsnInputStream localAis = ais.readSequenceStreamData(length);
  137. int tag = localAis.readTag();
  138. if (localAis.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !localAis.isTagPrimitive())
  139. throw new MAPParsingComponentException("Error while decoding MAPUserAbortInfo.map-UserAbortChoice: bad tag class or not primitive element",
  140. MAPParsingComponentExceptionReason.MistypedParameter);
  141. MAPUserAbortChoiceImpl usAbrtChoice = new MAPUserAbortChoiceImpl();
  142. switch (tag) {
  143. case MAPUserAbortChoiceImpl.USER_SPECIFIC_REASON_TAG:
  144. localAis.readNull();
  145. usAbrtChoice.setUserSpecificReason();
  146. this.setMAPUserAbortChoice(usAbrtChoice);
  147. break;
  148. case MAPUserAbortChoiceImpl.USER_RESOURCE_LIMITATION_TAG:
  149. localAis.readNull();
  150. usAbrtChoice.setUserResourceLimitation();
  151. this.setMAPUserAbortChoice(usAbrtChoice);
  152. break;
  153. case MAPUserAbortChoiceImpl.RESOURCE_UNAVAILABLE:
  154. int code = (int) localAis.readInteger();
  155. ResourceUnavailableReason resUnaReas = ResourceUnavailableReason.getInstance(code);
  156. usAbrtChoice.setResourceUnavailableReason(resUnaReas);
  157. this.setMAPUserAbortChoice(usAbrtChoice);
  158. break;
  159. case MAPUserAbortChoiceImpl.APPLICATION_PROCEDURE_CANCELLATION:
  160. code = (int) localAis.readInteger();
  161. ProcedureCancellationReason procCanReasn = ProcedureCancellationReason.getInstance(code);
  162. usAbrtChoice.setProcedureCancellationReason(procCanReasn);
  163. this.setMAPUserAbortChoice(usAbrtChoice);
  164. break;
  165. default:
  166. throw new MAPParsingComponentException("Error while decoding MAPUserAbortInfo.map-UserAbortChoice: bad tag",
  167. MAPParsingComponentExceptionReason.MistypedParameter);
  168. }
  169. while (localAis.available() > 0) {
  170. tag = localAis.readTag();
  171. switch (localAis.getTagClass()) {
  172. case Tag.CLASS_UNIVERSAL:
  173. switch (tag) {
  174. case Tag.SEQUENCE:
  175. this.extensionContainer = new MAPExtensionContainerImpl();
  176. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(localAis);
  177. break;
  178. default:
  179. localAis.advanceElement();
  180. break;
  181. }
  182. break;
  183. default:
  184. localAis.advanceElement();
  185. break;
  186. }
  187. }
  188. }
  189. @Override
  190. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  191. this.encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, MAP_USER_ABORT_INFO_TAG);
  192. }
  193. @Override
  194. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  195. try {
  196. asnOs.writeTag(tagClass, false, tag);
  197. int pos = asnOs.StartContentDefiniteLength();
  198. this.encodeData(asnOs);
  199. asnOs.FinalizeContent(pos);
  200. } catch (AsnException e) {
  201. throw new MAPException("AsnException when encoding MAPUserAbortInfo: " + e.getMessage(), e);
  202. }
  203. }
  204. @Override
  205. public void encodeData(AsnOutputStream asnOS) throws MAPException {
  206. if (this.mapUserAbortChoice == null)
  207. throw new MAPException("Error encoding MAPUserAbortInfo: UserSpecificReason must not be null");
  208. try {
  209. if(this.mapUserAbortChoice.isUserSpecificReason()) {
  210. asnOS.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, MAPUserAbortChoiceImpl.USER_SPECIFIC_REASON_TAG);
  211. } else if(this.mapUserAbortChoice.isUserResourceLimitation()) {
  212. asnOS.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, MAPUserAbortChoiceImpl.USER_RESOURCE_LIMITATION_TAG);
  213. } else if(this.mapUserAbortChoice.isResourceUnavailableReason()) {
  214. ResourceUnavailableReason rur = this.mapUserAbortChoice.getResourceUnavailableReason();
  215. if (rur == null)
  216. throw new MAPException("Error encoding MAPUserAbortInfo: ResourceUnavailableReason value must not be null");
  217. asnOS.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, MAPUserAbortChoiceImpl.RESOURCE_UNAVAILABLE, rur.getCode());
  218. } else if(this.mapUserAbortChoice.isProcedureCancellationReason()) {
  219. ProcedureCancellationReason pcr = this.mapUserAbortChoice.getProcedureCancellationReason();
  220. if (pcr == null)
  221. throw new MAPException("Error encoding MAPUserAbortInfo: ProcedureCancellationReason value must not be null");
  222. asnOS.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, MAPUserAbortChoiceImpl.APPLICATION_PROCEDURE_CANCELLATION, pcr.getCode());
  223. }
  224. if (this.extensionContainer != null)
  225. ((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOS);
  226. } catch (IOException e) {
  227. throw new MAPException("IOException when encoding MAPUserAbortInfo: " + e.getMessage(), e);
  228. } catch (AsnException e) {
  229. throw new MAPException("AsnException when encoding MAPUserAbortInfo: " + e.getMessage(), e);
  230. }
  231. }
  232. }