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

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