PageRenderTime 45ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/supplementary/UnstructuredSSRequestIndicationImpl.java

http://mobicents.googlecode.com/
Java | 301 lines | 198 code | 54 blank | 49 comment | 29 complexity | ff32cbf400779663febdf1972a539488 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.supplementary;
  23. import java.io.IOException;
  24. import javolution.xml.XMLFormat;
  25. import javolution.xml.stream.XMLStreamException;
  26. import org.mobicents.protocols.asn.AsnException;
  27. import org.mobicents.protocols.asn.AsnInputStream;
  28. import org.mobicents.protocols.asn.AsnOutputStream;
  29. import org.mobicents.protocols.asn.Tag;
  30. import org.mobicents.protocols.ss7.map.api.MAPException;
  31. import org.mobicents.protocols.ss7.map.api.MAPMessageType;
  32. import org.mobicents.protocols.ss7.map.api.MAPOperationCode;
  33. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
  34. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason;
  35. import org.mobicents.protocols.ss7.map.api.primitives.AlertingPattern;
  36. import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
  37. import org.mobicents.protocols.ss7.map.api.primitives.USSDString;
  38. import org.mobicents.protocols.ss7.map.api.service.supplementary.UnstructuredSSRequestIndication;
  39. import org.mobicents.protocols.ss7.map.primitives.AlertingPatternImpl;
  40. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  41. import org.mobicents.protocols.ss7.map.primitives.USSDStringImpl;
  42. /**
  43. *
  44. * @author amit bhayani
  45. *
  46. */
  47. public class UnstructuredSSRequestIndicationImpl extends USSDMessageImpl implements UnstructuredSSRequestIndication {
  48. private static final String MSISDN = "msisdn";
  49. private static final String ALERTING_PATTERN = "alertingPattern";
  50. private static final int _TAG_MSISDN = 0;
  51. private ISDNAddressString msisdnAddressString = null;
  52. private AlertingPattern alertingPattern = null;
  53. /**
  54. * @param ussdDataCodingSch
  55. * @param ussdString
  56. */
  57. public UnstructuredSSRequestIndicationImpl() {
  58. super();
  59. }
  60. public UnstructuredSSRequestIndicationImpl(byte ussdDataCodingSch, USSDString ussdString,
  61. AlertingPattern alertingPattern, ISDNAddressString msisdnAddressString) {
  62. super(ussdDataCodingSch, ussdString);
  63. this.alertingPattern = alertingPattern;
  64. this.msisdnAddressString = msisdnAddressString;
  65. }
  66. @Override
  67. public MAPMessageType getMessageType() {
  68. return MAPMessageType.unstructuredSSRequest_Request;
  69. }
  70. @Override
  71. public int getOperationCode() {
  72. return MAPOperationCode.unstructuredSS_Request;
  73. }
  74. /*
  75. * (non-Javadoc)
  76. *
  77. * @see org.mobicents.protocols.ss7.map.api.service.supplementary.
  78. * ProcessUnstructuredSSRequestIndication#getMSISDNAddressString()
  79. */
  80. @Override
  81. public ISDNAddressString getMSISDNAddressString() {
  82. return this.msisdnAddressString;
  83. }
  84. /*
  85. * (non-Javadoc)
  86. *
  87. * @see org.mobicents.protocols.ss7.map.api.service.supplementary.
  88. * ProcessUnstructuredSSRequestIndication#getAlertingPattern()
  89. */
  90. @Override
  91. public AlertingPattern getAlertingPattern() {
  92. return this.alertingPattern;
  93. }
  94. @Override
  95. public int getTag() throws MAPException {
  96. return Tag.SEQUENCE;
  97. }
  98. @Override
  99. public int getTagClass() {
  100. return Tag.CLASS_UNIVERSAL;
  101. }
  102. @Override
  103. public boolean getIsPrimitive() {
  104. return false;
  105. }
  106. @Override
  107. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  108. try {
  109. int length = ansIS.readLength();
  110. this._decode(ansIS, length);
  111. } catch (IOException e) {
  112. throw new MAPParsingComponentException("IOException when decoding UnstructuredSSRequestIndication: "
  113. + e.getMessage(), e, MAPParsingComponentExceptionReason.MistypedParameter);
  114. } catch (AsnException e) {
  115. throw new MAPParsingComponentException("AsnException when decoding UnstructuredSSRequestIndication: "
  116. + e.getMessage(), e, MAPParsingComponentExceptionReason.MistypedParameter);
  117. }
  118. }
  119. @Override
  120. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  121. try {
  122. this._decode(ansIS, length);
  123. } catch (IOException e) {
  124. throw new MAPParsingComponentException("IOException when decoding UnstructuredSSRequestIndication: "
  125. + e.getMessage(), e, MAPParsingComponentExceptionReason.MistypedParameter);
  126. } catch (AsnException e) {
  127. throw new MAPParsingComponentException("AsnException when decoding UnstructuredSSRequestIndication: "
  128. + e.getMessage(), e, MAPParsingComponentExceptionReason.MistypedParameter);
  129. }
  130. }
  131. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException,
  132. AsnException {
  133. AsnInputStream ais = ansIS.readSequenceStreamData(length);
  134. int tag = ais.readTag();
  135. // ussd-DataCodingScheme USSD-DataCodingScheme
  136. if (ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
  137. throw new MAPParsingComponentException(
  138. "Error while decoding UnstructuredSSRequestIndication: Parameter ussd-DataCodingScheme bad tag class or not primitive",
  139. MAPParsingComponentExceptionReason.MistypedParameter);
  140. int length1 = ais.readLength();
  141. this.ussdDataCodingSch = ais.readOctetStringData(length1)[0];
  142. tag = ais.readTag();
  143. // ussd-String USSD-String
  144. if (ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
  145. throw new MAPParsingComponentException(
  146. "Error while decoding UnstructuredSSRequestIndication: Parameter ussd-String bad tag class or not primitive",
  147. MAPParsingComponentExceptionReason.MistypedParameter);
  148. this.ussdString = new USSDStringImpl();
  149. ((USSDStringImpl) this.ussdString).decodeAll(ais);
  150. while (true) {
  151. if (ais.available() == 0)
  152. break;
  153. tag = ais.readTag();
  154. switch (tag) {
  155. case _TAG_MSISDN:
  156. // msisdn [0] ISDN-AddressString OPTIONAL
  157. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive())
  158. throw new MAPParsingComponentException(
  159. "Error while decoding UnstructuredSSRequestIndication: Parameter msisdn bad tag class or not primitive",
  160. MAPParsingComponentExceptionReason.MistypedParameter);
  161. this.msisdnAddressString = new ISDNAddressStringImpl();
  162. ((ISDNAddressStringImpl) this.msisdnAddressString).decodeAll(ais);
  163. break;
  164. default:
  165. // alertingPattern AlertingPattern OPTIONAL
  166. if (tag == Tag.STRING_OCTET && ais.getTagClass() == Tag.CLASS_UNIVERSAL && ais.isTagPrimitive()) {
  167. this.alertingPattern = new AlertingPatternImpl();
  168. ((AlertingPatternImpl) this.alertingPattern).decodeAll(ais);
  169. } else {
  170. ais.advanceElement();
  171. }
  172. break;
  173. }
  174. }
  175. }
  176. @Override
  177. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  178. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  179. }
  180. @Override
  181. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  182. try {
  183. asnOs.writeTag(tagClass, false, tag);
  184. int pos = asnOs.StartContentDefiniteLength();
  185. this.encodeData(asnOs);
  186. asnOs.FinalizeContent(pos);
  187. } catch (AsnException e) {
  188. throw new MAPException("AsnException when encoding ProcessUnstructuredSSRequestIndication", e);
  189. }
  190. }
  191. @Override
  192. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  193. if (this.ussdString == null)
  194. throw new MAPException("ussdString must not be null");
  195. try {
  196. asnOs.writeOctetString(new byte[] { this.ussdDataCodingSch });
  197. ((USSDStringImpl) this.ussdString).encodeAll(asnOs);
  198. if (this.alertingPattern != null) {
  199. ((AlertingPatternImpl) this.alertingPattern).encodeAll(asnOs);
  200. }
  201. if (this.msisdnAddressString != null) {
  202. ((ISDNAddressStringImpl) this.msisdnAddressString).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
  203. _TAG_MSISDN);
  204. }
  205. } catch (IOException e) {
  206. throw new MAPException("IOException when encoding ProcessUnstructuredSSRequestIndication", e);
  207. } catch (AsnException e) {
  208. throw new MAPException("AsnException when encoding ProcessUnstructuredSSRequestIndication", e);
  209. }
  210. }
  211. @Override
  212. public String toString() {
  213. StringBuilder sb = new StringBuilder();
  214. sb.append("UnstructuredSSRequest [");
  215. sb.append(super.toString());
  216. if (alertingPattern != null) {
  217. sb.append(", alertingPattern=");
  218. sb.append(alertingPattern.toString());
  219. }
  220. if (msisdnAddressString != null) {
  221. sb.append(", msisdn=");
  222. sb.append(msisdnAddressString.toString());
  223. }
  224. sb.append("]");
  225. return sb.toString();
  226. }
  227. /**
  228. * XML Serialization/Deserialization
  229. */
  230. protected static final XMLFormat<UnstructuredSSRequestIndicationImpl> UNSTRUCTURED_SS_REQUEST_XML = new XMLFormat<UnstructuredSSRequestIndicationImpl>(
  231. UnstructuredSSRequestIndicationImpl.class) {
  232. @Override
  233. public void read(javolution.xml.XMLFormat.InputElement xml, UnstructuredSSRequestIndicationImpl ussdMessage)
  234. throws XMLStreamException {
  235. USSD_MESSAGE_XML.read(xml, ussdMessage);
  236. ussdMessage.msisdnAddressString = xml.get(MSISDN, ISDNAddressStringImpl.class);
  237. ussdMessage.alertingPattern = xml.get(ALERTING_PATTERN, AlertingPatternImpl.class);
  238. }
  239. @Override
  240. public void write(UnstructuredSSRequestIndicationImpl ussdMessage, javolution.xml.XMLFormat.OutputElement xml)
  241. throws XMLStreamException {
  242. USSD_MESSAGE_XML.write(ussdMessage, xml);
  243. xml.add(((ISDNAddressStringImpl) ussdMessage.msisdnAddressString), MSISDN, ISDNAddressStringImpl.class);
  244. xml.add(((AlertingPatternImpl) ussdMessage.alertingPattern), ALERTING_PATTERN, AlertingPatternImpl.class);
  245. }
  246. };
  247. }