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

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