PageRenderTime 264ms CodeModel.GetById 248ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 360 lines | 274 code | 57 blank | 29 comment | 51 complexity | 8e2fdd24fe961b063dafdd7cea74cc0e MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  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.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.sms.SM_RP_MTI;
  37. import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_SMEA;
  38. import org.mobicents.protocols.ss7.map.api.service.sms.SendRoutingInfoForSMRequestIndication;
  39. import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
  40. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  41. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  42. /**
  43. *
  44. * @author sergey vetyutnev
  45. *
  46. */
  47. public class SendRoutingInfoForSMRequestIndicationImpl extends SmsMessageImpl implements SendRoutingInfoForSMRequestIndication {
  48. protected static final int _TAG_msisdn = 0;
  49. protected static final int _TAG_sm_RP_PRI = 1;
  50. protected static final int _TAG_serviceCentreAddress = 2;
  51. protected static final int _TAG_extensionContainer = 6;
  52. protected static final int _TAG_gprsSupportIndicator = 7;
  53. protected static final int _TAG_sm_RP_MTI = 8;
  54. protected static final int _TAG_sm_RP_SMEA = 9;
  55. private ISDNAddressString msisdn;
  56. private boolean sm_RP_PRI;
  57. private AddressString serviceCentreAddress;
  58. private MAPExtensionContainer extensionContainer;
  59. private boolean gprsSupportIndicator;
  60. private SM_RP_MTI sM_RP_MTI;
  61. private SM_RP_SMEAImpl sM_RP_SMEA;
  62. public SendRoutingInfoForSMRequestIndicationImpl() {
  63. }
  64. public SendRoutingInfoForSMRequestIndicationImpl(ISDNAddressString msisdn, boolean sm_RP_PRI, AddressString serviceCentreAddress,
  65. MAPExtensionContainer extensionContainer, boolean gprsSupportIndicator, SM_RP_MTI sM_RP_MTI, SM_RP_SMEA sM_RP_SMEA) {
  66. this.msisdn = msisdn;
  67. this.sm_RP_PRI = sm_RP_PRI;
  68. this.serviceCentreAddress = serviceCentreAddress;
  69. this.extensionContainer = extensionContainer;
  70. this.gprsSupportIndicator = gprsSupportIndicator;
  71. this.sM_RP_MTI = sM_RP_MTI;
  72. this.sM_RP_SMEA = (SM_RP_SMEAImpl)sM_RP_SMEA;
  73. }
  74. @Override
  75. public MAPMessageType getMessageType() {
  76. return MAPMessageType.sendRoutingInfoForSM_Request;
  77. }
  78. @Override
  79. public int getOperationCode() {
  80. return MAPOperationCode.sendRoutingInfoForSM;
  81. }
  82. @Override
  83. public ISDNAddressString getMsisdn() {
  84. return this.msisdn;
  85. }
  86. @Override
  87. public boolean getSm_RP_PRI() {
  88. return this.sm_RP_PRI;
  89. }
  90. @Override
  91. public AddressString getServiceCentreAddress() {
  92. return this.serviceCentreAddress;
  93. }
  94. @Override
  95. public MAPExtensionContainer getExtensionContainer() {
  96. return this.extensionContainer;
  97. }
  98. @Override
  99. public boolean getGprsSupportIndicator() {
  100. return this.gprsSupportIndicator;
  101. }
  102. @Override
  103. public SM_RP_MTI getSM_RP_MTI() {
  104. return this.sM_RP_MTI;
  105. }
  106. @Override
  107. public SM_RP_SMEA getSM_RP_SMEA() {
  108. return this.sM_RP_SMEA;
  109. }
  110. @Override
  111. public int getTag() throws MAPException {
  112. return Tag.SEQUENCE;
  113. }
  114. @Override
  115. public int getTagClass() {
  116. return Tag.CLASS_UNIVERSAL;
  117. }
  118. @Override
  119. public boolean getIsPrimitive() {
  120. return false;
  121. }
  122. @Override
  123. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  124. try {
  125. int length = ansIS.readLength();
  126. this._decode(ansIS, length);
  127. } catch (IOException e) {
  128. throw new MAPParsingComponentException("IOException when decoding sendRoutingInfoForSMRequest: " + e.getMessage(), e,
  129. MAPParsingComponentExceptionReason.MistypedParameter);
  130. } catch (AsnException e) {
  131. throw new MAPParsingComponentException("AsnException when decoding sendRoutingInfoForSMRequest: " + e.getMessage(), e,
  132. MAPParsingComponentExceptionReason.MistypedParameter);
  133. }
  134. }
  135. @Override
  136. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  137. try {
  138. this._decode(ansIS, length);
  139. } catch (IOException e) {
  140. throw new MAPParsingComponentException("IOException when decoding sendRoutingInfoForSMRequest: " + e.getMessage(), e,
  141. MAPParsingComponentExceptionReason.MistypedParameter);
  142. } catch (AsnException e) {
  143. throw new MAPParsingComponentException("AsnException when decoding sendRoutingInfoForSMRequest: " + e.getMessage(), e,
  144. MAPParsingComponentExceptionReason.MistypedParameter);
  145. }
  146. }
  147. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  148. this.msisdn = null;
  149. this.sm_RP_PRI = false;
  150. this.serviceCentreAddress = null;
  151. this.extensionContainer = null;
  152. this.gprsSupportIndicator = false;
  153. this.sM_RP_MTI = null;
  154. this.sM_RP_SMEA = null;
  155. AsnInputStream ais = ansIS.readSequenceStreamData(length);
  156. int num = 0;
  157. while (true) {
  158. if (ais.available() == 0)
  159. break;
  160. int tag = ais.readTag();
  161. switch (num) {
  162. case 0:
  163. // msisdn
  164. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive() || tag != _TAG_msisdn)
  165. throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMRequest.msisdn: Parameter bad tag or tag class or not primitive",
  166. MAPParsingComponentExceptionReason.MistypedParameter);
  167. this.msisdn = new ISDNAddressStringImpl();
  168. ((ISDNAddressStringImpl)this.msisdn).decodeAll(ais);
  169. break;
  170. case 1:
  171. // sm-RP-PRI
  172. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive() || tag != _TAG_sm_RP_PRI)
  173. throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMRequest.sm-RP-PRI: Parameter 1 bad tag class or tag or not primitive",
  174. MAPParsingComponentExceptionReason.MistypedParameter);
  175. this.sm_RP_PRI = ais.readBoolean();
  176. break;
  177. case 2:
  178. // serviceCentreAddress
  179. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive() || tag != _TAG_serviceCentreAddress)
  180. throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMRequest.serviceCentreAddress: Parameter 2 bad tag class or tag or not primitive",
  181. MAPParsingComponentExceptionReason.MistypedParameter);
  182. this.serviceCentreAddress = new ISDNAddressStringImpl();
  183. ((AddressStringImpl)this.serviceCentreAddress).decodeAll(ais);
  184. break;
  185. default:
  186. if (ais.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) {
  187. switch (tag) {
  188. case _TAG_extensionContainer:
  189. if (ais.isTagPrimitive())
  190. throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMRequest.extensionContainer: Parameter extensionContainer is primitive",
  191. MAPParsingComponentExceptionReason.MistypedParameter);
  192. this.extensionContainer = new MAPExtensionContainerImpl();
  193. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
  194. break;
  195. case _TAG_gprsSupportIndicator:
  196. if (!ais.isTagPrimitive())
  197. throw new MAPParsingComponentException(
  198. "Error while decoding sendRoutingInfoForSMRequest.gprsSupportIndicator: Parameter gprsSupportIndicator is not primitive",
  199. MAPParsingComponentExceptionReason.MistypedParameter);
  200. ais.readNull();
  201. this.gprsSupportIndicator = true;
  202. break;
  203. case _TAG_sm_RP_MTI:
  204. if (!ais.isTagPrimitive())
  205. throw new MAPParsingComponentException(
  206. "Error while decoding sendRoutingInfoForSMRequest.sM_RP_MTI: Parameter sM_RP_MTI is not primitive",
  207. MAPParsingComponentExceptionReason.MistypedParameter);
  208. int i1 = (int)ais.readInteger();
  209. this.sM_RP_MTI = SM_RP_MTI.getInstance(i1);
  210. break;
  211. case _TAG_sm_RP_SMEA:
  212. if (!ais.isTagPrimitive())
  213. throw new MAPParsingComponentException(
  214. "Error while decoding sendRoutingInfoForSMRequest.sM_RP_SMEA: Parameter sM_RP_SMEA is not primitive",
  215. MAPParsingComponentExceptionReason.MistypedParameter);
  216. this.sM_RP_SMEA = new SM_RP_SMEAImpl();
  217. this.sM_RP_SMEA.decodeAll(ais);
  218. break;
  219. default:
  220. ais.advanceElement();
  221. break;
  222. }
  223. } else {
  224. ais.advanceElement();
  225. }
  226. break;
  227. }
  228. num++;
  229. }
  230. if (num < 3)
  231. throw new MAPParsingComponentException("Error while decoding sendRoutingInfoForSMRequest: Needs at least 3 mandatory parameters, found " + num,
  232. MAPParsingComponentExceptionReason.MistypedParameter);
  233. }
  234. @Override
  235. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  236. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  237. }
  238. @Override
  239. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  240. try {
  241. asnOs.writeTag(tagClass, false, tag);
  242. int pos = asnOs.StartContentDefiniteLength();
  243. this.encodeData(asnOs);
  244. asnOs.FinalizeContent(pos);
  245. } catch (AsnException e) {
  246. throw new MAPException("AsnException when encoding sendRoutingInfoForSMRequest: " + e.getMessage(), e);
  247. }
  248. }
  249. @Override
  250. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  251. if (msisdn == null || serviceCentreAddress == null)
  252. throw new MAPException("msisdn, sm_RP_PRI and serviceCentreAddress must not be null");
  253. try {
  254. ((ISDNAddressStringImpl)this.msisdn).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_msisdn);
  255. asnOs.writeBoolean(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_sm_RP_PRI, this.sm_RP_PRI);
  256. ((AddressStringImpl)this.serviceCentreAddress).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_serviceCentreAddress);
  257. if (this.extensionContainer != null)
  258. ((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_extensionContainer);
  259. if (this.gprsSupportIndicator == true)
  260. asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_gprsSupportIndicator);
  261. if (this.sM_RP_MTI != null)
  262. asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_sm_RP_MTI, this.sM_RP_MTI.getCode());
  263. if (this.sM_RP_SMEA != null)
  264. this.sM_RP_SMEA.encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_sm_RP_SMEA);
  265. } catch (IOException e) {
  266. throw new MAPException("IOException when encoding sendRoutingInfoForSMRequest: " + e.getMessage(), e);
  267. } catch (AsnException e) {
  268. throw new MAPException("AsnException when encoding sendRoutingInfoForSMRequest: " + e.getMessage(), e);
  269. }
  270. }
  271. @Override
  272. public String toString() {
  273. StringBuilder sb = new StringBuilder();
  274. sb.append("SendRoutingInfoForSMRequest [");
  275. if (this.msisdn != null) {
  276. sb.append("msisdn=");
  277. sb.append(this.msisdn.toString());
  278. }
  279. sb.append(", sm_RP_PRI=");
  280. sb.append(((Boolean)this.sm_RP_PRI).toString());
  281. if (this.serviceCentreAddress != null) {
  282. sb.append(", serviceCentreAddress=");
  283. sb.append(this.serviceCentreAddress.toString());
  284. }
  285. if (this.extensionContainer != null) {
  286. sb.append(", extensionContainer=");
  287. sb.append(this.extensionContainer.toString());
  288. }
  289. if (this.gprsSupportIndicator) {
  290. sb.append(", gprsSupportIndicator");
  291. }
  292. if (this.sM_RP_MTI != null) {
  293. sb.append(", sM_RP_MTI=");
  294. sb.append(this.sM_RP_MTI.toString());
  295. }
  296. if (this.sM_RP_SMEA != null) {
  297. sb.append(", sM_RP_SMEA=");
  298. sb.append(this.sM_RP_SMEA.toString());
  299. }
  300. sb.append("]");
  301. return sb.toString();
  302. }
  303. }