PageRenderTime 43ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

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