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

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