/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/service/subscriberInformation/LocationInformationImpl.java

http://mobicents.googlecode.com/ · Java · 414 lines · 307 code · 58 blank · 49 comment · 27 complexity · a1e969c427f8233e4dd3814c4623b2ed 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.subscriberInformation;
  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.CellGlobalIdOrServiceAreaIdOrLAI;
  32. import org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString;
  33. import org.mobicents.protocols.ss7.map.api.primitives.MAPExtensionContainer;
  34. import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.GeodeticInformation;
  35. import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.GeographicalInformation;
  36. import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.LSAIdentity;
  37. import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.LocationInformation;
  38. import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.LocationInformationEPS;
  39. import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.LocationNumberMap;
  40. import org.mobicents.protocols.ss7.map.api.service.subscriberInformation.UserCSGInformation;
  41. import org.mobicents.protocols.ss7.map.primitives.CellGlobalIdOrServiceAreaIdOrLAIImpl;
  42. import org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl;
  43. import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
  44. /**
  45. *
  46. * @author sergey vetyutnev
  47. *
  48. */
  49. public class LocationInformationImpl implements LocationInformation, MAPAsnPrimitive {
  50. public static final int _ID_geographicalInformation = 0;
  51. public static final int _ID_vlr_number = 1;
  52. public static final int _ID_locationNumber = 2;
  53. public static final int _ID_cellGlobalIdOrServiceAreaIdOrLAI = 3;
  54. public static final int _ID_extensionContainer = 4;
  55. public static final int _ID_selectedLSA_Id = 5;
  56. public static final int _ID_msc_Number = 6;
  57. public static final int _ID_geodeticInformation = 7;
  58. public static final int _ID_currentLocationRetrieved = 8;
  59. public static final int _ID_sai_Present = 9;
  60. public static final int _ID_locationInformationEPS = 10;
  61. public static final int _ID_userCSGInformation = 11;
  62. public static final String _PrimitiveName = "LocationInformation";
  63. private Integer ageOfLocationInformation;
  64. private GeographicalInformation geographicalInformation;
  65. private ISDNAddressString vlrNumber;
  66. private LocationNumberMap locationNumber;
  67. private CellGlobalIdOrServiceAreaIdOrLAI cellGlobalIdOrServiceAreaIdOrLAI;
  68. private MAPExtensionContainer extensionContainer;
  69. private LSAIdentity selectedLSAId;
  70. private ISDNAddressString mscNumber;
  71. private GeodeticInformation geodeticInformation;
  72. private boolean currentLocationRetrieved;
  73. private boolean saiPresent;
  74. private LocationInformationEPS locationInformationEPS;
  75. private UserCSGInformation userCSGInformation;
  76. public LocationInformationImpl() {
  77. }
  78. public LocationInformationImpl(Integer ageOfLocationInformation, GeographicalInformation geographicalInformation, ISDNAddressString vlrNumber,
  79. LocationNumberMap locationNumber, CellGlobalIdOrServiceAreaIdOrLAI cellGlobalIdOrServiceAreaIdOrLAI, MAPExtensionContainer extensionContainer,
  80. LSAIdentity selectedLSAId, ISDNAddressString mscNumber, GeodeticInformation geodeticInformation, boolean currentLocationRetrieved,
  81. boolean saiPresent, LocationInformationEPS locationInformationEPS, UserCSGInformation userCSGInformation) {
  82. this.ageOfLocationInformation = ageOfLocationInformation;
  83. this.geographicalInformation = geographicalInformation;
  84. this.vlrNumber = vlrNumber;
  85. this.locationNumber = locationNumber;
  86. this.cellGlobalIdOrServiceAreaIdOrLAI = cellGlobalIdOrServiceAreaIdOrLAI;
  87. this.extensionContainer = extensionContainer;
  88. this.selectedLSAId = selectedLSAId;
  89. this.mscNumber = mscNumber;
  90. this.geodeticInformation = geodeticInformation;
  91. this.currentLocationRetrieved = currentLocationRetrieved;
  92. this.saiPresent = saiPresent;
  93. this.locationInformationEPS = locationInformationEPS;
  94. this.userCSGInformation = userCSGInformation;
  95. }
  96. @Override
  97. public Integer getAgeOfLocationInformation() {
  98. return this.ageOfLocationInformation;
  99. }
  100. @Override
  101. public GeographicalInformation getGeographicalInformation() {
  102. return this.geographicalInformation;
  103. }
  104. @Override
  105. public ISDNAddressString getVlrNumber() {
  106. return this.vlrNumber;
  107. }
  108. @Override
  109. public LocationNumberMap getLocationNumber() {
  110. return locationNumber;
  111. }
  112. @Override
  113. public CellGlobalIdOrServiceAreaIdOrLAI getCellGlobalIdOrServiceAreaIdOrLAI() {
  114. return cellGlobalIdOrServiceAreaIdOrLAI;
  115. }
  116. @Override
  117. public MAPExtensionContainer getExtensionContainer() {
  118. return extensionContainer;
  119. }
  120. @Override
  121. public LSAIdentity getSelectedLSAId() {
  122. return selectedLSAId;
  123. }
  124. @Override
  125. public ISDNAddressString getMscNumber() {
  126. return mscNumber;
  127. }
  128. @Override
  129. public GeodeticInformation getGeodeticInformation() {
  130. return geodeticInformation;
  131. }
  132. @Override
  133. public boolean getCurrentLocationRetrieved() {
  134. return currentLocationRetrieved;
  135. }
  136. @Override
  137. public boolean getSaiPresent() {
  138. return saiPresent;
  139. }
  140. @Override
  141. public LocationInformationEPS getLocationInformationEPS() {
  142. return locationInformationEPS;
  143. }
  144. @Override
  145. public UserCSGInformation getUserCSGInformation() {
  146. return userCSGInformation;
  147. }
  148. @Override
  149. public int getTag() throws MAPException {
  150. return Tag.SEQUENCE;
  151. }
  152. @Override
  153. public int getTagClass() {
  154. return Tag.CLASS_UNIVERSAL;
  155. }
  156. @Override
  157. public boolean getIsPrimitive() {
  158. return false;
  159. }
  160. @Override
  161. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  162. try {
  163. int length = ansIS.readLength();
  164. this._decode(ansIS, length);
  165. } catch (IOException e) {
  166. throw new MAPParsingComponentException("IOException when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
  167. MAPParsingComponentExceptionReason.MistypedParameter);
  168. } catch (AsnException e) {
  169. throw new MAPParsingComponentException("AsnException when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
  170. MAPParsingComponentExceptionReason.MistypedParameter);
  171. }
  172. }
  173. @Override
  174. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  175. try {
  176. this._decode(ansIS, length);
  177. } catch (IOException e) {
  178. throw new MAPParsingComponentException("IOException when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
  179. MAPParsingComponentExceptionReason.MistypedParameter);
  180. } catch (AsnException e) {
  181. throw new MAPParsingComponentException("AsnException when decoding " + _PrimitiveName + ": " + e.getMessage(), e,
  182. MAPParsingComponentExceptionReason.MistypedParameter);
  183. }
  184. }
  185. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  186. this.ageOfLocationInformation = null;
  187. this.geographicalInformation = null;
  188. this.vlrNumber = null;
  189. this.locationNumber = null;
  190. this.cellGlobalIdOrServiceAreaIdOrLAI = null;
  191. this.extensionContainer = null;
  192. this.selectedLSAId = null;
  193. this.mscNumber = null;
  194. this.geodeticInformation = null;
  195. this.currentLocationRetrieved = false;
  196. this.saiPresent = false;
  197. this.locationInformationEPS = null;
  198. this.userCSGInformation = null;
  199. AsnInputStream ais = ansIS.readSequenceStreamData(length);
  200. while( true ) {
  201. if( ais.available()==0 )
  202. break;
  203. int tag = ais.readTag();
  204. // optional parameters
  205. if (ais.getTagClass() == Tag.CLASS_UNIVERSAL) {
  206. switch (tag) {
  207. case Tag.INTEGER: // AgeOfLocationInformation
  208. this.ageOfLocationInformation = (int) ais.readInteger();
  209. break;
  210. default:
  211. ais.advanceElement();
  212. break;
  213. }
  214. } else if (ais.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) {
  215. switch (tag) {
  216. case _ID_geographicalInformation:
  217. ais.advanceElement(); // TODO: implement it
  218. break;
  219. case _ID_vlr_number:
  220. this.vlrNumber = new ISDNAddressStringImpl();
  221. ((ISDNAddressStringImpl) this.vlrNumber).decodeAll(ais);
  222. break;
  223. case _ID_locationNumber:
  224. this.locationNumber = new LocationNumberMapImpl();
  225. ((LocationNumberMapImpl) this.locationNumber).decodeAll(ais);
  226. break;
  227. case _ID_cellGlobalIdOrServiceAreaIdOrLAI:
  228. this.cellGlobalIdOrServiceAreaIdOrLAI = new CellGlobalIdOrServiceAreaIdOrLAIImpl();
  229. AsnInputStream ais2 = ais.readSequenceStream();
  230. ais2.readTag();
  231. ((CellGlobalIdOrServiceAreaIdOrLAIImpl) this.cellGlobalIdOrServiceAreaIdOrLAI).decodeAll(ais2);
  232. break;
  233. case _ID_extensionContainer:
  234. ais.advanceElement(); // TODO: implement it
  235. break;
  236. case _ID_selectedLSA_Id:
  237. ais.advanceElement(); // TODO: implement it
  238. break;
  239. case _ID_msc_Number:
  240. ais.advanceElement(); // TODO: implement it
  241. break;
  242. case _ID_geodeticInformation:
  243. ais.advanceElement(); // TODO: implement it
  244. break;
  245. case _ID_currentLocationRetrieved:
  246. ais.advanceElement(); // TODO: implement it
  247. break;
  248. case _ID_sai_Present:
  249. ais.advanceElement(); // TODO: implement it
  250. break;
  251. case _ID_locationInformationEPS:
  252. ais.advanceElement(); // TODO: implement it
  253. break;
  254. case _ID_userCSGInformation:
  255. ais.advanceElement(); // TODO: implement it
  256. break;
  257. default:
  258. ais.advanceElement();
  259. break;
  260. }
  261. } else {
  262. ais.advanceElement();
  263. }
  264. }
  265. }
  266. @Override
  267. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  268. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, this.getTag());
  269. }
  270. @Override
  271. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  272. try {
  273. asnOs.writeTag(tagClass, true, tag);
  274. int pos = asnOs.StartContentDefiniteLength();
  275. this.encodeData(asnOs);
  276. asnOs.FinalizeContent(pos);
  277. } catch (AsnException e) {
  278. throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
  279. }
  280. }
  281. @Override
  282. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  283. try {
  284. if (ageOfLocationInformation != null)
  285. asnOs.writeInteger((int) ageOfLocationInformation);
  286. // TODO: implement unimplemented members
  287. // private GeographicalInformation geographicalInformation;
  288. if (vlrNumber != null)
  289. ((ISDNAddressStringImpl) vlrNumber).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_vlr_number);
  290. if (locationNumber != null)
  291. ((LocationNumberMapImpl) locationNumber).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_locationNumber);
  292. if (cellGlobalIdOrServiceAreaIdOrLAI != null) {
  293. try {
  294. asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _ID_cellGlobalIdOrServiceAreaIdOrLAI);
  295. int pos = asnOs.StartContentDefiniteLength();
  296. ((CellGlobalIdOrServiceAreaIdOrLAIImpl) this.cellGlobalIdOrServiceAreaIdOrLAI).encodeAll(asnOs);
  297. asnOs.FinalizeContent(pos);
  298. } catch (AsnException e) {
  299. throw new MAPException("AsnException while encoding parameter cellGlobalIdOrServiceAreaIdOrLAI", e);
  300. }
  301. }
  302. // TODO: implement unimplemented members
  303. // private MAPExtensionContainer extensionContainer;
  304. // private LSAIdentity selectedLSAId;
  305. // private ISDNAddressString mscNumber;
  306. // private GeodeticInformation geodeticInformation;
  307. // private boolean currentLocationRetrieved;
  308. // private boolean saiPresent;
  309. // private LocationInformationEPS locationInformationEPS;
  310. // private UserCSGInformation userCSGInformation;
  311. } catch (IOException e) {
  312. throw new MAPException("IOException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
  313. } catch (AsnException e) {
  314. throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
  315. }
  316. }
  317. @Override
  318. public String toString() {
  319. StringBuilder sb = new StringBuilder();
  320. sb.append("LocationInformation [");
  321. if (this.ageOfLocationInformation != null) {
  322. sb.append("ageOfLocationInformation=");
  323. sb.append(this.ageOfLocationInformation);
  324. }
  325. // TODO: implement unimplemented members
  326. // private GeographicalInformation geographicalInformation;
  327. if (this.vlrNumber != null) {
  328. sb.append(", vlrNumber=");
  329. sb.append(this.vlrNumber.toString());
  330. }
  331. if (this.locationNumber != null) {
  332. sb.append(", locationNumber=");
  333. sb.append(this.locationNumber.toString());
  334. }
  335. if (this.cellGlobalIdOrServiceAreaIdOrLAI != null) {
  336. sb.append(", cellGlobalIdOrServiceAreaIdOrLAI=[");
  337. sb.append(this.cellGlobalIdOrServiceAreaIdOrLAI.toString());
  338. sb.append("]");
  339. }
  340. if (this.extensionContainer != null) {
  341. sb.append(", extensionContainer=");
  342. sb.append(this.extensionContainer.toString());
  343. }
  344. // TODO: implement unimplemented members
  345. // private MAPExtensionContainer extensionContainer;
  346. // private LSAIdentity selectedLSAId;
  347. // private ISDNAddressString mscNumber;
  348. // private GeodeticInformation geodeticInformation;
  349. // private boolean currentLocationRetrieved;
  350. // private boolean saiPresent;
  351. // private LocationInformationEPS locationInformationEPS;
  352. // private UserCSGInformation userCSGInformation;
  353. sb.append("]");
  354. return sb.toString();
  355. }
  356. }