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

http://mobicents.googlecode.com/ · Java · 324 lines · 173 code · 38 blank · 113 comment · 23 complexity · f0aacf6989cefe3f86e1d20f604a3e9b 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.ISDNAddressString;
  34. import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
  35. import org.mobicents.protocols.ss7.map.api.primitives.SubscriberIdentity;
  36. import org.mobicents.protocols.ss7.map.api.service.lsm.SendRoutingInfoForLCSRequestIndication;
  37. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  38. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  39. import org.mobicents.protocols.ss7.map.primitives.SubscriberIdentityImpl;
  40. /**
  41. * @author amit bhayani
  42. *
  43. */
  44. public class SendRoutingInfoForLCSRequestIndicationImpl extends LsmMessageImpl implements SendRoutingInfoForLCSRequestIndication {
  45. private static final int _TAG_MLC_NUMBER = 0;
  46. private static final int _TAG_TARGET_MS = 1;
  47. private static final int _TAG_EXTENSION_CONTAINER = 2;
  48. private MAPExtensionContainer extensionContainer = null;
  49. private SubscriberIdentity targetMS = null;
  50. private ISDNAddressString mlcNumber = null;
  51. /**
  52. *
  53. */
  54. public SendRoutingInfoForLCSRequestIndicationImpl() {
  55. super();
  56. }
  57. /**
  58. * @param targetMS
  59. * @param mlcNumber
  60. */
  61. public SendRoutingInfoForLCSRequestIndicationImpl(ISDNAddressString mlcNumber, SubscriberIdentity targetMS) {
  62. super();
  63. this.targetMS = targetMS;
  64. this.mlcNumber = mlcNumber;
  65. }
  66. /**
  67. * @param extensionContainer
  68. * @param targetMS
  69. * @param mlcNumber
  70. */
  71. public SendRoutingInfoForLCSRequestIndicationImpl(ISDNAddressString mlcNumber, SubscriberIdentity targetMS, MAPExtensionContainer extensionContainer) {
  72. this(mlcNumber, targetMS);
  73. this.extensionContainer = extensionContainer;
  74. }
  75. @Override
  76. public MAPMessageType getMessageType() {
  77. return MAPMessageType.sendRoutingInfoForLCS_Request;
  78. }
  79. @Override
  80. public int getOperationCode() {
  81. return MAPOperationCode.sendRoutingInfoForLCS;
  82. }
  83. /*
  84. * (non-Javadoc)
  85. *
  86. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  87. * SendRoutingInforForLCSRequestIndication#getMLCNumber()
  88. */
  89. @Override
  90. public ISDNAddressString getMLCNumber() {
  91. return this.mlcNumber;
  92. }
  93. /*
  94. * (non-Javadoc)
  95. *
  96. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  97. * SendRoutingInforForLCSRequestIndication#getTargetMS()
  98. */
  99. @Override
  100. public SubscriberIdentity getTargetMS() {
  101. return this.targetMS;
  102. }
  103. /*
  104. * (non-Javadoc)
  105. *
  106. * @see org.mobicents.protocols.ss7.map.api.service.lsm.
  107. * SendRoutingInforForLCSRequestIndication#getExtensionContainer()
  108. */
  109. @Override
  110. public MAPExtensionContainer getExtensionContainer() {
  111. return this.extensionContainer;
  112. }
  113. /*
  114. * (non-Javadoc)
  115. *
  116. * @see
  117. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
  118. */
  119. @Override
  120. public int getTag() throws MAPException {
  121. return Tag.SEQUENCE;
  122. }
  123. /*
  124. * (non-Javadoc)
  125. *
  126. * @see
  127. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass
  128. * ()
  129. */
  130. @Override
  131. public int getTagClass() {
  132. return Tag.CLASS_UNIVERSAL;
  133. }
  134. /*
  135. * (non-Javadoc)
  136. *
  137. * @see
  138. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive
  139. * ()
  140. */
  141. @Override
  142. public boolean getIsPrimitive() {
  143. return false;
  144. }
  145. /*
  146. * (non-Javadoc)
  147. *
  148. * @see
  149. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll
  150. * (org.mobicents.protocols.asn.AsnInputStream)
  151. */
  152. @Override
  153. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  154. try {
  155. int length = ansIS.readLength();
  156. this._decode(ansIS, length);
  157. } catch (IOException e) {
  158. throw new MAPParsingComponentException("IOException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  159. MAPParsingComponentExceptionReason.MistypedParameter);
  160. } catch (AsnException e) {
  161. throw new MAPParsingComponentException("AsnException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  162. MAPParsingComponentExceptionReason.MistypedParameter);
  163. }
  164. }
  165. /*
  166. * (non-Javadoc)
  167. *
  168. * @see
  169. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData
  170. * (org.mobicents.protocols.asn.AsnInputStream, int)
  171. */
  172. @Override
  173. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  174. try {
  175. this._decode(ansIS, length);
  176. } catch (IOException e) {
  177. throw new MAPParsingComponentException("IOException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  178. MAPParsingComponentExceptionReason.MistypedParameter);
  179. } catch (AsnException e) {
  180. throw new MAPParsingComponentException("AsnException when decoding ProvideSubscriberLocationRequestIndication: ", e,
  181. MAPParsingComponentExceptionReason.MistypedParameter);
  182. }
  183. }
  184. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  185. AsnInputStream ais = ansIS.readSequenceStreamData(length);
  186. // mlcNumber [0] ISDN-AddressString,
  187. int tag = ais.readTag();
  188. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive() || tag != _TAG_MLC_NUMBER) {
  189. throw new MAPParsingComponentException(
  190. "Error while decoding SendRoutingInforForLCSRequestIndication: Parameter [mlcNumber [0] ISDN-AddressString] bad tag class or not primitive or not Sequence",
  191. MAPParsingComponentExceptionReason.MistypedParameter);
  192. }
  193. this.mlcNumber = new ISDNAddressStringImpl();
  194. ((ISDNAddressStringImpl)this.mlcNumber).decodeAll(ais);
  195. // targetMS [1] SubscriberIdentity
  196. tag = ais.readTag();
  197. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive() || tag != _TAG_TARGET_MS) {
  198. throw new MAPParsingComponentException(
  199. "Error while decoding SendRoutingInforForLCSRequestIndication: Parameter [targetMS [1] SubscriberIdentity] bad tag class or not primitive or not Sequence",
  200. MAPParsingComponentExceptionReason.MistypedParameter);
  201. }
  202. int length1 = ais.readLength();
  203. tag = ais.readTag();
  204. this.targetMS = new SubscriberIdentityImpl();
  205. ((SubscriberIdentityImpl)this.targetMS).decodeAll(ais);
  206. while (true) {
  207. if (ais.available() == 0)
  208. break;
  209. tag = ais.readTag();
  210. switch (tag) {
  211. case _TAG_EXTENSION_CONTAINER:
  212. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  213. throw new MAPParsingComponentException(
  214. "Error while decoding SendRoutingInforForLCSRequestIndication: Parameter [extensionContainer [2] ExtensionContainer] bad tag class or not primitive or not Sequence",
  215. MAPParsingComponentExceptionReason.MistypedParameter);
  216. }
  217. this.extensionContainer = new MAPExtensionContainerImpl();
  218. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
  219. break;
  220. default:
  221. // DO we care?
  222. ais.advanceElement();
  223. break;
  224. }
  225. }
  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 MWStatus: " + 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.mlcNumber == null) {
  266. throw new MAPException(
  267. "Encoding of SendRoutingInforForLCSRequestIndication failed. Manadatory parameter mlcNumber [0] ISDN-AddressString is not set");
  268. }
  269. if (this.targetMS == null) {
  270. throw new MAPException(
  271. "Encoding of SendRoutingInforForLCSRequestIndication failed. Manadatory parameter targetMS [1] SubscriberIdentity is not set");
  272. }
  273. ((ISDNAddressStringImpl)this.mlcNumber).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_MLC_NUMBER);
  274. try {
  275. asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _TAG_TARGET_MS);
  276. } catch (AsnException e) {
  277. throw new MAPException("AsnException while encoding parameter targetMS [1] SubscriberIdentity");
  278. }
  279. int pos = asnOs.StartContentDefiniteLength();
  280. ((SubscriberIdentityImpl)this.targetMS).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, ((SubscriberIdentityImpl)this.targetMS).getTag());
  281. asnOs.FinalizeContent(pos);
  282. if (this.extensionContainer != null) {
  283. ((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_EXTENSION_CONTAINER);
  284. }
  285. }
  286. }