/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/lsm/SubscriberLocationReportResponseIndicationImpl.java

http://mobicents.googlecode.com/ · Java · 308 lines · 164 code · 30 blank · 114 comment · 21 complexity · 1d07ab4212dc5b6afb31c61649d1445e 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.lsm;
  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.AddressString;
  34. import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
  35. import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
  36. import org.mobicents.protocols.ss7.map.api.service.lsm.SubscriberLocationReportResponseIndication;
  37. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  38. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  39. /**
  40. * TODO : Add unit test
  41. *
  42. * @author amit bhayani
  43. *
  44. */
  45. public class SubscriberLocationReportResponseIndicationImpl extends LsmMessageImpl implements SubscriberLocationReportResponseIndication {
  46. private static final int _TAG_NA_ESRK = 0;
  47. private static final int _TAG_NA_ESRD = 1;
  48. private ISDNAddressString naEsrd = null;
  49. private ISDNAddressString naEsrk = null;
  50. private MAPExtensionContainer extensionContainer = null;
  51. /**
  52. *
  53. */
  54. public SubscriberLocationReportResponseIndicationImpl() {
  55. super();
  56. }
  57. /**
  58. * @param naEsrd
  59. * @param naEsrk
  60. * @param extensionContainer
  61. */
  62. public SubscriberLocationReportResponseIndicationImpl(ISDNAddressString naEsrd, ISDNAddressString naEsrk, MAPExtensionContainer extensionContainer) {
  63. super();
  64. this.naEsrd = naEsrd;
  65. this.naEsrk = naEsrk;
  66. this.extensionContainer = extensionContainer;
  67. }
  68. @Override
  69. public MAPMessageType getMessageType() {
  70. return MAPMessageType.subscriberLocationReport_Response;
  71. }
  72. @Override
  73. public int getOperationCode() {
  74. return MAPOperationCode.subscriberLocationReport;
  75. }
  76. /*
  77. * (non-Javadoc)
  78. *
  79. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  80. * SubscriberLocationReportResponseIndication#getExtensionContainer()
  81. */
  82. @Override
  83. public MAPExtensionContainer getExtensionContainer() {
  84. return this.extensionContainer;
  85. }
  86. /*
  87. * (non-Javadoc)
  88. *
  89. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  90. * SubscriberLocationReportResponseIndication#getNaESRK()
  91. */
  92. @Override
  93. public AddressString getNaESRK() {
  94. return this.naEsrk;
  95. }
  96. /*
  97. * (non-Javadoc)
  98. *
  99. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  100. * SubscriberLocationReportResponseIndication#getNaESRD()
  101. */
  102. @Override
  103. public AddressString getNaESRD() {
  104. return this.naEsrd;
  105. }
  106. /*
  107. * (non-Javadoc)
  108. *
  109. * @see
  110. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
  111. */
  112. @Override
  113. public int getTag() throws MAPException {
  114. return Tag.SEQUENCE;
  115. }
  116. /*
  117. * (non-Javadoc)
  118. *
  119. * @see
  120. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass
  121. * ()
  122. */
  123. @Override
  124. public int getTagClass() {
  125. return Tag.CLASS_UNIVERSAL;
  126. }
  127. /*
  128. * (non-Javadoc)
  129. *
  130. * @see
  131. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive
  132. * ()
  133. */
  134. @Override
  135. public boolean getIsPrimitive() {
  136. return false;
  137. }
  138. /*
  139. * (non-Javadoc)
  140. *
  141. * @see
  142. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll
  143. * (org.mobicents.protocols.asn.AsnInputStream)
  144. */
  145. @Override
  146. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  147. try {
  148. int length = ansIS.readLength();
  149. this._decode(ansIS, length);
  150. } catch (IOException e) {
  151. throw new MAPParsingComponentException("IOException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  152. MAPParsingComponentExceptionReason.MistypedParameter);
  153. } catch (AsnException e) {
  154. throw new MAPParsingComponentException("AsnException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  155. MAPParsingComponentExceptionReason.MistypedParameter);
  156. }
  157. }
  158. /*
  159. * (non-Javadoc)
  160. *
  161. * @see
  162. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData
  163. * (org.mobicents.protocols.asn.AsnInputStream, int)
  164. */
  165. @Override
  166. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  167. try {
  168. this._decode(ansIS, length);
  169. } catch (IOException e) {
  170. throw new MAPParsingComponentException("IOException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  171. MAPParsingComponentExceptionReason.MistypedParameter);
  172. } catch (AsnException e) {
  173. throw new MAPParsingComponentException("AsnException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  174. MAPParsingComponentExceptionReason.MistypedParameter);
  175. }
  176. }
  177. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  178. AsnInputStream ais = ansIS.readSequenceStreamData(length);
  179. while (true) {
  180. if (ais.available() == 0)
  181. break;
  182. int tag = ais.readTag();
  183. if (ais.getTagClass() == Tag.CLASS_UNIVERSAL) {
  184. switch (tag) {
  185. case Tag.SEQUENCE:
  186. // ExtensionContainer
  187. if (ais.isTagPrimitive())
  188. throw new MAPParsingComponentException(
  189. "Error while decoding ReportSMDeliveryStatusResponse: Parameter extensionContainer is primitive",
  190. MAPParsingComponentExceptionReason.MistypedParameter);
  191. this.extensionContainer = new MAPExtensionContainerImpl();
  192. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
  193. break;
  194. default:
  195. ais.advanceElement();
  196. break;
  197. }// switch
  198. } else {
  199. switch (tag) {
  200. case _TAG_NA_ESRK:
  201. // na-ESRK [0] ISDN-AddressString OPTIONAL
  202. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  203. throw new MAPParsingComponentException(
  204. "Error while decoding SubscriberLocationReportResponseIndication: Parameter [na-ESRK [0] ISDN-AddressString] bad tag class or not primitive or not Sequence",
  205. MAPParsingComponentExceptionReason.MistypedParameter);
  206. }
  207. this.naEsrk = new ISDNAddressStringImpl();
  208. ((ISDNAddressStringImpl)this.naEsrk).decodeAll(ais);
  209. break;
  210. case _TAG_NA_ESRD:
  211. // na-ESRD [1] ISDN-AddressString OPTIONAL,
  212. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  213. throw new MAPParsingComponentException(
  214. "Error while decoding SubscriberLocationReportResponseIndication: Parameter [na-ESRD [1] ISDN-AddressString] bad tag class or not primitive or not Sequence",
  215. MAPParsingComponentExceptionReason.MistypedParameter);
  216. }
  217. this.naEsrd = new ISDNAddressStringImpl();
  218. ((ISDNAddressStringImpl)this.naEsrd).decodeAll(ais);
  219. break;
  220. default:
  221. ais.advanceElement();
  222. break;
  223. }
  224. }
  225. }// while
  226. }
  227. /*
  228. * (non-Javadoc)
  229. *
  230. * @see
  231. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
  232. * (org.mobicents.protocols.asn.AsnOutputStream)
  233. */
  234. @Override
  235. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  236. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  237. }
  238. /*
  239. * (non-Javadoc)
  240. *
  241. * @see
  242. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
  243. * (org.mobicents.protocols.asn.AsnOutputStream, int, int)
  244. */
  245. @Override
  246. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  247. try {
  248. asnOs.writeTag(tagClass, false, tag);
  249. int pos = asnOs.StartContentDefiniteLength();
  250. this.encodeData(asnOs);
  251. asnOs.FinalizeContent(pos);
  252. } catch (AsnException e) {
  253. throw new MAPException("AsnException when encoding ReportSMDeliveryStatusResponse: " + e.getMessage(), e);
  254. }
  255. }
  256. /*
  257. * (non-Javadoc)
  258. *
  259. * @see
  260. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData
  261. * (org.mobicents.protocols.asn.AsnOutputStream)
  262. */
  263. @Override
  264. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  265. if (this.extensionContainer != null) {
  266. // extensionContainer ExtensionContainer OPTIONAL
  267. ((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs);
  268. }
  269. if (this.naEsrk != null) {
  270. // na-ESRK [0] ISDN-AddressString OPTIONAL
  271. ((ISDNAddressStringImpl)this.naEsrk).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_NA_ESRK);
  272. }
  273. if (this.naEsrd != null) {
  274. // na-ESRD [1] ISDN-AddressString OPTIONAL ,
  275. ((ISDNAddressStringImpl)this.naEsrd).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_NA_ESRD);
  276. }
  277. }
  278. }