/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/lsm/AreaDefinitionImpl.java

http://mobicents.googlecode.com/ · Java · 246 lines · 128 code · 25 blank · 93 comment · 24 complexity · 98a42cb3854b151825b522f642b95cc3 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.lsm;
  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.service.lsm.AreaDefinition;
  32. import org.mobicents.protocols.ss7.map.api.service.lsm.AreaList;
  33. import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
  34. /**
  35. * @author amit bhayani
  36. *
  37. */
  38. public class AreaDefinitionImpl implements AreaDefinition, MAPAsnPrimitive {
  39. private AreaList areaList = null;
  40. /**
  41. *
  42. */
  43. public AreaDefinitionImpl() {
  44. super();
  45. }
  46. /**
  47. * @param areaList
  48. */
  49. public AreaDefinitionImpl(AreaList areaList) {
  50. super();
  51. this.areaList = areaList;
  52. }
  53. /*
  54. * (non-Javadoc)
  55. *
  56. * @see
  57. * org.mobicents.protocols.ss7.map.api.service.lsm.AreaDefinition#getAreaList
  58. * ()
  59. */
  60. @Override
  61. public AreaList getAreaList() {
  62. return this.areaList;
  63. }
  64. /*
  65. * (non-Javadoc)
  66. *
  67. * @see
  68. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
  69. */
  70. @Override
  71. public int getTag() throws MAPException {
  72. return Tag.SEQUENCE;
  73. }
  74. /*
  75. * (non-Javadoc)
  76. *
  77. * @see
  78. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass
  79. * ()
  80. */
  81. @Override
  82. public int getTagClass() {
  83. return Tag.CLASS_UNIVERSAL;
  84. }
  85. /*
  86. * (non-Javadoc)
  87. *
  88. * @see
  89. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive
  90. * ()
  91. */
  92. @Override
  93. public boolean getIsPrimitive() {
  94. return false;
  95. }
  96. /*
  97. * (non-Javadoc)
  98. *
  99. * @see
  100. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll
  101. * (org.mobicents.protocols.asn.AsnInputStream)
  102. */
  103. @Override
  104. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  105. try {
  106. int length = ansIS.readLength();
  107. this._decode(ansIS, length);
  108. } catch (IOException e) {
  109. throw new MAPParsingComponentException("IOException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
  110. MAPParsingComponentExceptionReason.MistypedParameter);
  111. } catch (AsnException e) {
  112. throw new MAPParsingComponentException("AsnException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
  113. MAPParsingComponentExceptionReason.MistypedParameter);
  114. }
  115. }
  116. /*
  117. * (non-Javadoc)
  118. *
  119. * @see
  120. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData
  121. * (org.mobicents.protocols.asn.AsnInputStream, int)
  122. */
  123. @Override
  124. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  125. try {
  126. this._decode(ansIS, length);
  127. } catch (IOException e) {
  128. throw new MAPParsingComponentException("IOException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
  129. MAPParsingComponentExceptionReason.MistypedParameter);
  130. } catch (AsnException e) {
  131. throw new MAPParsingComponentException("AsnException when decoding ReportSMDeliveryStatusRequest: " + e.getMessage(), e,
  132. MAPParsingComponentExceptionReason.MistypedParameter);
  133. }
  134. }
  135. private void _decode(AsnInputStream asnIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  136. AsnInputStream ais = asnIS.readSequenceStreamData(length);
  137. int tag = ais.readTag();
  138. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive() || tag != 0) {
  139. throw new MAPParsingComponentException(
  140. "Error while decoding AreaDefinition: Parameter 0 [areaList [0] AreaList] bad tag class, tag or not primitive",
  141. MAPParsingComponentExceptionReason.MistypedParameter);
  142. }
  143. this.areaList = new AreaListImpl();
  144. ((AreaListImpl) this.areaList).decodeAll(ais);
  145. while (true) {
  146. if (ais.available() == 0)
  147. break;
  148. switch (ais.readTag()) {
  149. default:
  150. ais.advanceElement();
  151. break;
  152. }
  153. }
  154. }
  155. /*
  156. * (non-Javadoc)
  157. *
  158. * @see
  159. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
  160. * (org.mobicents.protocols.asn.AsnOutputStream)
  161. */
  162. @Override
  163. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  164. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  165. }
  166. /*
  167. * (non-Javadoc)
  168. *
  169. * @see
  170. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
  171. * (org.mobicents.protocols.asn.AsnOutputStream, int, int)
  172. */
  173. @Override
  174. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  175. try {
  176. asnOs.writeTag(tagClass, false, tag);
  177. int pos = asnOs.StartContentDefiniteLength();
  178. this.encodeData(asnOs);
  179. asnOs.FinalizeContent(pos);
  180. } catch (AsnException e) {
  181. throw new MAPException("AsnException when encoding reportSMDeliveryStatusRequest: " + e.getMessage(), e);
  182. }
  183. }
  184. /*
  185. * (non-Javadoc)
  186. *
  187. * @see
  188. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData
  189. * (org.mobicents.protocols.asn.AsnOutputStream)
  190. */
  191. @Override
  192. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  193. if (this.areaList == null) {
  194. throw new MAPException("Error while encoding AreaDefinition the mandatory parameter[areaList [0] AreaList] is not defined");
  195. }
  196. ((AreaListImpl) this.areaList).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, 0);
  197. }
  198. @Override
  199. public int hashCode() {
  200. final int prime = 31;
  201. int result = 1;
  202. result = prime * result + ((areaList == null) ? 0 : areaList.hashCode());
  203. return result;
  204. }
  205. @Override
  206. public boolean equals(Object obj) {
  207. if (this == obj)
  208. return true;
  209. if (obj == null)
  210. return false;
  211. if (getClass() != obj.getClass())
  212. return false;
  213. AreaDefinitionImpl other = (AreaDefinitionImpl) obj;
  214. if (areaList == null) {
  215. if (other.areaList != null)
  216. return false;
  217. } else if (!areaList.equals(other.areaList))
  218. return false;
  219. return true;
  220. }
  221. }