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

http://mobicents.googlecode.com/ · Java · 303 lines · 225 code · 47 blank · 31 comment · 36 complexity · 9ffba24f7c0b6b28467f0686bf05c54f 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.ISDNAddressString;
  34. import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
  35. import org.mobicents.protocols.ss7.map.api.service.sms.InformServiceCentreRequestIndication;
  36. import org.mobicents.protocols.ss7.map.api.service.sms.MWStatus;
  37. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  38. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  39. /**
  40. *
  41. * @author sergey vetyutnev
  42. *
  43. */
  44. public class InformServiceCentreRequestIndicationImpl extends SmsMessageImpl implements InformServiceCentreRequestIndication {
  45. protected static final int _TAG_AdditionalAbsentSubscriberDiagnosticSM = 0;
  46. private ISDNAddressString storedMSISDN;
  47. private MWStatus mwStatus;
  48. private MAPExtensionContainer extensionContainer;
  49. private Integer absentSubscriberDiagnosticSM;
  50. private Integer additionalAbsentSubscriberDiagnosticSM;
  51. public InformServiceCentreRequestIndicationImpl() {
  52. }
  53. public InformServiceCentreRequestIndicationImpl(ISDNAddressString storedMSISDN, MWStatus mwStatus, MAPExtensionContainer extensionContainer,
  54. Integer absentSubscriberDiagnosticSM, Integer additionalAbsentSubscriberDiagnosticSM) {
  55. this.storedMSISDN = storedMSISDN;
  56. this.mwStatus = mwStatus;
  57. this.extensionContainer = extensionContainer;
  58. this.absentSubscriberDiagnosticSM = absentSubscriberDiagnosticSM;
  59. this.additionalAbsentSubscriberDiagnosticSM = additionalAbsentSubscriberDiagnosticSM;
  60. }
  61. @Override
  62. public MAPMessageType getMessageType() {
  63. return MAPMessageType.InformServiceCentre_Request;
  64. }
  65. @Override
  66. public int getOperationCode() {
  67. return MAPOperationCode.informServiceCentre;
  68. }
  69. @Override
  70. public ISDNAddressString getStoredMSISDN() {
  71. return this.storedMSISDN;
  72. }
  73. @Override
  74. public MWStatus getMwStatus() {
  75. return this.mwStatus;
  76. }
  77. @Override
  78. public MAPExtensionContainer getExtensionContainer() {
  79. return this.extensionContainer;
  80. }
  81. @Override
  82. public Integer getAbsentSubscriberDiagnosticSM() {
  83. return this.absentSubscriberDiagnosticSM;
  84. }
  85. @Override
  86. public Integer getAdditionalAbsentSubscriberDiagnosticSM() {
  87. return this.additionalAbsentSubscriberDiagnosticSM;
  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 InformServiceCentreRequest: " + e.getMessage(), e,
  108. MAPParsingComponentExceptionReason.MistypedParameter);
  109. } catch (AsnException e) {
  110. throw new MAPParsingComponentException("AsnException when decoding InformServiceCentreRequest: " + 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 InformServiceCentreRequest: " + e.getMessage(), e,
  120. MAPParsingComponentExceptionReason.MistypedParameter);
  121. } catch (AsnException e) {
  122. throw new MAPParsingComponentException("AsnException when decoding InformServiceCentreRequest: " + e.getMessage(), e,
  123. MAPParsingComponentExceptionReason.MistypedParameter);
  124. }
  125. }
  126. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  127. this.storedMSISDN = null;
  128. this.mwStatus = null;
  129. this.extensionContainer = null;
  130. this.absentSubscriberDiagnosticSM = null;
  131. this.additionalAbsentSubscriberDiagnosticSM = null;
  132. AsnInputStream ais = ansIS.readSequenceStreamData(length);
  133. while (true) {
  134. if (ais.available() == 0)
  135. break;
  136. int tag = ais.readTag();
  137. if (ais.getTagClass() == Tag.CLASS_UNIVERSAL) {
  138. switch (tag) {
  139. case Tag.STRING_OCTET:
  140. // storedMSISDN
  141. if (!ais.isTagPrimitive())
  142. throw new MAPParsingComponentException("Error while decoding informServiceCentreRequest: Parameter storedMSISDN is not primitive",
  143. MAPParsingComponentExceptionReason.MistypedParameter);
  144. storedMSISDN = new ISDNAddressStringImpl();
  145. ((ISDNAddressStringImpl)storedMSISDN).decodeAll(ais);
  146. break;
  147. case Tag.STRING_BIT:
  148. // mw-Status
  149. if (!ais.isTagPrimitive())
  150. throw new MAPParsingComponentException("Error while decoding informServiceCentreRequest: Parameter mw-Status is not primitive",
  151. MAPParsingComponentExceptionReason.MistypedParameter);
  152. mwStatus = new MWStatusImpl();
  153. ((MWStatusImpl)mwStatus).decodeAll(ais);
  154. break;
  155. case Tag.SEQUENCE:
  156. // extensionContainer
  157. if (ais.isTagPrimitive())
  158. throw new MAPParsingComponentException("Error while decoding reportSMDeliveryStatusRequest: Parameter extensionContainer is primitive",
  159. MAPParsingComponentExceptionReason.MistypedParameter);
  160. extensionContainer = new MAPExtensionContainerImpl();
  161. ((MAPExtensionContainerImpl)extensionContainer).decodeAll(ais);
  162. break;
  163. case Tag.INTEGER:
  164. // absentSubscriberDiagnosticSM
  165. if (!ais.isTagPrimitive())
  166. throw new MAPParsingComponentException(
  167. "Error while decoding informServiceCentreRequest: Parameter absentSubscriberDiagnosticSM is not primitive",
  168. MAPParsingComponentExceptionReason.MistypedParameter);
  169. absentSubscriberDiagnosticSM = (int) ais.readInteger();
  170. break;
  171. default:
  172. ais.advanceElement();
  173. break;
  174. }
  175. } else if (ais.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) {
  176. switch (tag) {
  177. case InformServiceCentreRequestIndicationImpl._TAG_AdditionalAbsentSubscriberDiagnosticSM:
  178. // additionalAbsentSubscriberDiagnosticSM
  179. if (!ais.isTagPrimitive())
  180. throw new MAPParsingComponentException(
  181. "Error while decoding informServiceCentreRequest: Parameter deliveryOutcomeIndicator is not primitive",
  182. MAPParsingComponentExceptionReason.MistypedParameter);
  183. additionalAbsentSubscriberDiagnosticSM = (int) ais.readInteger();
  184. break;
  185. default:
  186. ais.advanceElement();
  187. break;
  188. }
  189. } else {
  190. ais.advanceElement();
  191. }
  192. }
  193. }
  194. @Override
  195. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  196. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  197. }
  198. @Override
  199. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  200. try {
  201. asnOs.writeTag(tagClass, false, tag);
  202. int pos = asnOs.StartContentDefiniteLength();
  203. this.encodeData(asnOs);
  204. asnOs.FinalizeContent(pos);
  205. } catch (AsnException e) {
  206. throw new MAPException("AsnException when encoding InformServiceCentreRequest: " + e.getMessage(), e);
  207. }
  208. }
  209. @Override
  210. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  211. if (this.storedMSISDN != null)
  212. ((ISDNAddressStringImpl)this.storedMSISDN).encodeAll(asnOs);
  213. if (this.mwStatus != null)
  214. ((MWStatusImpl)this.mwStatus).encodeAll(asnOs);
  215. if (this.extensionContainer != null)
  216. ((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs);
  217. try {
  218. if (this.absentSubscriberDiagnosticSM != null)
  219. asnOs.writeInteger(this.absentSubscriberDiagnosticSM);
  220. if (this.additionalAbsentSubscriberDiagnosticSM != null)
  221. asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, InformServiceCentreRequestIndicationImpl._TAG_AdditionalAbsentSubscriberDiagnosticSM,
  222. this.additionalAbsentSubscriberDiagnosticSM);
  223. } catch (IOException e) {
  224. throw new MAPException("IOException when encoding InformServiceCentreRequest: " + e.getMessage(), e);
  225. } catch (AsnException e) {
  226. throw new MAPException("AsnException when encoding InformServiceCentreRequest: " + e.getMessage(), e);
  227. }
  228. }
  229. @Override
  230. public String toString() {
  231. StringBuilder sb = new StringBuilder();
  232. sb.append("InformServiceCentreRequest [");
  233. if (this.storedMSISDN != null) {
  234. sb.append("storedMSISDN=");
  235. sb.append(this.storedMSISDN.toString());
  236. }
  237. if (this.mwStatus != null) {
  238. sb.append(", mwStatus=");
  239. sb.append(this.mwStatus.toString());
  240. }
  241. if (this.extensionContainer != null) {
  242. sb.append(", extensionContainer=");
  243. sb.append(this.extensionContainer.toString());
  244. }
  245. if (this.absentSubscriberDiagnosticSM != null) {
  246. sb.append(", absentSubscriberDiagnosticSM=");
  247. sb.append(this.absentSubscriberDiagnosticSM.toString());
  248. }
  249. if (this.additionalAbsentSubscriberDiagnosticSM != null) {
  250. sb.append(", additionalAbsentSubscriberDiagnosticSM=");
  251. sb.append(this.additionalAbsentSubscriberDiagnosticSM.toString());
  252. }
  253. sb.append("]");
  254. return sb.toString();
  255. }
  256. }