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

http://mobicents.googlecode.com/ · Java · 229 lines · 139 code · 25 blank · 65 comment · 20 complexity · d3db1386b70d46d5e840146a6556b0dd 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.SupportedLCSCapabilitySets;
  33. import org.mobicents.protocols.ss7.map.primitives.MAPAsnPrimitive;
  34. /**
  35. * @author amit bhayani
  36. *
  37. */
  38. public class SupportedLCSCapabilitySetsImpl implements SupportedLCSCapabilitySets, MAPAsnPrimitive {
  39. private static final int _INDEX_LCS_CAPABILITY_SET1 = 0;
  40. private static final int _INDEX_LCS_CAPABILITY_SET2 = 1;
  41. private static final int _INDEX_LCS_CAPABILITY_SET3 = 2;
  42. private static final int _INDEX_LCS_CAPABILITY_SET4 = 3;
  43. //TODO : Is this correct?
  44. private BitSetStrictLength bitString = new BitSetStrictLength(4);
  45. /**
  46. *
  47. */
  48. public SupportedLCSCapabilitySetsImpl() {
  49. super();
  50. }
  51. public SupportedLCSCapabilitySetsImpl(Boolean lcsCapabilitySet1, Boolean lcsCapabilitySet2, Boolean lcsCapabilitySet3, Boolean lcsCapabilitySet4) {
  52. if (lcsCapabilitySet1)
  53. this.bitString.set(_INDEX_LCS_CAPABILITY_SET1);
  54. if (lcsCapabilitySet2)
  55. this.bitString.set(_INDEX_LCS_CAPABILITY_SET2);
  56. if (lcsCapabilitySet3)
  57. this.bitString.set(_INDEX_LCS_CAPABILITY_SET3);
  58. if (lcsCapabilitySet4)
  59. this.bitString.set(_INDEX_LCS_CAPABILITY_SET4);
  60. }
  61. /* (non-Javadoc)
  62. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTag()
  63. */
  64. @Override
  65. public int getTag() throws MAPException {
  66. return Tag.STRING_BIT;
  67. }
  68. /* (non-Javadoc)
  69. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getTagClass()
  70. */
  71. @Override
  72. public int getTagClass() {
  73. return Tag.CLASS_UNIVERSAL;
  74. }
  75. /* (non-Javadoc)
  76. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#getIsPrimitive()
  77. */
  78. @Override
  79. public boolean getIsPrimitive() {
  80. return true;
  81. }
  82. /* (non-Javadoc)
  83. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeAll(org.mobicents.protocols.asn.AsnInputStream)
  84. */
  85. @Override
  86. public void decodeAll(AsnInputStream ansIS) throws MAPParsingComponentException {
  87. try {
  88. int length = ansIS.readLength();
  89. this._decode(ansIS, length);
  90. } catch (IOException e) {
  91. throw new MAPParsingComponentException("IOException when decoding MWStatus: " + e.getMessage(), e,
  92. MAPParsingComponentExceptionReason.MistypedParameter);
  93. } catch (AsnException e) {
  94. throw new MAPParsingComponentException("AsnException when decoding MWStatus: " + e.getMessage(), e,
  95. MAPParsingComponentExceptionReason.MistypedParameter);
  96. }
  97. }
  98. /* (non-Javadoc)
  99. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#decodeData(org.mobicents.protocols.asn.AsnInputStream, int)
  100. */
  101. @Override
  102. public void decodeData(AsnInputStream ansIS, int length) throws MAPParsingComponentException {
  103. try {
  104. this._decode(ansIS, length);
  105. } catch (IOException e) {
  106. throw new MAPParsingComponentException("IOException when decoding MWStatus: " + e.getMessage(), e,
  107. MAPParsingComponentExceptionReason.MistypedParameter);
  108. } catch (AsnException e) {
  109. throw new MAPParsingComponentException("AsnException when decoding MWStatus: " + e.getMessage(), e,
  110. MAPParsingComponentExceptionReason.MistypedParameter);
  111. }
  112. }
  113. private void _decode(AsnInputStream ansIS, int length) throws MAPParsingComponentException, IOException, AsnException {
  114. if (length == 0 || length > 4)
  115. throw new MAPParsingComponentException("Error decoding SupportedLCSCapabilitySets: the SupportedLCSCapabilitySets field must contain from 2 or 4 octets. Contains: " + length,
  116. MAPParsingComponentExceptionReason.MistypedParameter);
  117. this.bitString = ansIS.readBitStringData(length);
  118. }
  119. /* (non-Javadoc)
  120. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll(org.mobicents.protocols.asn.AsnOutputStream)
  121. */
  122. @Override
  123. public void encodeAll(AsnOutputStream asnOs) throws MAPException {
  124. this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.STRING_BIT);
  125. }
  126. /* (non-Javadoc)
  127. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeAll(org.mobicents.protocols.asn.AsnOutputStream, int, int)
  128. */
  129. @Override
  130. public void encodeAll(AsnOutputStream asnOs, int tagClass, int tag) throws MAPException {
  131. try {
  132. asnOs.writeTag(tagClass, true, tag);
  133. int pos = asnOs.StartContentDefiniteLength();
  134. this.encodeData(asnOs);
  135. asnOs.FinalizeContent(pos);
  136. } catch (AsnException e) {
  137. throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
  138. }
  139. }
  140. /* (non-Javadoc)
  141. * @see org.mobicents.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData(org.mobicents.protocols.asn.AsnOutputStream)
  142. */
  143. @Override
  144. public void encodeData(AsnOutputStream asnOs) throws MAPException {
  145. try {
  146. asnOs.writeBitStringData(this.bitString);
  147. } catch (IOException e) {
  148. throw new MAPException("IOException when encoding MWStatus: " + e.getMessage(), e);
  149. } catch (AsnException e) {
  150. throw new MAPException("AsnException when encoding MWStatus: " + e.getMessage(), e);
  151. }
  152. }
  153. /* (non-Javadoc)
  154. * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedLCSCapabilitySets#getLcsCapabilitySet1()
  155. */
  156. @Override
  157. public boolean getLcsCapabilitySet1() {
  158. return this.bitString.get(_INDEX_LCS_CAPABILITY_SET1);
  159. }
  160. /* (non-Javadoc)
  161. * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedLCSCapabilitySets#getLcsCapabilitySet2()
  162. */
  163. @Override
  164. public boolean getLcsCapabilitySet2() {
  165. return this.bitString.get(_INDEX_LCS_CAPABILITY_SET2);
  166. }
  167. /* (non-Javadoc)
  168. * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedLCSCapabilitySets#getLcsCapabilitySet3()
  169. */
  170. @Override
  171. public boolean getLcsCapabilitySet3() {
  172. return this.bitString.get(_INDEX_LCS_CAPABILITY_SET3);
  173. }
  174. /* (non-Javadoc)
  175. * @see org.mobicents.protocols.ss7.map.api.service.lsm.SupportedLCSCapabilitySets#getLcsCapabilitySet4()
  176. */
  177. @Override
  178. public boolean getLcsCapabilitySet4() {
  179. return this.bitString.get(_INDEX_LCS_CAPABILITY_SET4);
  180. }
  181. @Override
  182. public int hashCode() {
  183. final int prime = 31;
  184. int result = 1;
  185. result = prime * result + ((bitString == null) ? 0 : bitString.hashCode());
  186. return result;
  187. }
  188. @Override
  189. public boolean equals(Object obj) {
  190. if (this == obj)
  191. return true;
  192. if (obj == null)
  193. return false;
  194. if (getClass() != obj.getClass())
  195. return false;
  196. SupportedLCSCapabilitySetsImpl other = (SupportedLCSCapabilitySetsImpl) obj;
  197. if (bitString == null) {
  198. if (other.bitString != null)
  199. return false;
  200. } else if (!bitString.equals(other.bitString))
  201. return false;
  202. return true;
  203. }
  204. }