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

http://mobicents.googlecode.com/ · Java · 273 lines · 195 code · 52 blank · 26 comment · 45 complexity · ced9000758c669fef92e39dc585292df 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.MAPErrorMessageFacilityNotSup;
  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 MAPErrorMessageFacilityNotSupImpl extends MAPErrorMessageImpl implements MAPErrorMessageFacilityNotSup {
  41. public static final int shapeOfLocationEstimateNotSupported_TAG = 0;
  42. public static final int neededLcsCapabilityNotSupportedInServingNode_TAG = 1;
  43. private MAPExtensionContainer extensionContainer;
  44. private Boolean shapeOfLocationEstimateNotSupported;
  45. private Boolean neededLcsCapabilityNotSupportedInServingNode;
  46. public MAPErrorMessageFacilityNotSupImpl(MAPExtensionContainer extensionContainer, Boolean shapeOfLocationEstimateNotSupported,
  47. Boolean neededLcsCapabilityNotSupportedInServingNode) {
  48. super((long) MAPErrorCode.facilityNotSupported);
  49. this.extensionContainer = extensionContainer;
  50. this.shapeOfLocationEstimateNotSupported = shapeOfLocationEstimateNotSupported;
  51. this.neededLcsCapabilityNotSupportedInServingNode = neededLcsCapabilityNotSupportedInServingNode;
  52. }
  53. protected MAPErrorMessageFacilityNotSupImpl() {
  54. super((long) MAPErrorCode.facilityNotSupported);
  55. }
  56. @Override
  57. public boolean isEmFacilityNotSup() {
  58. return true;
  59. }
  60. @Override
  61. public MAPErrorMessageFacilityNotSup getEmFacilityNotSup() {
  62. return this;
  63. }
  64. @Override
  65. public MAPExtensionContainer getExtensionContainer() {
  66. return this.extensionContainer;
  67. }
  68. @Override
  69. public Boolean getShapeOfLocationEstimateNotSupported() {
  70. return this.shapeOfLocationEstimateNotSupported;
  71. }
  72. @Override
  73. public Boolean getNeededLcsCapabilityNotSupportedInServingNode() {
  74. return this.neededLcsCapabilityNotSupportedInServingNode;
  75. }
  76. @Override
  77. public void setExtensionContainer(MAPExtensionContainer extensionContainer) {
  78. this.extensionContainer = extensionContainer;
  79. }
  80. @Override
  81. public void setShapeOfLocationEstimateNotSupported(Boolean shapeOfLocationEstimateNotSupported) {
  82. this.shapeOfLocationEstimateNotSupported = shapeOfLocationEstimateNotSupported;
  83. }
  84. @Override
  85. public void getNeededLcsCapabilityNotSupportedInServingNode(Boolean neededLcsCapabilityNotSupportedInServingNode) {
  86. this.neededLcsCapabilityNotSupportedInServingNode = neededLcsCapabilityNotSupportedInServingNode;
  87. }
  88. @Override
  89. public int getTag() throws MAPException {
  90. return Tag.SEQUENCE;
  91. }
  92. @Override
  93. public int getTagClass() {
  94. return Tag.CLASS_UNIVERSAL;
  95. }
  96. @Override
  97. public boolean getIsPrimitive() {
  98. return false;
  99. }
  100. @Override
  101. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  102. try {
  103. int length = ansIS.readLength();
  104. this._decode(ansIS, length);
  105. } catch (IOException e) {
  106. throw new MAPParsingComponentException("IOException when decoding MAPErrorMessageFacilityNotSup: " + e.getMessage(), e,
  107. MAPParsingComponentExceptionReason.MistypedParameter);
  108. } catch (AsnException e) {
  109. throw new MAPParsingComponentException("AsnException when decoding MAPErrorMessageFacilityNotSup: " + e.getMessage(), e,
  110. MAPParsingComponentExceptionReason.MistypedParameter);
  111. }
  112. }
  113. @Override
  114. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  115. try {
  116. this._decode(ansIS, length);
  117. } catch (IOException e) {
  118. throw new MAPParsingComponentException("IOException when decoding MAPErrorMessageFacilityNotSup: " + e.getMessage(), e,
  119. MAPParsingComponentExceptionReason.MistypedParameter);
  120. } catch (AsnException e) {
  121. throw new MAPParsingComponentException("AsnException when decoding MAPErrorMessageFacilityNotSup: " + e.getMessage(), e,
  122. MAPParsingComponentExceptionReason.MistypedParameter);
  123. }
  124. }
  125. private void _decode(AsnInputStream localAis, int length) throws MAPParsingComponentException, IOException, AsnException {
  126. this.extensionContainer = null;
  127. this.shapeOfLocationEstimateNotSupported = null;
  128. this.neededLcsCapabilityNotSupportedInServingNode = null;
  129. if (localAis.getTagClass() != Tag.CLASS_UNIVERSAL || localAis.getTag() != Tag.SEQUENCE || localAis.isTagPrimitive())
  130. throw new MAPParsingComponentException(
  131. "Error decoding MAPErrorMessageFacilityNotSup: bad tag class or tag or parameter is primitive or no parameter data",
  132. MAPParsingComponentExceptionReason.MistypedParameter);
  133. AsnInputStream ais = localAis.readSequenceStreamData(length);
  134. while (true) {
  135. if (ais.available() == 0)
  136. break;
  137. int tag = ais.readTag();
  138. switch (ais.getTagClass()) {
  139. case Tag.CLASS_UNIVERSAL:
  140. switch (tag) {
  141. case Tag.SEQUENCE:
  142. this.extensionContainer = new MAPExtensionContainerImpl();
  143. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
  144. break;
  145. default:
  146. ais.advanceElement();
  147. break;
  148. }
  149. break;
  150. case Tag.CLASS_CONTEXT_SPECIFIC:
  151. switch (tag) {
  152. case shapeOfLocationEstimateNotSupported_TAG:
  153. ais.readNull();
  154. this.shapeOfLocationEstimateNotSupported = true;
  155. break;
  156. case neededLcsCapabilityNotSupportedInServingNode_TAG:
  157. ais.readNull();
  158. this.neededLcsCapabilityNotSupportedInServingNode = true;
  159. break;
  160. default:
  161. ais.advanceElement();
  162. break;
  163. }
  164. break;
  165. default:
  166. ais.advanceElement();
  167. break;
  168. }
  169. }
  170. if (this.shapeOfLocationEstimateNotSupported == null)
  171. this.shapeOfLocationEstimateNotSupported = false;
  172. if (this.neededLcsCapabilityNotSupportedInServingNode == null)
  173. this.neededLcsCapabilityNotSupportedInServingNode = false;
  174. }
  175. @Override
  176. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  177. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  178. }
  179. @Override
  180. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  181. try {
  182. asnOs.writeTag(tagClass, false, tag);
  183. int pos = asnOs.StartContentDefiniteLength();
  184. this.encodeData(asnOs);
  185. asnOs.FinalizeContent(pos);
  186. } catch (AsnException e) {
  187. throw new MAPException("AsnException when encoding MAPErrorMessageFacilityNotSup: " + e.getMessage(), e);
  188. }
  189. }
  190. @Override
  191. public void encodeData(AsnOutputStream aos) throws MAPException {
  192. if (this.extensionContainer == null && (this.shapeOfLocationEstimateNotSupported == null || this.shapeOfLocationEstimateNotSupported == false)
  193. && (this.neededLcsCapabilityNotSupportedInServingNode == null || this.neededLcsCapabilityNotSupportedInServingNode == false))
  194. return;
  195. try {
  196. if (this.extensionContainer != null)
  197. ((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(aos);
  198. if(this.shapeOfLocationEstimateNotSupported != null && this.shapeOfLocationEstimateNotSupported == true)
  199. aos.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, shapeOfLocationEstimateNotSupported_TAG);
  200. if(this.neededLcsCapabilityNotSupportedInServingNode != null && this.neededLcsCapabilityNotSupportedInServingNode == true)
  201. aos.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, neededLcsCapabilityNotSupportedInServingNode_TAG);
  202. } catch (IOException e) {
  203. throw new MAPException("IOException when encoding MAPErrorMessageFacilityNotSup: " + e.getMessage(), e);
  204. } catch (AsnException e) {
  205. throw new MAPException("AsnException when encoding MAPErrorMessageFacilityNotSup: " + e.getMessage(), e);
  206. }
  207. }
  208. @Override
  209. public String toString() {
  210. StringBuilder sb = new StringBuilder();
  211. sb.append("MAPErrorMessageFacilityNotSup [");
  212. if (this.extensionContainer != null)
  213. sb.append("extensionContainer=" + this.extensionContainer.toString());
  214. if (this.shapeOfLocationEstimateNotSupported != null && this.shapeOfLocationEstimateNotSupported == true)
  215. sb.append(", shapeOfLocationEstimateNotSupported=true");
  216. if (this.neededLcsCapabilityNotSupportedInServingNode != null && this.neededLcsCapabilityNotSupportedInServingNode == true)
  217. sb.append(", neededLcsCapabilityNotSupportedInServingNode=true");
  218. sb.append("]");
  219. return sb.toString();
  220. }
  221. }