/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/errors/MAPErrorMessageSubscriberBusyForMtSmsImpl.java

http://mobicents.googlecode.com/ · Java · 235 lines · 163 code · 46 blank · 26 comment · 28 complexity · 14cd19ce084a67dededd1b752f840c94 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.errors;
  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.MAPParsingComponentException;
  30. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason;
  31. import org.mobicents.protocols.ss7.map.api.errors.MAPErrorCode;
  32. import org.mobicents.protocols.ss7.map.api.errors.MAPErrorMessageSubscriberBusyForMtSms;
  33. import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
  34. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  35. /**
  36. *
  37. * @author sergey vetyutnev
  38. *
  39. */
  40. public class MAPErrorMessageSubscriberBusyForMtSmsImpl extends MAPErrorMessageImpl implements MAPErrorMessageSubscriberBusyForMtSms {
  41. private MAPExtensionContainer extensionContainer;
  42. private Boolean gprsConnectionSuspended;
  43. public MAPErrorMessageSubscriberBusyForMtSmsImpl(MAPExtensionContainer extensionContainer, Boolean gprsConnectionSuspended) {
  44. super((long) MAPErrorCode.subscriberBusyForMTSMS);
  45. this.extensionContainer = extensionContainer;
  46. this.gprsConnectionSuspended = gprsConnectionSuspended;
  47. }
  48. protected MAPErrorMessageSubscriberBusyForMtSmsImpl() {
  49. super((long) MAPErrorCode.subscriberBusyForMTSMS);
  50. }
  51. @Override
  52. public boolean isEmSubscriberBusyForMtSms() {
  53. return true;
  54. }
  55. @Override
  56. public MAPErrorMessageSubscriberBusyForMtSms getEmSubscriberBusyForMtSms() {
  57. return this;
  58. }
  59. @Override
  60. public MAPExtensionContainer getExtensionContainer() {
  61. return this.extensionContainer;
  62. }
  63. @Override
  64. public Boolean getGprsConnectionSuspended() {
  65. return this.gprsConnectionSuspended;
  66. }
  67. @Override
  68. public void setExtensionContainer(MAPExtensionContainer extensionContainer) {
  69. this.extensionContainer = extensionContainer;
  70. }
  71. @Override
  72. public void setGprsConnectionSuspended(Boolean gprsConnectionSuspended) {
  73. this.gprsConnectionSuspended = gprsConnectionSuspended;
  74. }
  75. @Override
  76. public int getTag() throws MAPException {
  77. return Tag.SEQUENCE;
  78. }
  79. @Override
  80. public int getTagClass() {
  81. return Tag.CLASS_UNIVERSAL;
  82. }
  83. @Override
  84. public boolean getIsPrimitive() {
  85. return false;
  86. }
  87. @Override
  88. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  89. try {
  90. int length = ansIS.readLength();
  91. this._decode(ansIS, length);
  92. } catch (IOException e) {
  93. throw new MAPParsingComponentException("IOException when decoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e,
  94. MAPParsingComponentExceptionReason.MistypedParameter);
  95. } catch (AsnException e) {
  96. throw new MAPParsingComponentException("AsnException when decoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e,
  97. MAPParsingComponentExceptionReason.MistypedParameter);
  98. }
  99. }
  100. @Override
  101. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  102. try {
  103. this._decode(ansIS, length);
  104. } catch (IOException e) {
  105. throw new MAPParsingComponentException("IOException when decoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e,
  106. MAPParsingComponentExceptionReason.MistypedParameter);
  107. } catch (AsnException e) {
  108. throw new MAPParsingComponentException("AsnException when decoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e,
  109. MAPParsingComponentExceptionReason.MistypedParameter);
  110. }
  111. }
  112. private void _decode(AsnInputStream localAis, int length) throws MAPParsingComponentException, IOException, AsnException {
  113. this.extensionContainer = null;
  114. this.gprsConnectionSuspended = null;
  115. if (localAis.getTagClass() != Tag.CLASS_UNIVERSAL || localAis.getTag() != Tag.SEQUENCE || localAis.isTagPrimitive())
  116. throw new MAPParsingComponentException(
  117. "Error decoding MAPErrorMessageSubscriberBusyForMtSms: bad tag class or tag or parameter is primitive",
  118. MAPParsingComponentExceptionReason.MistypedParameter);
  119. AsnInputStream ais = localAis.readSequenceStreamData(length);
  120. while (true) {
  121. if (ais.available() == 0)
  122. break;
  123. int tag = ais.readTag();
  124. switch (ais.getTagClass()) {
  125. case Tag.CLASS_UNIVERSAL:
  126. switch (tag) {
  127. case Tag.SEQUENCE:
  128. this.extensionContainer = new MAPExtensionContainerImpl();
  129. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
  130. break;
  131. case Tag.NULL:
  132. ais.readNull();
  133. this.gprsConnectionSuspended = true;
  134. break;
  135. default:
  136. ais.advanceElement();
  137. break;
  138. }
  139. break;
  140. default:
  141. ais.advanceElement();
  142. break;
  143. }
  144. }
  145. if (this.gprsConnectionSuspended == null)
  146. this.gprsConnectionSuspended = false;
  147. }
  148. @Override
  149. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  150. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  151. }
  152. @Override
  153. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  154. try {
  155. asnOs.writeTag(tagClass, false, tag);
  156. int pos = asnOs.StartContentDefiniteLength();
  157. this.encodeData(asnOs);
  158. asnOs.FinalizeContent(pos);
  159. } catch (AsnException e) {
  160. throw new MAPException("AsnException when encoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e);
  161. }
  162. }
  163. @Override
  164. public void encodeData(AsnOutputStream aos) throws MAPException {
  165. if (this.gprsConnectionSuspended == null && this.extensionContainer == null)
  166. return;
  167. try {
  168. if (this.extensionContainer != null)
  169. ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(aos);
  170. if (this.gprsConnectionSuspended != null && this.gprsConnectionSuspended == true)
  171. aos.writeNull();
  172. } catch (IOException e) {
  173. throw new MAPException("IOException when encoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e);
  174. } catch (AsnException e) {
  175. throw new MAPException("AsnException when encoding MAPErrorMessageSubscriberBusyForMtSms: " + e.getMessage(), e);
  176. }
  177. }
  178. @Override
  179. public String toString() {
  180. StringBuilder sb = new StringBuilder();
  181. sb.append("MAPErrorMessageSubscriberBusyForMtSms [");
  182. if (this.extensionContainer != null)
  183. sb.append("extensionContainer=" + this.extensionContainer.toString());
  184. if (this.gprsConnectionSuspended != null && this.gprsConnectionSuspended == true)
  185. sb.append(", gprsConnectionSuspended=true");
  186. sb.append("]");
  187. return sb.toString();
  188. }
  189. }