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

http://mobicents.googlecode.com/ · Java · 421 lines · 325 code · 61 blank · 35 comment · 76 complexity · d538a3810f3a7655dff67002d3d296b9 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.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.ReportSMDeliveryStatusRequestIndication;
  37. import org.mobicents.protocols.ss7.map.api.service.sms.SMDeliveryOutcome;
  38. import org.mobicents.protocols.ss7.map.primitives.AddressStringImpl;
  39. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  40. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  41. /**
  42. *
  43. * @author sergey vetyutnev
  44. *
  45. */
  46. public class ReportSMDeliveryStatusRequestIndicationImpl extends SmsMessageImpl implements ReportSMDeliveryStatusRequestIndication {
  47. protected static final int _TAG_AbsentSubscriberDiagnosticSM = 0;
  48. protected static final int _TAG_ExtensionContainer = 1;
  49. protected static final int _TAG_GprsSupportIndicator = 2;
  50. protected static final int _TAG_DeliveryOutcomeIndicator = 3;
  51. protected static final int _TAG_AdditionalSMDeliveryOutcome = 4;
  52. protected static final int _TAG_AdditionalAbsentSubscriberDiagnosticSM = 5;
  53. private ISDNAddressString msisdn;
  54. private AddressString serviceCentreAddress;
  55. private SMDeliveryOutcome sMDeliveryOutcome;
  56. private Integer absentSubscriberDiagnosticSM;
  57. private MAPExtensionContainer extensionContainer;
  58. private boolean gprsSupportIndicator;
  59. private boolean deliveryOutcomeIndicator;
  60. private SMDeliveryOutcome additionalSMDeliveryOutcome;
  61. private Integer additionalAbsentSubscriberDiagnosticSM;
  62. private long mapProtocolVersion;
  63. public ReportSMDeliveryStatusRequestIndicationImpl(long mapProtocolVersion) {
  64. this.mapProtocolVersion = mapProtocolVersion;
  65. }
  66. public ReportSMDeliveryStatusRequestIndicationImpl(long mapProtocolVersion, ISDNAddressString msisdn, AddressString serviceCentreAddress, SMDeliveryOutcome sMDeliveryOutcome,
  67. Integer absentSubscriberDiagnosticSM, MAPExtensionContainer extensionContainer, boolean gprsSupportIndicator, boolean deliveryOutcomeIndicator,
  68. SMDeliveryOutcome additionalSMDeliveryOutcome, Integer additionalAbsentSubscriberDiagnosticSM) {
  69. this.mapProtocolVersion = mapProtocolVersion;
  70. this.msisdn = msisdn;
  71. this.serviceCentreAddress = serviceCentreAddress;
  72. this.sMDeliveryOutcome = sMDeliveryOutcome;
  73. this.absentSubscriberDiagnosticSM = absentSubscriberDiagnosticSM;
  74. this.extensionContainer = extensionContainer;
  75. this.gprsSupportIndicator = gprsSupportIndicator;
  76. this.deliveryOutcomeIndicator = deliveryOutcomeIndicator;
  77. this.additionalSMDeliveryOutcome = additionalSMDeliveryOutcome;
  78. this.additionalAbsentSubscriberDiagnosticSM = additionalAbsentSubscriberDiagnosticSM;
  79. }
  80. @Override
  81. public MAPMessageType getMessageType() {
  82. return MAPMessageType.reportSM_DeliveryStatus_Request;
  83. }
  84. @Override
  85. public int getOperationCode() {
  86. return MAPOperationCode.reportSM_DeliveryStatus;
  87. }
  88. @Override
  89. public ISDNAddressString getMsisdn() {
  90. return this.msisdn;
  91. }
  92. @Override
  93. public AddressString getServiceCentreAddress() {
  94. return this.serviceCentreAddress;
  95. }
  96. @Override
  97. public SMDeliveryOutcome getSMDeliveryOutcome() {
  98. return this.sMDeliveryOutcome;
  99. }
  100. @Override
  101. public Integer getAbsentSubscriberDiagnosticSM() {
  102. return this.absentSubscriberDiagnosticSM;
  103. }
  104. @Override
  105. public MAPExtensionContainer getExtensionContainer() {
  106. return this.extensionContainer;
  107. }
  108. @Override
  109. public boolean getGprsSupportIndicator() {
  110. return this.gprsSupportIndicator;
  111. }
  112. @Override
  113. public boolean getDeliveryOutcomeIndicator() {
  114. return this.deliveryOutcomeIndicator;
  115. }
  116. @Override
  117. public SMDeliveryOutcome getAdditionalSMDeliveryOutcome() {
  118. return this.additionalSMDeliveryOutcome;
  119. }
  120. @Override
  121. public Integer getAdditionalAbsentSubscriberDiagnosticSM() {
  122. return this.additionalAbsentSubscriberDiagnosticSM;
  123. }
  124. @Override
  125. public int getTag() throws MAPException {
  126. return Tag.SEQUENCE;
  127. }
  128. @Override
  129. public int getTagClass() {
  130. return Tag.CLASS_UNIVERSAL;
  131. }
  132. @Override
  133. public boolean getIsPrimitive() {
  134. return false;
  135. }
  136. @Override
  137. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  138. try {
  139. int length = ansIS.readLength();
  140. this._decode(ansIS, length);
  141. } catch (IOException e) {
  142. throw new MAPParsingComponentException("IOException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
  143. MAPParsingComponentExceptionReason.MistypedParameter);
  144. } catch (AsnException e) {
  145. throw new MAPParsingComponentException("AsnException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
  146. MAPParsingComponentExceptionReason.MistypedParameter);
  147. }
  148. }
  149. @Override
  150. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  151. try {
  152. this._decode(ansIS, length);
  153. } catch (IOException e) {
  154. throw new MAPParsingComponentException("IOException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
  155. MAPParsingComponentExceptionReason.MistypedParameter);
  156. } catch (AsnException e) {
  157. throw new MAPParsingComponentException("AsnException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
  158. MAPParsingComponentExceptionReason.MistypedParameter);
  159. }
  160. }
  161. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  162. this.msisdn = null;
  163. this.serviceCentreAddress = null;
  164. this.sMDeliveryOutcome = null;
  165. this.absentSubscriberDiagnosticSM = null;
  166. this.extensionContainer = null;
  167. this.gprsSupportIndicator = false;
  168. this.deliveryOutcomeIndicator = false;
  169. this.additionalSMDeliveryOutcome = null;
  170. this.additionalAbsentSubscriberDiagnosticSM = null;
  171. AsnInputStream ais = ansIS.readSequenceStreamData(length);
  172. int num = 0;
  173. while (true) {
  174. if (ais.available() == 0)
  175. break;
  176. int tag = ais.readTag();
  177. switch (num) {
  178. case 0:
  179. // msisdn
  180. if (tag != Tag.STRING_OCTET || ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
  181. throw new MAPParsingComponentException("Error while decoding ReportSMDeliveryStatusRequest.msisdn: Parameter bad tag or tag class or not primitive",
  182. MAPParsingComponentExceptionReason.MistypedParameter);
  183. this.msisdn = new ISDNAddressStringImpl();
  184. ((ISDNAddressStringImpl)this.msisdn).decodeAll(ais);
  185. break;
  186. case 1:
  187. // serviceCentreAddress
  188. if (tag != Tag.STRING_OCTET || ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
  189. throw new MAPParsingComponentException("Error while decoding ReportSMDeliveryStatusRequest.serviceCentreAddress: Parameter bad tag or tag class or not primitive",
  190. MAPParsingComponentExceptionReason.MistypedParameter);
  191. this.serviceCentreAddress = new AddressStringImpl();
  192. ((AddressStringImpl)this.serviceCentreAddress).decodeAll(ais);
  193. break;
  194. case 2:
  195. // sMDeliveryOutcome
  196. if (tag != Tag.ENUMERATED || ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
  197. throw new MAPParsingComponentException("Error while decoding ReportSMDeliveryStatusRequest.sMDeliveryOutcome: Parameter bad tag or tag class or not primitive",
  198. MAPParsingComponentExceptionReason.MistypedParameter);
  199. int i1 = (int)ais.readInteger();
  200. this.sMDeliveryOutcome = SMDeliveryOutcome.getInstance(i1);
  201. break;
  202. default:
  203. if (ais.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) {
  204. switch (tag) {
  205. case _TAG_AbsentSubscriberDiagnosticSM:
  206. // absentSubscriberDiagnosticSM
  207. if (!ais.isTagPrimitive())
  208. throw new MAPParsingComponentException(
  209. "Error while decoding reportSMDeliveryStatusRequest: Parameter absentSubscriberDiagnosticSM is not primitive",
  210. MAPParsingComponentExceptionReason.MistypedParameter);
  211. this.absentSubscriberDiagnosticSM = (int)ais.readInteger();
  212. break;
  213. case _TAG_ExtensionContainer:
  214. // extensionContainer
  215. if (ais.isTagPrimitive())
  216. throw new MAPParsingComponentException(
  217. "Error while decoding reportSMDeliveryStatusRequest: Parameter extensionContainer is primitive",
  218. MAPParsingComponentExceptionReason.MistypedParameter);
  219. this.extensionContainer = new MAPExtensionContainerImpl();
  220. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
  221. break;
  222. case _TAG_GprsSupportIndicator:
  223. // gprsSupportIndicator
  224. if (!ais.isTagPrimitive())
  225. throw new MAPParsingComponentException(
  226. "Error while decoding reportSMDeliveryStatusRequest: Parameter gprsSupportIndicator is not primitive",
  227. MAPParsingComponentExceptionReason.MistypedParameter);
  228. ais.readNull();
  229. this.gprsSupportIndicator = true;
  230. break;
  231. case _TAG_DeliveryOutcomeIndicator:
  232. // deliveryOutcomeIndicator
  233. if (!ais.isTagPrimitive())
  234. throw new MAPParsingComponentException(
  235. "Error while decoding reportSMDeliveryStatusRequest: Parameter deliveryOutcomeIndicator is not primitive",
  236. MAPParsingComponentExceptionReason.MistypedParameter);
  237. ais.readNull();
  238. this.deliveryOutcomeIndicator = true;
  239. break;
  240. case _TAG_AdditionalSMDeliveryOutcome:
  241. // additionalSMDeliveryOutcome
  242. if (!ais.isTagPrimitive())
  243. throw new MAPParsingComponentException(
  244. "Error while decoding reportSMDeliveryStatusRequest: Parameter additionalSMDeliveryOutcome is not primitive",
  245. MAPParsingComponentExceptionReason.MistypedParameter);
  246. i1 = (int) ais.readInteger();
  247. this.additionalSMDeliveryOutcome = SMDeliveryOutcome.getInstance(i1);
  248. break;
  249. case _TAG_AdditionalAbsentSubscriberDiagnosticSM:
  250. // additionalAbsentSubscriberDiagnosticSM
  251. if (!ais.isTagPrimitive())
  252. throw new MAPParsingComponentException(
  253. "Error while decoding reportSMDeliveryStatusRequest: Parameter additionalAbsentSubscriberDiagnosticSM is not primitive",
  254. MAPParsingComponentExceptionReason.MistypedParameter);
  255. this.additionalAbsentSubscriberDiagnosticSM = (int)ais.readInteger();
  256. break;
  257. default:
  258. ais.advanceElement();
  259. break;
  260. }
  261. } else {
  262. ais.advanceElement();
  263. }
  264. break;
  265. }
  266. num++;
  267. }
  268. if (num < 3 && this.mapProtocolVersion >= 2 || num < 2 && this.mapProtocolVersion == 1)
  269. throw new MAPParsingComponentException("Error while decoding reportSMDeliveryStatusRequest: Needs at least 3 mandatory parameters, found " + num,
  270. MAPParsingComponentExceptionReason.MistypedParameter);
  271. }
  272. @Override
  273. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  274. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  275. }
  276. @Override
  277. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  278. try {
  279. asnOs.writeTag(tagClass, false, tag);
  280. int pos = asnOs.StartContentDefiniteLength();
  281. this.encodeData(asnOs);
  282. asnOs.FinalizeContent(pos);
  283. } catch (AsnException e) {
  284. throw new MAPException("AsnException when encoding reportSMDeliveryStatusRequest: " + e.getMessage(), e);
  285. }
  286. }
  287. @Override
  288. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  289. if (this.mapProtocolVersion == 1) {
  290. if (this.msisdn == null || this.serviceCentreAddress == null)
  291. throw new MAPException("msisdn and serviceCentreAddress must not be null");
  292. } else {
  293. if (this.msisdn == null || this.serviceCentreAddress == null || this.sMDeliveryOutcome == null)
  294. throw new MAPException("msisdn, serviceCentreAddress and sMDeliveryOutcome must not be null");
  295. }
  296. try {
  297. ((ISDNAddressStringImpl)this.msisdn).encodeAll(asnOs);
  298. ((AddressStringImpl)this.serviceCentreAddress).encodeAll(asnOs);
  299. if (this.mapProtocolVersion >= 1)
  300. asnOs.writeInteger(Tag.CLASS_UNIVERSAL, Tag.ENUMERATED, this.sMDeliveryOutcome.getCode());
  301. if (this.absentSubscriberDiagnosticSM != null)
  302. asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_AbsentSubscriberDiagnosticSM, this.absentSubscriberDiagnosticSM);
  303. if (this.extensionContainer != null)
  304. ((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_ExtensionContainer);
  305. if (this.gprsSupportIndicator == true)
  306. asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_GprsSupportIndicator);
  307. if (this.deliveryOutcomeIndicator == true)
  308. asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_DeliveryOutcomeIndicator);
  309. if (this.additionalSMDeliveryOutcome != null)
  310. asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_AdditionalSMDeliveryOutcome, this.additionalSMDeliveryOutcome.getCode());
  311. if (this.additionalAbsentSubscriberDiagnosticSM != null)
  312. asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_AdditionalAbsentSubscriberDiagnosticSM, this.additionalAbsentSubscriberDiagnosticSM);
  313. } catch (IOException e) {
  314. throw new MAPException("IOException when encoding mtForwardShortMessageRequest: " + e.getMessage(), e);
  315. } catch (AsnException e) {
  316. throw new MAPException("AsnException when encoding mtForwardShortMessageRequest: " + e.getMessage(), e);
  317. }
  318. }
  319. @Override
  320. public String toString() {
  321. StringBuilder sb = new StringBuilder();
  322. sb.append("ReportSMDeliveryStatusRequest [");
  323. if (this.msisdn != null) {
  324. sb.append("msisdn=");
  325. sb.append(this.msisdn.toString());
  326. }
  327. if (this.serviceCentreAddress != null) {
  328. sb.append(", serviceCentreAddress=");
  329. sb.append(this.serviceCentreAddress.toString());
  330. }
  331. if (this.sMDeliveryOutcome != null) {
  332. sb.append(", sMDeliveryOutcome=");
  333. sb.append(this.sMDeliveryOutcome.toString());
  334. }
  335. if (this.absentSubscriberDiagnosticSM != null) {
  336. sb.append(", absentSubscriberDiagnosticSM=");
  337. sb.append(this.absentSubscriberDiagnosticSM.toString());
  338. }
  339. if (this.extensionContainer != null) {
  340. sb.append(", extensionContainer=");
  341. sb.append(this.extensionContainer.toString());
  342. }
  343. if (this.gprsSupportIndicator) {
  344. sb.append(", gprsSupportIndicator");
  345. }
  346. if (this.deliveryOutcomeIndicator) {
  347. sb.append(", deliveryOutcomeIndicator");
  348. }
  349. if (this.additionalSMDeliveryOutcome != null) {
  350. sb.append(", additionalSMDeliveryOutcome=");
  351. sb.append(this.additionalSMDeliveryOutcome.toString());
  352. }
  353. if (this.additionalAbsentSubscriberDiagnosticSM != null) {
  354. sb.append(", additionalAbsentSubscriberDiagnosticSM=");
  355. sb.append(this.additionalAbsentSubscriberDiagnosticSM.toString());
  356. }
  357. sb.append("]");
  358. return sb.toString();
  359. }
  360. }