PageRenderTime 38ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 293 lines | 216 code | 48 blank | 29 comment | 48 complexity | 0be915caed4d9f100b5a7382e7052e02 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.IMSI;
  34. import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
  35. import org.mobicents.protocols.ss7.map.api.service.sms.MoForwardShortMessageRequestIndication;
  36. import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_DA;
  37. import org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_OA;
  38. import org.mobicents.protocols.ss7.map.api.service.sms.SmsSignalInfo;
  39. import org.mobicents.protocols.ss7.map.primitives.IMSIImpl;
  40. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  41. /**
  42. *
  43. * @author sergey vetyutnev
  44. *
  45. */
  46. public class MoForwardShortMessageRequestIndicationImpl extends SmsMessageImpl implements MoForwardShortMessageRequestIndication {
  47. private SM_RP_DA sm_RP_DA;
  48. private SM_RP_OA sm_RP_OA;
  49. private SmsSignalInfoImpl sm_RP_UI;
  50. private MAPExtensionContainer extensionContainer;
  51. private IMSI imsi;
  52. public MoForwardShortMessageRequestIndicationImpl() {
  53. }
  54. public MoForwardShortMessageRequestIndicationImpl(SM_RP_DA sm_RP_DA, SM_RP_OA sm_RP_OA, SmsSignalInfo sm_RP_UI, MAPExtensionContainer extensionContainer, IMSI imsi) {
  55. this.sm_RP_DA = sm_RP_DA;
  56. this.sm_RP_OA = sm_RP_OA;
  57. this.sm_RP_UI = (SmsSignalInfoImpl)sm_RP_UI;
  58. this.extensionContainer = extensionContainer;
  59. this.imsi = imsi;
  60. }
  61. @Override
  62. public MAPMessageType getMessageType() {
  63. return MAPMessageType.moForwardSM_Request;
  64. }
  65. @Override
  66. public int getOperationCode() {
  67. return MAPOperationCode.mo_forwardSM;
  68. }
  69. @Override
  70. public SM_RP_DA getSM_RP_DA() {
  71. return this.sm_RP_DA;
  72. }
  73. @Override
  74. public SM_RP_OA getSM_RP_OA() {
  75. return this.sm_RP_OA;
  76. }
  77. @Override
  78. public SmsSignalInfo getSM_RP_UI() {
  79. return this.sm_RP_UI;
  80. }
  81. @Override
  82. public MAPExtensionContainer getExtensionContainer() {
  83. return this.extensionContainer;
  84. }
  85. @Override
  86. public IMSI getIMSI() {
  87. return this.imsi;
  88. }
  89. @Override
  90. public int getTag() throws MAPException {
  91. return Tag.SEQUENCE;
  92. }
  93. @Override
  94. public int getTagClass() {
  95. return Tag.CLASS_UNIVERSAL;
  96. }
  97. @Override
  98. public boolean getIsPrimitive() {
  99. return false;
  100. }
  101. @Override
  102. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  103. try {
  104. int length = ansIS.readLength();
  105. this._decode(ansIS, length);
  106. } catch (IOException e) {
  107. throw new MAPParsingComponentException("IOException when decoding moForwardShortMessageRequest: " + e.getMessage(), e,
  108. MAPParsingComponentExceptionReason.MistypedParameter);
  109. } catch (AsnException e) {
  110. throw new MAPParsingComponentException("AsnException when decoding moForwardShortMessageRequest: " + e.getMessage(), e,
  111. MAPParsingComponentExceptionReason.MistypedParameter);
  112. }
  113. }
  114. @Override
  115. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  116. try {
  117. this._decode(ansIS, length);
  118. } catch (IOException e) {
  119. throw new MAPParsingComponentException("IOException when decoding moForwardShortMessageRequest: " + e.getMessage(), e,
  120. MAPParsingComponentExceptionReason.MistypedParameter);
  121. } catch (AsnException e) {
  122. throw new MAPParsingComponentException("AsnException when decoding moForwardShortMessageRequest: " + e.getMessage(), e,
  123. MAPParsingComponentExceptionReason.MistypedParameter);
  124. }
  125. }
  126. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  127. this.sm_RP_DA = null;
  128. this.sm_RP_OA = null;
  129. this.sm_RP_UI = null;
  130. this.extensionContainer = null;
  131. this.imsi = null;
  132. AsnInputStream ais = ansIS.readSequenceStreamData(length);
  133. int num = 0;
  134. while (true) {
  135. if (ais.available() == 0)
  136. break;
  137. int tag = ais.readTag();
  138. switch (num) {
  139. case 0:
  140. // SM_RP_DA
  141. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive())
  142. throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter 0 bad tag class or not primitive",
  143. MAPParsingComponentExceptionReason.MistypedParameter);
  144. this.sm_RP_DA = new SM_RP_DAImpl();
  145. ((SM_RP_DAImpl)this.sm_RP_DA).decodeAll(ais);
  146. break;
  147. case 1:
  148. // SM_RP_OA
  149. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive())
  150. throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter 1 bad tag class or not primitive",
  151. MAPParsingComponentExceptionReason.MistypedParameter);
  152. this.sm_RP_OA = new SM_RP_OAImpl();
  153. ((SM_RP_OAImpl)this.sm_RP_OA).decodeAll(ais);
  154. break;
  155. case 2:
  156. // sm-RP-UI
  157. if (ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
  158. throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter 2 bad tag class or not primitive",
  159. MAPParsingComponentExceptionReason.MistypedParameter);
  160. if (tag != Tag.STRING_OCTET)
  161. throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter 2 tag must be STRING_OCTET, found: "
  162. + tag, MAPParsingComponentExceptionReason.MistypedParameter);
  163. this.sm_RP_UI = new SmsSignalInfoImpl();
  164. this.sm_RP_UI.decodeAll(ais);
  165. break;
  166. default:
  167. if (tag == Tag.SEQUENCE && ais.getTagClass() == Tag.CLASS_UNIVERSAL) {
  168. if (ais.isTagPrimitive())
  169. throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter extensionContainer is primitive",
  170. MAPParsingComponentExceptionReason.MistypedParameter);
  171. this.extensionContainer = new MAPExtensionContainerImpl();
  172. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
  173. } else if (tag == Tag.STRING_OCTET && ais.getTagClass() == Tag.CLASS_UNIVERSAL) {
  174. if (!ais.isTagPrimitive())
  175. throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Parameter imsi is not primitive",
  176. MAPParsingComponentExceptionReason.MistypedParameter);
  177. this.imsi = new IMSIImpl();
  178. ((IMSIImpl)this.imsi).decodeAll(ais);
  179. } else {
  180. ais.advanceElement();
  181. }
  182. break;
  183. }
  184. num++;
  185. }
  186. if (num < 3)
  187. throw new MAPParsingComponentException("Error while decoding moForwardShortMessageRequest: Needs at least 3 mandatory parameters, found " + num,
  188. MAPParsingComponentExceptionReason.MistypedParameter);
  189. }
  190. @Override
  191. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  192. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  193. }
  194. @Override
  195. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  196. try {
  197. asnOs.writeTag(tagClass, false, tag);
  198. int pos = asnOs.StartContentDefiniteLength();
  199. this.encodeData(asnOs);
  200. asnOs.FinalizeContent(pos);
  201. } catch (AsnException e) {
  202. throw new MAPException("AsnException when encoding moForwardShortMessageRequest: " + e.getMessage(), e);
  203. }
  204. }
  205. @Override
  206. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  207. if (this.sm_RP_DA == null || this.sm_RP_OA == null || this.sm_RP_UI == null)
  208. throw new MAPException("sm_RP_DA,sm_RP_OA and sm_RP_UI must not be null");
  209. ((SM_RP_DAImpl) this.sm_RP_DA).encodeAll(asnOs);
  210. ((SM_RP_OAImpl) this.sm_RP_OA).encodeAll(asnOs);
  211. this.sm_RP_UI.encodeAll(asnOs);
  212. if (this.extensionContainer != null)
  213. ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs);
  214. if (this.imsi != null)
  215. ((IMSIImpl) this.imsi).encodeAll(asnOs);
  216. }
  217. @Override
  218. public String toString() {
  219. StringBuilder sb = new StringBuilder();
  220. sb.append("MoForwardShortMessageRequest [");
  221. if (this.sm_RP_DA != null) {
  222. sb.append("sm_RP_DA=");
  223. sb.append(this.sm_RP_DA.toString());
  224. }
  225. if (this.sm_RP_OA != null) {
  226. sb.append(", sm_RP_OA=");
  227. sb.append(this.sm_RP_OA.toString());
  228. }
  229. if (this.sm_RP_UI != null) {
  230. sb.append(", sm_RP_UI=[");
  231. sb.append(this.sm_RP_UI.toString());
  232. sb.append("]");
  233. }
  234. if (this.extensionContainer != null) {
  235. sb.append(", extensionContainer=");
  236. sb.append(this.extensionContainer.toString());
  237. }
  238. if (this.imsi != null) {
  239. sb.append(", imsi=");
  240. sb.append(this.imsi.toString());
  241. }
  242. sb.append("]");
  243. return sb.toString();
  244. }
  245. }