/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/sms/SendRoutingInfoForSMResponseIndicationImpl.java

http://mobicents.googlecode.com/ · Java · 249 lines · 181 code · 45 blank · 23 comment · 32 complexity · 227d76c736ac7b99badea56e9c7bf193 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.service.sms;
  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.MAPMessageType;
  30. import org.mobicents.protocols.ss7.map.api.MAPOperationCode;
  31. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
  32. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason;
  33. import org.mobicents.protocols.ss7.map.api.primitives.IMSI;
  34. import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
  35. import org.mobicents.protocols.ss7.map.api.service.sms.LocationInfoWithLMSI;
  36. import org.mobicents.protocols.ss7.map.api.service.sms.SendRoutingInfoForSMResponseIndication;
  37. import org.mobicents.protocols.ss7.map.primitives.IMSIImpl;
  38. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  39. public class SendRoutingInfoForSMResponseIndicationImpl extends SmsMessageImpl implements SendRoutingInfoForSMResponseIndication {
  40. protected static final int _TAG_LocationInfoWithLMSI = 0;
  41. protected static final int _TAG_ExtensionContainer = 4;
  42. private IMSI imsi;
  43. private LocationInfoWithLMSI locationInfoWithLMSI;
  44. private MAPExtensionContainer extensionContainer;
  45. public SendRoutingInfoForSMResponseIndicationImpl() {
  46. }
  47. public SendRoutingInfoForSMResponseIndicationImpl(IMSI imsi, LocationInfoWithLMSI locationInfoWithLMSI, MAPExtensionContainer extensionContainer) {
  48. this.imsi = imsi;
  49. this.locationInfoWithLMSI = locationInfoWithLMSI;
  50. this.extensionContainer = extensionContainer;
  51. }
  52. @Override
  53. public MAPMessageType getMessageType() {
  54. return MAPMessageType.sendRoutingInfoForSM_Response;
  55. }
  56. @Override
  57. public int getOperationCode() {
  58. return MAPOperationCode.sendRoutingInfoForSM;
  59. }
  60. @Override
  61. public IMSI getIMSI() {
  62. return this.imsi;
  63. }
  64. @Override
  65. public LocationInfoWithLMSI getLocationInfoWithLMSI() {
  66. return this.locationInfoWithLMSI;
  67. }
  68. @Override
  69. public MAPExtensionContainer getExtensionContainer() {
  70. return this.extensionContainer;
  71. }
  72. @Override
  73. public int getTag() throws MAPException {
  74. return Tag.SEQUENCE;
  75. }
  76. @Override
  77. public int getTagClass() {
  78. return Tag.CLASS_UNIVERSAL;
  79. }
  80. @Override
  81. public boolean getIsPrimitive() {
  82. return false;
  83. }
  84. @Override
  85. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  86. try {
  87. int length = ansIS.readLength();
  88. this._decode(ansIS, length);
  89. } catch (IOException e) {
  90. throw new MAPParsingComponentException("IOException when decoding sendRoutingInfoForSMResponse: " + e.getMessage(), e,
  91. MAPParsingComponentExceptionReason.MistypedParameter);
  92. } catch (AsnException e) {
  93. throw new MAPParsingComponentException("AsnException when decoding sendRoutingInfoForSMResponse: " + e.getMessage(), e,
  94. MAPParsingComponentExceptionReason.MistypedParameter);
  95. }
  96. }
  97. @Override
  98. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  99. try {
  100. this._decode(ansIS, length);
  101. } catch (IOException e) {
  102. throw new MAPParsingComponentException("IOException when decoding sendRoutingInfoForSMResponse: " + e.getMessage(), e,
  103. MAPParsingComponentExceptionReason.MistypedParameter);
  104. } catch (AsnException e) {
  105. throw new MAPParsingComponentException("AsnException when decoding sendRoutingInfoForSMResponse: " + e.getMessage(), e,
  106. MAPParsingComponentExceptionReason.MistypedParameter);
  107. }
  108. }
  109. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  110. this.imsi = null;
  111. this.locationInfoWithLMSI = null;
  112. this.extensionContainer = null;
  113. AsnInputStream ais = ansIS.readSequenceStreamData(length);
  114. int num = 0;
  115. while (true) {
  116. if (ais.available() == 0)
  117. break;
  118. int tag = ais.readTag();
  119. switch (num) {
  120. case 0:
  121. // imsi
  122. if (ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive() || tag != Tag.STRING_OCTET)
  123. throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMResponse.imsi: Parameter 0 bad tag or tag class or not primitive",
  124. MAPParsingComponentExceptionReason.MistypedParameter);
  125. this.imsi = new IMSIImpl();
  126. ((IMSIImpl)this.imsi).decodeAll(ais);
  127. break;
  128. case 1:
  129. // locationInfoWithLMSI
  130. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive() || tag != _TAG_LocationInfoWithLMSI)
  131. throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMResponse.locationInfoWithLMSI: Parameter 1 bad tag class or tag or primitive",
  132. MAPParsingComponentExceptionReason.MistypedParameter);
  133. this.locationInfoWithLMSI = new LocationInfoWithLMSIImpl();
  134. ((LocationInfoWithLMSIImpl)this.locationInfoWithLMSI).decodeAll(ais);
  135. break;
  136. default:
  137. if (ais.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) {
  138. switch (tag) {
  139. case _TAG_ExtensionContainer:
  140. if (ais.isTagPrimitive())
  141. throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMResponse.extensionContainer: Parameter extensionContainer is primitive",
  142. MAPParsingComponentExceptionReason.MistypedParameter);
  143. this.extensionContainer = new MAPExtensionContainerImpl();
  144. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
  145. break;
  146. default:
  147. ais.advanceElement();
  148. break;
  149. }
  150. } else {
  151. ais.advanceElement();
  152. }
  153. break;
  154. }
  155. num++;
  156. }
  157. if (num < 2)
  158. throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMResponse: Needs at least 2 mandatory parameters, found " + num,
  159. MAPParsingComponentExceptionReason.MistypedParameter);
  160. }
  161. @Override
  162. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  163. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  164. }
  165. @Override
  166. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  167. try {
  168. asnOs.writeTag(tagClass, false, tag);
  169. int pos = asnOs.StartContentDefiniteLength();
  170. this.encodeData(asnOs);
  171. asnOs.FinalizeContent(pos);
  172. } catch (AsnException e) {
  173. throw new MAPException("AsnException when encoding sendRoutingInfoForSMResponse: " + e.getMessage(), e);
  174. }
  175. }
  176. @Override
  177. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  178. if (this.imsi == null || this.locationInfoWithLMSI == null)
  179. throw new MAPException("imsi and locationInfoWithLMSI must not be null");
  180. ((IMSIImpl)this.imsi).encodeAll(asnOs);
  181. ((LocationInfoWithLMSIImpl)this.locationInfoWithLMSI).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LocationInfoWithLMSI);
  182. if (this.extensionContainer != null)
  183. ((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_ExtensionContainer);
  184. }
  185. @Override
  186. public String toString() {
  187. StringBuilder sb = new StringBuilder();
  188. sb.append("SendRoutingInfoForSMResponse [");
  189. if (this.imsi != null) {
  190. sb.append(", imsi=");
  191. sb.append(this.imsi.toString());
  192. }
  193. if (this.locationInfoWithLMSI != null) {
  194. sb.append(", locationInfoWithLMSI=");
  195. sb.append(this.locationInfoWithLMSI.toString());
  196. }
  197. if (this.extensionContainer != null) {
  198. sb.append(", extensionContainer=");
  199. sb.append(this.extensionContainer.toString());
  200. }
  201. sb.append("]");
  202. return sb.toString();
  203. }
  204. }