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

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