PageRenderTime 32ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 468 lines | 300 code | 48 blank | 120 comment | 95 complexity | 05547ec4add06875e0e0dc7fb3844daf MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  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.primitives.ISDNAddressString;
  32. import org.mobicents.protocols.ss7.map.api.primitives.LMSI;
  33. import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
  34. import org.mobicents.protocols.ss7.map.api.service.lsm.AdditionalNumber;
  35. import org.mobicents.protocols.ss7.map.api.service.lsm.LCSLocationInfo;
  36. import org.mobicents.protocols.ss7.map.api.service.lsm.SupportedLCSCapabilitySets;
  37. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  38. import org.mobicents.protocols.ss7.map.primitives.LMSIImpl;
  39. import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
  40. import org.mobicents.protocols.ss7.map.primitives.MAPExtensionContainerImpl;
  41. /**
  42. * TODO : Add unit test for this
  43. * @author amit bhayani
  44. *
  45. */
  46. public class LCSLocationInfoImpl implements LCSLocationInfo, MAPAsnPrimitive {
  47. private static final int _TAG_LMSI = 0;
  48. private static final int _TAG_EXTENSION_CONTAINER = 1;
  49. private static final int _TAG_GPRS_NODE_IND = 2;
  50. private static final int _TAG_ADDITIONAL_NUMBER = 3;
  51. private static final int _TAG_SUPPORTED_LCS_CAPBILITY_SET = 4;
  52. private static final int _TAG_ADDITIONAL_LCS_CAPBILITY_SET = 5;
  53. private ISDNAddressString networkNodeNumber = null;
  54. private LMSI lmsi = null;
  55. private MAPExtensionContainer extensionContainer = null;
  56. private Boolean gprsNodeIndicator = null;
  57. private AdditionalNumber additionalNumber = null;
  58. private SupportedLCSCapabilitySets supportedLCSCapabilitySets = null;
  59. private SupportedLCSCapabilitySets additionalLCSCapabilitySets = null;
  60. /**
  61. *
  62. */
  63. public LCSLocationInfoImpl() {
  64. super();
  65. }
  66. /**
  67. * @param networkNodeNumber
  68. * @param lmsi
  69. * @param extensionContainer
  70. * @param gprsNodeIndicator
  71. * @param additionalNumber
  72. * @param supportedLCSCapabilitySets
  73. * @param additionalLCSCapabilitySets
  74. */
  75. public LCSLocationInfoImpl(ISDNAddressString networkNodeNumber, LMSI lmsi, MAPExtensionContainer extensionContainer, Boolean gprsNodeIndicator,
  76. AdditionalNumber additionalNumber, SupportedLCSCapabilitySets supportedLCSCapabilitySets, SupportedLCSCapabilitySets additionalLCSCapabilitySets) {
  77. super();
  78. this.networkNodeNumber = networkNodeNumber;
  79. this.lmsi = lmsi;
  80. this.extensionContainer = extensionContainer;
  81. this.gprsNodeIndicator = gprsNodeIndicator;
  82. this.additionalNumber = additionalNumber;
  83. this.supportedLCSCapabilitySets = supportedLCSCapabilitySets;
  84. this.additionalLCSCapabilitySets = additionalLCSCapabilitySets;
  85. }
  86. /*
  87. * (non-Javadoc)
  88. *
  89. * @see org.mobicents.protocols.ss7.map.api.service.lsm.LCSLocationInfo#
  90. * getNetworkNodeNumber()
  91. */
  92. @Override
  93. public ISDNAddressString getNetworkNodeNumber() {
  94. return this.networkNodeNumber;
  95. }
  96. /*
  97. * (non-Javadoc)
  98. *
  99. * @see
  100. * org.mobicents.protocols.ss7.map.api.service.lsm.LCSLocationInfo#getLMSI()
  101. */
  102. @Override
  103. public LMSI getLMSI() {
  104. return this.lmsi;
  105. }
  106. /*
  107. * (non-Javadoc)
  108. *
  109. * @see org.mobicents.protocols.ss7.map.api.service.lsm.LCSLocationInfo#
  110. * getExtensionContainer()
  111. */
  112. @Override
  113. public MAPExtensionContainer getExtensionContainer() {
  114. return this.extensionContainer;
  115. }
  116. /*
  117. * (non-Javadoc)
  118. *
  119. * @see org.mobicents.protocols.ss7.map.api.service.lsm.LCSLocationInfo#
  120. * getGprsNodeIndicator()
  121. */
  122. @Override
  123. public Boolean getGprsNodeIndicator() {
  124. return this.gprsNodeIndicator;
  125. }
  126. /*
  127. * (non-Javadoc)
  128. *
  129. * @see org.mobicents.protocols.ss7.map.api.service.lsm.LCSLocationInfo#
  130. * getAdditionalNumber()
  131. */
  132. @Override
  133. public AdditionalNumber getAdditionalNumber() {
  134. return this.additionalNumber;
  135. }
  136. /*
  137. * (non-Javadoc)
  138. *
  139. * @see org.mobicents.protocols.ss7.map.api.service.lsm.LCSLocationInfo#
  140. * getSupportedLCSCapabilitySets()
  141. */
  142. @Override
  143. public SupportedLCSCapabilitySets getSupportedLCSCapabilitySets() {
  144. return this.supportedLCSCapabilitySets;
  145. }
  146. /*
  147. * (non-Javadoc)
  148. *
  149. * @see org.mobicents.protocols.ss7.map.api.service.lsm.LCSLocationInfo#
  150. * getadditionalLCSCapabilitySets()
  151. */
  152. @Override
  153. public SupportedLCSCapabilitySets getAdditionalLCSCapabilitySets() {
  154. return this.additionalLCSCapabilitySets;
  155. }
  156. /* (non-Javadoc)
  157. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
  158. */
  159. @Override
  160. public int getTag() throws MAPException {
  161. return Tag.SEQUENCE;
  162. }
  163. /* (non-Javadoc)
  164. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass()
  165. */
  166. @Override
  167. public int getTagClass() {
  168. return Tag.CLASS_UNIVERSAL;
  169. }
  170. /* (non-Javadoc)
  171. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive()
  172. */
  173. @Override
  174. public boolean getIsPrimitive() {
  175. return false;
  176. }
  177. /* (non-Javadoc)
  178. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll(org.mobicents.protocols.asn.AsnInputStream)
  179. */
  180. @Override
  181. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  182. try {
  183. int length = ansIS.readLength();
  184. this._decode(ansIS, length);
  185. } catch (IOException e) {
  186. throw new MAPParsingComponentException("IOException when decoding SM_RP_DA: " + e.getMessage(), e,
  187. MAPParsingComponentExceptionReason.MistypedParameter);
  188. } catch (AsnException e) {
  189. throw new MAPParsingComponentException("AsnException when decoding SM_RP_DA: " + e.getMessage(), e,
  190. MAPParsingComponentExceptionReason.MistypedParameter);
  191. }
  192. }
  193. /* (non-Javadoc)
  194. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData(org.mobicents.protocols.asn.AsnInputStream, int)
  195. */
  196. @Override
  197. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  198. try {
  199. this._decode(ansIS, length);
  200. } catch (IOException e) {
  201. throw new MAPParsingComponentException("IOException when decoding SM_RP_DA: " + e.getMessage(), e,
  202. MAPParsingComponentExceptionReason.MistypedParameter);
  203. } catch (AsnException e) {
  204. throw new MAPParsingComponentException("AsnException when decoding SM_RP_DA: " + e.getMessage(), e,
  205. MAPParsingComponentExceptionReason.MistypedParameter);
  206. }
  207. }
  208. private void _decode(AsnInputStream asnIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  209. AsnInputStream ais = asnIS.readSequenceStreamData(length);
  210. int tag = ais.readTag();
  211. if (ais.getTagClass() != Tag.CLASS_UNIVERSAL || !ais.isTagPrimitive() || tag != Tag.STRING_OCTET) {
  212. throw new MAPParsingComponentException(
  213. "Error while decoding LCSLocationInfo: Parameter [networkNode-Number ISDN-AddressString] bad tag class, tag or not primitive",
  214. MAPParsingComponentExceptionReason.MistypedParameter);
  215. }
  216. this.networkNodeNumber = new ISDNAddressStringImpl();
  217. ((ISDNAddressStringImpl)this.networkNodeNumber).decodeAll(ais);
  218. while(true){
  219. if (ais.available() == 0)
  220. break;
  221. tag = ais.readTag();
  222. switch(tag){
  223. case _TAG_LMSI:
  224. // lmsi [0] LMSI OPTIONAL,
  225. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  226. throw new MAPParsingComponentException(
  227. "Error while decoding LCSLocationInfo: Parameter [lmsi [0] LMSI ] bad tag class, tag or not primitive",
  228. MAPParsingComponentExceptionReason.MistypedParameter);
  229. }
  230. this.lmsi = new LMSIImpl();
  231. ((LMSIImpl)this.lmsi).decodeAll(ais);
  232. break;
  233. case _TAG_EXTENSION_CONTAINER:
  234. // extensionContainer [1] ExtensionContainer
  235. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  236. throw new MAPParsingComponentException(
  237. "Error while decoding LCSLocationInfo: Parameter [extensionContainer [1] ExtensionContainer ] bad tag class, tag or not primitive",
  238. MAPParsingComponentExceptionReason.MistypedParameter);
  239. }
  240. this.extensionContainer = new MAPExtensionContainerImpl();
  241. ((MAPExtensionContainerImpl)this.extensionContainer).decodeAll(ais);
  242. break;
  243. case _TAG_GPRS_NODE_IND:
  244. // gprsNodeIndicator [2] NULL
  245. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  246. throw new MAPParsingComponentException(
  247. "Error while decoding LCSLocationInfo: Parameter [gprsNodeIndicator [2] NULL ] bad tag class, tag or not primitive",
  248. MAPParsingComponentExceptionReason.MistypedParameter);
  249. }
  250. this.gprsNodeIndicator = true;
  251. break;
  252. case _TAG_ADDITIONAL_NUMBER:
  253. // additional-Number [3] Additional-Number OPTIONAL
  254. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive()) {
  255. throw new MAPParsingComponentException(
  256. "Error while decoding LCSLocationInfo: Parameter [additional-Number [3] Additional-Number] bad tag class, tag or not primitive",
  257. MAPParsingComponentExceptionReason.MistypedParameter);
  258. }
  259. int lenhth1 = ais.readLength();
  260. tag = ais.readTag();
  261. this.additionalNumber = new AdditionalNumberImpl();
  262. ((AdditionalNumberImpl)this.additionalNumber).decodeAll(ais);
  263. break;
  264. case _TAG_SUPPORTED_LCS_CAPBILITY_SET:
  265. // supportedLCS-CapabilitySets [4] SupportedLCS-CapabilitySets
  266. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  267. throw new MAPParsingComponentException(
  268. "Error while decoding LCSLocationInfo: Parameter [supportedLCS-CapabilitySets [4] SupportedLCS-CapabilitySets] bad tag class, tag or not primitive",
  269. MAPParsingComponentExceptionReason.MistypedParameter);
  270. }
  271. this.supportedLCSCapabilitySets = new SupportedLCSCapabilitySetsImpl();
  272. ((SupportedLCSCapabilitySetsImpl)this.supportedLCSCapabilitySets).decodeAll(ais);
  273. break;
  274. case _TAG_ADDITIONAL_LCS_CAPBILITY_SET:
  275. //additional-LCS-CapabilitySets [5] SupportedLCS-CapabilitySets OPTIONAL
  276. if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || !ais.isTagPrimitive()) {
  277. throw new MAPParsingComponentException(
  278. "Error while decoding LCSLocationInfo: Parameter [additional-LCS-CapabilitySets [5] SupportedLCS-CapabilitySets] bad tag class, tag or not primitive",
  279. MAPParsingComponentExceptionReason.MistypedParameter);
  280. }
  281. this.additionalLCSCapabilitySets = new SupportedLCSCapabilitySetsImpl();
  282. ((SupportedLCSCapabilitySetsImpl)this.additionalLCSCapabilitySets).decodeAll(ais);
  283. break;
  284. default:
  285. // throw new MAPParsingComponentException("Error while decoding LCSLocationInfo: Expected tags 0 - 5 but found" + p.getTag(),
  286. // MAPParsingComponentExceptionReason.MistypedParameter);
  287. ais.advanceElement();
  288. }
  289. }
  290. }
  291. /* (non-Javadoc)
  292. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll(org.mobicents.protocols.asn.AsnOutputStream)
  293. */
  294. @Override
  295. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  296. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.SEQUENCE);
  297. }
  298. /* (non-Javadoc)
  299. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll(org.mobicents.protocols.asn.AsnOutputStream, int, int)
  300. */
  301. @Override
  302. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  303. try {
  304. asnOs.writeTag(tagClass, false, tag);
  305. int pos = asnOs.StartContentDefiniteLength();
  306. this.encodeData(asnOs);
  307. asnOs.FinalizeContent(pos);
  308. } catch (AsnException e) {
  309. throw new MAPException("AsnException when encoding InformServiceCentreRequest: " + e.getMessage(), e);
  310. }
  311. }
  312. /* (non-Javadoc)
  313. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData(org.mobicents.protocols.asn.AsnOutputStream)
  314. */
  315. @Override
  316. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  317. if (this.networkNodeNumber == null) {
  318. throw new MAPException("Error while encoding LCSLocationInfo the mandatory parameter networkNode-Number ISDN-AddressString is not defined");
  319. }
  320. ((ISDNAddressStringImpl)this.networkNodeNumber).encodeAll(asnOs);
  321. if (this.lmsi != null) {
  322. // lmsi [0] LMSI OPTIONAL,
  323. ((LMSIImpl)this.lmsi).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LMSI);
  324. }
  325. if (this.extensionContainer != null) {
  326. // extensionContainer [1] ExtensionContainer OPTIONAL,
  327. ((MAPExtensionContainerImpl)this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_EXTENSION_CONTAINER);
  328. }
  329. if (this.gprsNodeIndicator != null && this.gprsNodeIndicator) {
  330. // gprsNodeIndicator [2] NULL OPTIONAL,
  331. try {
  332. asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_GPRS_NODE_IND);
  333. } catch (IOException e) {
  334. throw new MAPException("Error while encoding LCSLocationInfo the optional parameter gprsNodeIndicator encoding failed ", e);
  335. } catch (AsnException e) {
  336. throw new MAPException("Error while encoding LCSLocationInfo the optional parameter gprsNodeIndicator encoding failed ", e);
  337. }
  338. }
  339. if (this.additionalNumber != null) {
  340. // additional-Number [3] Additional-Number OPTIONAL,
  341. try {
  342. asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _TAG_ADDITIONAL_NUMBER);
  343. } catch (AsnException e) {
  344. throw new MAPException("AsnException while encoding parameter additional-Number");
  345. }
  346. int pos = asnOs.StartContentDefiniteLength();
  347. ((AdditionalNumberImpl)this.additionalNumber).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, ((AdditionalNumberImpl)this.additionalNumber).getTag());
  348. asnOs.FinalizeContent(pos);
  349. }
  350. if (this.supportedLCSCapabilitySets != null) {
  351. // supportedLCS-CapabilitySets [4] SupportedLCS-CapabilitySets
  352. // OPTIONAL,
  353. ((SupportedLCSCapabilitySetsImpl)this.supportedLCSCapabilitySets).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_SUPPORTED_LCS_CAPBILITY_SET);
  354. }
  355. if (this.additionalLCSCapabilitySets != null) {
  356. // additional-LCS-CapabilitySets [5] SupportedLCS-CapabilitySets
  357. // OPTIONAL
  358. ((SupportedLCSCapabilitySetsImpl)this.additionalLCSCapabilitySets).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_ADDITIONAL_LCS_CAPBILITY_SET);
  359. }
  360. }
  361. @Override
  362. public int hashCode() {
  363. final int prime = 31;
  364. int result = 1;
  365. result = prime * result + ((additionalLCSCapabilitySets == null) ? 0 : additionalLCSCapabilitySets.hashCode());
  366. result = prime * result + ((additionalNumber == null) ? 0 : additionalNumber.hashCode());
  367. result = prime * result + ((extensionContainer == null) ? 0 : extensionContainer.hashCode());
  368. result = prime * result + ((gprsNodeIndicator == null) ? 0 : gprsNodeIndicator.hashCode());
  369. result = prime * result + ((lmsi == null) ? 0 : lmsi.hashCode());
  370. result = prime * result + ((networkNodeNumber == null) ? 0 : networkNodeNumber.hashCode());
  371. result = prime * result + ((supportedLCSCapabilitySets == null) ? 0 : supportedLCSCapabilitySets.hashCode());
  372. return result;
  373. }
  374. @Override
  375. public boolean equals(Object obj) {
  376. if (this == obj)
  377. return true;
  378. if (obj == null)
  379. return false;
  380. if (getClass() != obj.getClass())
  381. return false;
  382. LCSLocationInfoImpl other = (LCSLocationInfoImpl) obj;
  383. if (additionalLCSCapabilitySets == null) {
  384. if (other.additionalLCSCapabilitySets != null)
  385. return false;
  386. } else if (!additionalLCSCapabilitySets.equals(other.additionalLCSCapabilitySets))
  387. return false;
  388. if (additionalNumber == null) {
  389. if (other.additionalNumber != null)
  390. return false;
  391. } else if (!additionalNumber.equals(other.additionalNumber))
  392. return false;
  393. if (extensionContainer == null) {
  394. if (other.extensionContainer != null)
  395. return false;
  396. } else if (!extensionContainer.equals(other.extensionContainer))
  397. return false;
  398. if (gprsNodeIndicator == null) {
  399. if (other.gprsNodeIndicator != null)
  400. return false;
  401. } else if (!gprsNodeIndicator.equals(other.gprsNodeIndicator))
  402. return false;
  403. if (lmsi == null) {
  404. if (other.lmsi != null)
  405. return false;
  406. } else if (!lmsi.equals(other.lmsi))
  407. return false;
  408. if (networkNodeNumber == null) {
  409. if (other.networkNodeNumber != null)
  410. return false;
  411. } else if (!networkNodeNumber.equals(other.networkNodeNumber))
  412. return false;
  413. if (supportedLCSCapabilitySets == null) {
  414. if (other.supportedLCSCapabilitySets != null)
  415. return false;
  416. } else if (!supportedLCSCapabilitySets.equals(other.supportedLCSCapabilitySets))
  417. return false;
  418. return true;
  419. }
  420. }