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

http://mobicents.googlecode.com/ · Java · 458 lines · 270 code · 45 blank · 143 comment · 43 complexity · 279f014eb17c7458b9e481383bfe1dce 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.MAPExtensionContainer;
  34. import org.mobicents.protocols.ss7.map.api.primitives.SubscriberIdentity;
  35. import org.mobicents.protocols.ss7.map.api.service.lsm.LCSLocationInfo;
  36. import org.mobicents.protocols.ss7.map.api.service.lsm.SendRoutingInfoForLCSResponseIndication;
  37. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  38. import org.mobicents.protocols.ss7.map.primitives.SubscriberIdentityImpl;
  39. /**
  40. * @author amit bhayani
  41. *
  42. */
  43. public class SendRoutingInfoForLCSResponseIndicationImpl extends LsmMessageImpl implements SendRoutingInfoForLCSResponseIndication {
  44. private static final int _TAG_TARGET_MS = 0;
  45. private static final int _TAG_LCS_LOCATION_INFO = 1;
  46. private static final int _TAG_EXTENSION_CONTAINER = 2;
  47. private static final int _TAG_V_GMLC_ADDRESS = 3;
  48. private static final int _TAG_H_GMLC_ADDRESS = 4;
  49. private static final int _TAG_PPR_ADDRESS = 5;
  50. private static final int _TAG_ADDITIONAL_V_GMLC_ADDRESS = 6;
  51. private SubscriberIdentity targetMS = null;
  52. private LCSLocationInfo lcsLocationInfo = null;
  53. private MAPExtensionContainer extensionContainer = null;
  54. private byte[] vgmlcAddress = null;
  55. private byte[] hGmlcAddress = null;
  56. private byte[] pprAddress = null;
  57. private byte[] additionalVGmlcAddress = null;
  58. /**
  59. *
  60. */
  61. public SendRoutingInfoForLCSResponseIndicationImpl() {
  62. super();
  63. }
  64. /**
  65. * @param targetMS
  66. * @param lcsLocationInfo
  67. * @param extensionContainer
  68. * @param vgmlcAddress
  69. * @param hGmlcAddress
  70. * @param pprAddress
  71. * @param additionalVGmlcAddress
  72. */
  73. public SendRoutingInfoForLCSResponseIndicationImpl(SubscriberIdentity targetMS, LCSLocationInfo lcsLocationInfo, MAPExtensionContainer extensionContainer,
  74. byte[] vgmlcAddress, byte[] hGmlcAddress, byte[] pprAddress, byte[] additionalVGmlcAddress) {
  75. super();
  76. this.targetMS = targetMS;
  77. this.lcsLocationInfo = lcsLocationInfo;
  78. this.extensionContainer = extensionContainer;
  79. this.vgmlcAddress = vgmlcAddress;
  80. this.hGmlcAddress = hGmlcAddress;
  81. this.pprAddress = pprAddress;
  82. this.additionalVGmlcAddress = additionalVGmlcAddress;
  83. }
  84. @Override
  85. public MAPMessageType getMessageType() {
  86. return MAPMessageType.sendRoutingInfoForLCS_Response;
  87. }
  88. @Override
  89. public int getOperationCode() {
  90. return MAPOperationCode.sendRoutingInfoForLCS;
  91. }
  92. /*
  93. * (non-Javadoc)
  94. *
  95. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  96. * SendRoutingInforForLCSResponseIndication#getTargetMS()
  97. */
  98. @Override
  99. public SubscriberIdentity getTargetMS() {
  100. return this.targetMS;
  101. }
  102. /*
  103. * (non-Javadoc)
  104. *
  105. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  106. * SendRoutingInforForLCSResponseIndication#getLCSLocationInfo()
  107. */
  108. @Override
  109. public LCSLocationInfo getLCSLocationInfo() {
  110. return this.lcsLocationInfo;
  111. }
  112. /*
  113. * (non-Javadoc)
  114. *
  115. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  116. * SendRoutingInforForLCSResponseIndication#getExtensionContainer()
  117. */
  118. @Override
  119. public MAPExtensionContainer getExtensionContainer() {
  120. return this.extensionContainer;
  121. }
  122. /*
  123. * (non-Javadoc)
  124. *
  125. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  126. * SendRoutingInforForLCSResponseIndication#getVgmlcAddress()
  127. */
  128. @Override
  129. public byte[] getVgmlcAddress() {
  130. return this.vgmlcAddress;
  131. }
  132. /*
  133. * (non-Javadoc)
  134. *
  135. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  136. * SendRoutingInforForLCSResponseIndication#getHGmlcAddress()
  137. */
  138. @Override
  139. public byte[] getHGmlcAddress() {
  140. return this.hGmlcAddress;
  141. }
  142. /*
  143. * (non-Javadoc)
  144. *
  145. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  146. * SendRoutingInforForLCSResponseIndication#getPprAddress()
  147. */
  148. @Override
  149. public byte[] getPprAddress() {
  150. return this.pprAddress;
  151. }
  152. /*
  153. * (non-Javadoc)
  154. *
  155. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  156. * SendRoutingInforForLCSResponseIndication#getAdditionalVGmlcAddress()
  157. */
  158. @Override
  159. public byte[] getAdditionalVGmlcAddress() {
  160. return this.additionalVGmlcAddress;
  161. }
  162. /*
  163. * (non-Javadoc)
  164. *
  165. * @see
  166. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
  167. */
  168. @Override
  169. public int getTag() throws MAPException {
  170. return Tag.SEQUENCE;
  171. }
  172. /*
  173. * (non-Javadoc)
  174. *
  175. * @see
  176. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass
  177. * ()
  178. */
  179. @Override
  180. public int getTagClass() {
  181. return Tag.CLASS_UNIVERSAL;
  182. }
  183. /*
  184. * (non-Javadoc)
  185. *
  186. * @see
  187. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive
  188. * ()
  189. */
  190. @Override
  191. public boolean getIsPrimitive() {
  192. return false;
  193. }
  194. /*
  195. * (non-Javadoc)
  196. *
  197. * @see
  198. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll
  199. * (org.mobicents.protocols.asn.AsnInputStream)
  200. */
  201. @Override
  202. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  203. try {
  204. int length = ansIS.readLength();
  205. this._decode(ansIS, length);
  206. } catch (IOException e) {
  207. throw new MAPParsingComponentException("IOException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  208. MAPParsingComponentExceptionReason.MistypedParameter);
  209. } catch (AsnException e) {
  210. throw new MAPParsingComponentException("AsnException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  211. MAPParsingComponentExceptionReason.MistypedParameter);
  212. }
  213. }
  214. /*
  215. * (non-Javadoc)
  216. *
  217. * @see
  218. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData
  219. * (org.mobicents.protocols.asn.AsnInputStream, int)
  220. */
  221. @Override
  222. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  223. try {
  224. this._decode(ansIS, length);
  225. } catch (IOException e) {
  226. throw new MAPParsingComponentException("IOException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  227. MAPParsingComponentExceptionReason.MistypedParameter);
  228. } catch (AsnException e) {
  229. throw new MAPParsingComponentException("AsnException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  230. MAPParsingComponentExceptionReason.MistypedParameter);
  231. }
  232. }
  233. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  234. AsnInputStream ais = ansIS.readSequenceStreamData(length);
  235. // targetMS [0] SubscriberIdentity
  236. int tag = ais.readTag();
  237. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive() || tag != _TAG_TARGET_MS) {
  238. throw new MAPParsingComponentException(
  239. "Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [targetMS [0] SubscriberIdentity] bad tag class or not primitive or not Sequence",
  240. MAPParsingComponentExceptionReason.MistypedParameter);
  241. }
  242. int length1 = ais.readLength();
  243. tag = ais.readTag();
  244. this.targetMS = new SubscriberIdentityImpl();
  245. ((SubscriberIdentityImpl)this.targetMS).decodeAll(ais);
  246. // lcsLocationInfo [1] LCSLocationInfo,
  247. tag = ais.readTag();
  248. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive() || tag != _TAG_LCS_LOCATION_INFO) {
  249. throw new MAPParsingComponentException(
  250. "Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [lcsLocationInfo [1] LCSLocationInfo] bad tag class or not primitive or not Sequence",
  251. MAPParsingComponentExceptionReason.MistypedParameter);
  252. }
  253. this.lcsLocationInfo = new LCSLocationInfoImpl();
  254. ((LCSLocationInfoImpl)this.lcsLocationInfo).decodeAll(ais);
  255. while (true) {
  256. if (ais.available() == 0)
  257. break;
  258. tag = ais.readTag();
  259. switch (tag) {
  260. case _TAG_EXTENSION_CONTAINER:
  261. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  262. throw new MAPParsingComponentException(
  263. "Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [extensionContainer [2] ExtensionContainer] bad tag class or not primitive or not Sequence",
  264. MAPParsingComponentExceptionReason.MistypedParameter);
  265. }
  266. this.extensionContainer = new MAPExtensionContainerImpl();
  267. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
  268. break;
  269. case _TAG_V_GMLC_ADDRESS:
  270. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  271. throw new MAPParsingComponentException(
  272. "Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [v-gmlc-Address [3] GSN-Address] bad tag class or not primitive or not Sequence",
  273. MAPParsingComponentExceptionReason.MistypedParameter);
  274. }
  275. length1 = ais.readLength();
  276. this.vgmlcAddress = ais.readOctetStringData(length1);
  277. break;
  278. case _TAG_H_GMLC_ADDRESS:
  279. // h-gmlc-Address [4] GSN-Address OPTIONAL,
  280. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  281. throw new MAPParsingComponentException(
  282. "Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [h-gmlc-Address [4] GSN-Address] bad tag class or not primitive or not Sequence",
  283. MAPParsingComponentExceptionReason.MistypedParameter);
  284. }
  285. length1 = ais.readLength();
  286. this.hGmlcAddress = ais.readOctetStringData(length1);
  287. break;
  288. case _TAG_PPR_ADDRESS:
  289. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  290. throw new MAPParsingComponentException(
  291. "Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [ppr-Address [5] GSN-Address] bad tag class or not primitive or not Sequence",
  292. MAPParsingComponentExceptionReason.MistypedParameter);
  293. }
  294. length1 = ais.readLength();
  295. this.pprAddress = ais.readOctetStringData(length1);
  296. break;
  297. case _TAG_ADDITIONAL_V_GMLC_ADDRESS:
  298. // additional-v-gmlc-Address [6] GSN-Address OPTIONAL
  299. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  300. throw new MAPParsingComponentException(
  301. "Error while decoding SendRoutingInforForLCSResponseIndication: Parameter [additional-v-gmlc-Address [6] GSN-Address] bad tag class or not primitive or not Sequence",
  302. MAPParsingComponentExceptionReason.MistypedParameter);
  303. }
  304. length1 = ais.readLength();
  305. this.additionalVGmlcAddress = ais.readOctetStringData(length1);
  306. break;
  307. default:
  308. ais.advanceElement();
  309. break;
  310. }
  311. }// while
  312. }
  313. /*
  314. * (non-Javadoc)
  315. *
  316. * @see
  317. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
  318. * (org.mobicents.protocols.asn.AsnOutputStream)
  319. */
  320. @Override
  321. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  322. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  323. }
  324. /*
  325. * (non-Javadoc)
  326. *
  327. * @see
  328. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
  329. * (org.mobicents.protocols.asn.AsnOutputStream, int, int)
  330. */
  331. @Override
  332. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  333. try {
  334. asnOs.writeTag(tagClass, false, tag);
  335. int pos = asnOs.StartContentDefiniteLength();
  336. this.encodeData(asnOs);
  337. asnOs.FinalizeContent(pos);
  338. } catch (AsnException e) {
  339. throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
  340. }
  341. }
  342. /*
  343. * (non-Javadoc)
  344. *
  345. * @see
  346. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData
  347. * (org.mobicents.protocols.asn.AsnOutputStream)
  348. */
  349. @Override
  350. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  351. if (this.targetMS == null) {
  352. throw new MAPException(
  353. "Encoding of SendRoutingInforForLCSResponseIndication failed. Manadatory parameter targetMS [0] SubscriberIdentity is not set");
  354. }
  355. if (this.lcsLocationInfo == null) {
  356. throw new MAPException(
  357. "Encoding of SendRoutingInforForLCSResponseIndication failed. Manadatory parameter lcsLocationInfo [1] LCSLocationInfo is not set");
  358. }
  359. try {
  360. asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _TAG_TARGET_MS);
  361. } catch (AsnException e) {
  362. throw new MAPException("AsnException while encoding parameter targetMS [0] SubscriberIdentity");
  363. }
  364. int pos = asnOs.StartContentDefiniteLength();
  365. ((SubscriberIdentityImpl)this.targetMS).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, ((SubscriberIdentityImpl)this.targetMS).getTag());
  366. asnOs.FinalizeContent(pos);
  367. ((LCSLocationInfoImpl)this.lcsLocationInfo).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_LOCATION_INFO);
  368. if (this.extensionContainer != null) {
  369. // extensionContainer [2] ExtensionContainer OPTIONAL,
  370. ((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_EXTENSION_CONTAINER);
  371. }
  372. if (this.vgmlcAddress != null) {
  373. // v-gmlc-Address [3] GSN-Address OPTIONAL,
  374. try {
  375. asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_V_GMLC_ADDRESS, this.vgmlcAddress);
  376. } catch (IOException e) {
  377. throw new MAPException("IOException while encoding parameter v-gmlc-Address");
  378. } catch (AsnException e) {
  379. throw new MAPException("AsnException while encoding parameter v-gmlc-Address");
  380. }
  381. }
  382. if (this.hGmlcAddress != null) {
  383. // h-gmlc-Address [4] GSN-Address OPTIONAL,
  384. try {
  385. asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_H_GMLC_ADDRESS, this.hGmlcAddress);
  386. } catch (IOException e) {
  387. throw new MAPException("IOException while encoding parameter hGmlcAddress");
  388. } catch (AsnException e) {
  389. throw new MAPException("AsnException while encoding parameter hGmlcAddress");
  390. }
  391. }
  392. if (this.pprAddress != null) {
  393. // ppr-Address [5] GSN-Address OPTIONAL,
  394. try {
  395. asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_PPR_ADDRESS, this.pprAddress);
  396. } catch (IOException e) {
  397. throw new MAPException("IOException while encoding parameter pprAddress");
  398. } catch (AsnException e) {
  399. throw new MAPException("AsnException while encoding parameter pprAddress");
  400. }
  401. }
  402. if (this.additionalVGmlcAddress != null) {
  403. // additional-v-gmlc-Address [6] GSN-Address OPTIONAL,
  404. try {
  405. asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_ADDITIONAL_V_GMLC_ADDRESS, this.additionalVGmlcAddress);
  406. } catch (IOException e) {
  407. throw new MAPException("IOException while encoding parameter additionalVGmlcAddress");
  408. } catch (AsnException e) {
  409. throw new MAPException("AsnException while encoding parameter additionalVGmlcAddress");
  410. }
  411. }
  412. }
  413. }