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

http://mobicents.googlecode.com/ · Java · 314 lines · 161 code · 26 blank · 127 comment · 23 complexity · 9ebdf560f4ed7c59fe8f434c11d947f5 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
  4. * contributors as indicated by the @authors tag. All rights reserved.
  5. * See the copyright.txt in the distribution for a full listing
  6. * of individual contributors.
  7. *
  8. * This copyrighted material is made available to anyone wishing to use,
  9. * modify, copy, or redistribute it subject to the terms and conditions
  10. * of the GNU General Public License, v. 2.0.
  11. *
  12. * This program 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. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License,
  18. * v. 2.0 along with this distribution; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20. * MA 02110-1301, USA.
  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.BitSetStrictLength;
  28. import org.mobicents.protocols.asn.Tag;
  29. import org.mobicents.protocols.ss7.map.api.MAPException;
  30. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
  31. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentExceptionReason;
  32. import org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes;
  33. import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
  34. /**
  35. * @author amit bhayani
  36. *
  37. */
  38. public class SupportedGADShapesImpl implements SupportedGADShapes, MAPAsnPrimitive {
  39. private static final int _INDEX_ELLIPSOID_POINT = 0;
  40. private static final int _INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_CIRCLE = 1;
  41. private static final int _INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_ELLIPSE = 2;
  42. private static final int _INDEX_POLYGON = 3;
  43. private static final int _INDEX_ELLIPSOID_POINT_WITH_ALTITUDE = 4;
  44. private static final int _INDEX_ELLIPSOID_WITH_ALTITUDE_AND_UNCERTAINTY_ELIPSOID = 5;
  45. private static final int _INDEX_ELLIPSOID_ARC = 6;
  46. // TODO : Is this correct?
  47. private BitSetStrictLength bitString = new BitSetStrictLength(7);
  48. /**
  49. *
  50. */
  51. public SupportedGADShapesImpl() {
  52. super();
  53. }
  54. public SupportedGADShapesImpl(boolean ellipsoidPoint, boolean ellipsoidPointWithUncertaintyCircle, boolean ellipsoidPointWithUncertaintyEllipse,
  55. boolean polygon, boolean ellipsoidPointWithAltitude, boolean ellipsoidPointWithAltitudeAndUncertaintyElipsoid, boolean ellipsoidArc) {
  56. if (ellipsoidPoint)
  57. this.bitString.set(_INDEX_ELLIPSOID_POINT);
  58. if (ellipsoidPointWithUncertaintyCircle)
  59. this.bitString.set(_INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_CIRCLE);
  60. if (ellipsoidPointWithUncertaintyEllipse)
  61. this.bitString.set(_INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_ELLIPSE);
  62. if (polygon)
  63. this.bitString.set(_INDEX_POLYGON);
  64. if (ellipsoidPointWithAltitude)
  65. this.bitString.set(_INDEX_ELLIPSOID_POINT_WITH_ALTITUDE);
  66. if (ellipsoidPointWithAltitudeAndUncertaintyElipsoid)
  67. this.bitString.set(_INDEX_ELLIPSOID_WITH_ALTITUDE_AND_UNCERTAINTY_ELIPSOID);
  68. if (ellipsoidArc)
  69. this.bitString.set(_INDEX_ELLIPSOID_ARC);
  70. }
  71. /*
  72. * (non-Javadoc)
  73. *
  74. * @see
  75. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
  76. */
  77. @Override
  78. public int getTag() throws MAPException {
  79. return Tag.STRING_BIT;
  80. }
  81. /*
  82. * (non-Javadoc)
  83. *
  84. * @see
  85. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass
  86. * ()
  87. */
  88. @Override
  89. public int getTagClass() {
  90. return Tag.CLASS_UNIVERSAL;
  91. }
  92. /*
  93. * (non-Javadoc)
  94. *
  95. * @see
  96. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive
  97. * ()
  98. */
  99. @Override
  100. public boolean getIsPrimitive() {
  101. return true;
  102. }
  103. /*
  104. * (non-Javadoc)
  105. *
  106. * @see
  107. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll
  108. * (org.mobicents.protocols.asn.AsnInputStream)
  109. */
  110. @Override
  111. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  112. try {
  113. int length = ansIS.readLength();
  114. this._decode(ansIS, length);
  115. } catch (IOException e) {
  116. throw new MAPParsingComponentException("IOException when decoding MWStatus: " + e.getMessage(), e,
  117. MAPParsingComponentExceptionReason.MistypedParameter);
  118. } catch (AsnException e) {
  119. throw new MAPParsingComponentException("AsnException when decoding MWStatus: " + e.getMessage(), e,
  120. MAPParsingComponentExceptionReason.MistypedParameter);
  121. }
  122. }
  123. /*
  124. * (non-Javadoc)
  125. *
  126. * @see
  127. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData
  128. * (org.mobicents.protocols.asn.AsnInputStream, int)
  129. */
  130. @Override
  131. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  132. try {
  133. this._decode(ansIS, length);
  134. } catch (IOException e) {
  135. throw new MAPParsingComponentException("IOException when decoding MWStatus: " + e.getMessage(), e,
  136. MAPParsingComponentExceptionReason.MistypedParameter);
  137. } catch (AsnException e) {
  138. throw new MAPParsingComponentException("AsnException when decoding MWStatus: " + e.getMessage(), e,
  139. MAPParsingComponentExceptionReason.MistypedParameter);
  140. }
  141. }
  142. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  143. if (length == 0 || length > 7)
  144. throw new MAPParsingComponentException("Error decoding SupportedGADShapes: the SupportedGADShapes field must contain from 7 octets. Contains: "
  145. + length, MAPParsingComponentExceptionReason.MistypedParameter);
  146. this.bitString = ansIS.readBitStringData(length);
  147. }
  148. /*
  149. * (non-Javadoc)
  150. *
  151. * @see
  152. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
  153. * (org.mobicents.protocols.asn.AsnOutputStream)
  154. */
  155. @Override
  156. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  157. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.STRING_BIT);
  158. }
  159. /*
  160. * (non-Javadoc)
  161. *
  162. * @see
  163. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll
  164. * (org.mobicents.protocols.asn.AsnOutputStream, int, int)
  165. */
  166. @Override
  167. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  168. try {
  169. asnOs.writeTag(tagClass, true, tag);
  170. int pos = asnOs.StartContentDefiniteLength();
  171. this.encodeData(asnOs);
  172. asnOs.FinalizeContent(pos);
  173. } catch (AsnException e) {
  174. throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
  175. }
  176. }
  177. /*
  178. * (non-Javadoc)
  179. *
  180. * @see
  181. * org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData
  182. * (org.mobicents.protocols.asn.AsnOutputStream)
  183. */
  184. @Override
  185. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  186. try {
  187. asnOs.writeBitStringData(this.bitString);
  188. } catch (IOException e) {
  189. throw new MAPException("IOException when encoding MWStatus: " + e.getMessage(), e);
  190. } catch (AsnException e) {
  191. throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
  192. }
  193. }
  194. /*
  195. * (non-Javadoc)
  196. *
  197. * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
  198. * getEllipsoidPoint()
  199. */
  200. @Override
  201. public boolean getEllipsoidPoint() {
  202. return this.bitString.get(_INDEX_ELLIPSOID_POINT);
  203. }
  204. /*
  205. * (non-Javadoc)
  206. *
  207. * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
  208. * getEllipsoidPointWithUncertaintyCircle()
  209. */
  210. @Override
  211. public boolean getEllipsoidPointWithUncertaintyCircle() {
  212. return this.bitString.get(_INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_CIRCLE);
  213. }
  214. /*
  215. * (non-Javadoc)
  216. *
  217. * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
  218. * getEllipsoidPointWithUncertaintyEllipse()
  219. */
  220. @Override
  221. public boolean getEllipsoidPointWithUncertaintyEllipse() {
  222. return this.bitString.get(_INDEX_ELLIPSOID_POINT_WITH_UNCERTAINTY_ELLIPSE);
  223. }
  224. /*
  225. * (non-Javadoc)
  226. *
  227. * @see
  228. * org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#getPolygon
  229. * ()
  230. */
  231. @Override
  232. public boolean getPolygon() {
  233. return this.bitString.get(_INDEX_POLYGON);
  234. }
  235. /*
  236. * (non-Javadoc)
  237. *
  238. * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
  239. * getEllipsoidPointWithAltitude()
  240. */
  241. @Override
  242. public boolean getEllipsoidPointWithAltitude() {
  243. return this.bitString.get(_INDEX_ELLIPSOID_POINT_WITH_ALTITUDE);
  244. }
  245. /*
  246. * (non-Javadoc)
  247. *
  248. * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
  249. * getEllipsoidPointWithAltitudeAndUncertaintyElipsoid()
  250. */
  251. @Override
  252. public boolean getEllipsoidPointWithAltitudeAndUncertaintyElipsoid() {
  253. return this.bitString.get(_INDEX_ELLIPSOID_WITH_ALTITUDE_AND_UNCERTAINTY_ELIPSOID);
  254. }
  255. /*
  256. * (non-Javadoc)
  257. *
  258. * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedGADShapes#
  259. * getEllipsoidArc()
  260. */
  261. @Override
  262. public boolean getEllipsoidArc() {
  263. return this.bitString.get(_INDEX_ELLIPSOID_ARC);
  264. }
  265. @Override
  266. public int hashCode() {
  267. final int prime = 31;
  268. int result = 1;
  269. result = prime * result + ((bitString == null) ? 0 : bitString.hashCode());
  270. return result;
  271. }
  272. @Override
  273. public boolean equals(Object obj) {
  274. if (this == obj)
  275. return true;
  276. if (obj == null)
  277. return false;
  278. if (getClass() != obj.getClass())
  279. return false;
  280. SupportedGADShapesImpl other = (SupportedGADShapesImpl) obj;
  281. if (bitString == null) {
  282. if (other.bitString != null)
  283. return false;
  284. } else if (!bitString.equals(other.bitString))
  285. return false;
  286. return true;
  287. }
  288. }