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

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