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

http://mobicents.googlecode.com/ · Java · 210 lines · 135 code · 41 blank · 34 comment · 8 complexity · a9e9ca35cafdfd1168583a98ab1d0f31 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.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.USSDString;
  36. import org.mobicents.protocols.ss7.map.api.service.supplementary.UnstructuredSSResponseIndication;
  37. import org.mobicents.protocols.ss7.map.primitives.USSDStringImpl;
  38. /**
  39. *
  40. * @author amit bhayani
  41. *
  42. */
  43. public class UnstructuredSSResponseIndicationImpl extends USSDMessageImpl implements UnstructuredSSResponseIndication {
  44. /**
  45. *
  46. */
  47. public UnstructuredSSResponseIndicationImpl() {
  48. super();
  49. }
  50. public UnstructuredSSResponseIndicationImpl(byte ussdDataCodingSch, USSDString ussdString) {
  51. super(ussdDataCodingSch, ussdString);
  52. }
  53. @Override
  54. public MAPMessageType getMessageType() {
  55. return MAPMessageType.processUnstructuredSSRequest_Response;
  56. }
  57. @Override
  58. public int getOperationCode() {
  59. return MAPOperationCode.unstructuredSS_Request;
  60. }
  61. @Override
  62. public int getTag() throws MAPException {
  63. return Tag.SEQUENCE;
  64. }
  65. @Override
  66. public int getTagClass() {
  67. return Tag.CLASS_UNIVERSAL;
  68. }
  69. @Override
  70. public boolean getIsPrimitive() {
  71. return false;
  72. }
  73. @Override
  74. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  75. try {
  76. int length = ansIS.readLength();
  77. this._decode(ansIS, length);
  78. } catch (IOException e) {
  79. throw new MAPParsingComponentException("IOException when decoding UnstructuredSSResponseIndication: "
  80. + e.getMessage(), e, MAPParsingComponentExceptionReason.MistypedParameter);
  81. } catch (AsnException e) {
  82. throw new MAPParsingComponentException("AsnException when decoding UnstructuredSSResponseIndication: "
  83. + e.getMessage(), e, MAPParsingComponentExceptionReason.MistypedParameter);
  84. }
  85. }
  86. @Override
  87. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  88. try {
  89. this._decode(ansIS, length);
  90. } catch (IOException e) {
  91. throw new MAPParsingComponentException("IOException when decoding UnstructuredSSResponseIndication: "
  92. + e.getMessage(), e, MAPParsingComponentExceptionReason.MistypedParameter);
  93. } catch (AsnException e) {
  94. throw new MAPParsingComponentException("AsnException when decoding UnstructuredSSResponseIndication: "
  95. + e.getMessage(), e, MAPParsingComponentExceptionReason.MistypedParameter);
  96. }
  97. }
  98. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException,
  99. AsnException {
  100. AsnInputStream ais = ansIS.readSequenceStreamData(length);
  101. int tag = ais.readTag();
  102. // ussd-DataCodingScheme USSD-DataCodingScheme
  103. if (ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
  104. throw new MAPParsingComponentException(
  105. "Error while decoding UnstructuredSSResponseIndication: Parameter ussd-DataCodingScheme bad tag class or not primitive",
  106. MAPParsingComponentExceptionReason.MistypedParameter);
  107. int length1 = ais.readLength();
  108. this.ussdDataCodingSch = ais.readOctetStringData(length1)[0];
  109. tag = ais.readTag();
  110. // ussd-String USSD-String
  111. if (ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive())
  112. throw new MAPParsingComponentException(
  113. "Error while decoding UnstructuredSSResponseIndication: Parameter ussd-String bad tag class or not primitive",
  114. MAPParsingComponentExceptionReason.MistypedParameter);
  115. this.ussdString = new USSDStringImpl();
  116. ((USSDStringImpl) this.ussdString).decodeAll(ais);
  117. }
  118. @Override
  119. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  120. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  121. }
  122. @Override
  123. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  124. try {
  125. asnOs.writeTag(tagClass, false, tag);
  126. int pos = asnOs.StartContentDefiniteLength();
  127. this.encodeData(asnOs);
  128. asnOs.FinalizeContent(pos);
  129. } catch (AsnException e) {
  130. throw new MAPException("AsnException when encoding UnstructuredSSResponseIndication", e);
  131. }
  132. }
  133. @Override
  134. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  135. if (this.ussdString == null)
  136. throw new MAPException("ussdString must not be null");
  137. try {
  138. asnOs.writeOctetString(new byte[] { this.ussdDataCodingSch });
  139. ((USSDStringImpl) this.ussdString).encodeAll(asnOs);
  140. } catch (IOException e) {
  141. throw new MAPException("IOException when encoding UnstructuredSSResponseIndication", e);
  142. } catch (AsnException e) {
  143. throw new MAPException("AsnException when encoding UnstructuredSSResponseIndication", e);
  144. }
  145. }
  146. @Override
  147. public String toString() {
  148. StringBuilder sb = new StringBuilder();
  149. sb.append("UnstructuredSSResponse [");
  150. sb.append("]");
  151. return sb.toString();
  152. }
  153. /**
  154. * XML Serialization/Deserialization
  155. */
  156. protected static final XMLFormat<UnstructuredSSResponseIndicationImpl> UNSTRUCTURED_SS_RESPONSE_XML = new XMLFormat<UnstructuredSSResponseIndicationImpl>(
  157. UnstructuredSSResponseIndicationImpl.class) {
  158. @Override
  159. public void read(javolution.xml.XMLFormat.InputElement xml, UnstructuredSSResponseIndicationImpl ussdMessage)
  160. throws XMLStreamException {
  161. USSD_MESSAGE_XML.read(xml, ussdMessage);
  162. }
  163. @Override
  164. public void write(UnstructuredSSResponseIndicationImpl ussdMessage, javolution.xml.XMLFormat.OutputElement xml)
  165. throws XMLStreamException {
  166. USSD_MESSAGE_XML.write(ussdMessage, xml);
  167. }
  168. };
  169. }