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

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