/protocols/ss7/m3ua/impl/src/main/java/org/mobicents/protocols/ss7/m3ua/impl/parameter/AffectedPointCodeImpl.java

http://mobicents.googlecode.com/ · Java · 109 lines · 61 code · 19 blank · 29 comment · 2 complexity · 188f36742974d0ad376c841037cbfacd 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.m3ua.impl.parameter;
  23. import java.util.Arrays;
  24. import org.mobicents.protocols.ss7.m3ua.parameter.AffectedPointCode;
  25. import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
  26. /**
  27. *
  28. * @author amit bhayani
  29. *
  30. */
  31. public class AffectedPointCodeImpl extends ParameterImpl implements
  32. AffectedPointCode {
  33. private byte[] value;
  34. private int[] pointCodes;
  35. private short[] masks;
  36. protected AffectedPointCodeImpl(byte[] value) {
  37. this.tag = Parameter.Affected_Point_Code;
  38. int count = 0;
  39. int arrSize = 0;
  40. pointCodes = new int[(value.length / 4)];
  41. masks = new short[(value.length / 4)];
  42. while (count < value.length) {
  43. masks[arrSize] = value[count++];
  44. pointCodes[arrSize] = 0;
  45. pointCodes[arrSize] |= value[count++] & 0xFF;
  46. pointCodes[arrSize] <<= 8;
  47. pointCodes[arrSize] |= value[count++] & 0xFF;
  48. pointCodes[arrSize] <<= 8;
  49. pointCodes[arrSize++] |= value[count++] & 0xFF;
  50. }
  51. this.value = value;
  52. }
  53. protected AffectedPointCodeImpl(int[] pointCodes, short[] masks) {
  54. this.tag = Parameter.Affected_Point_Code;
  55. this.pointCodes = pointCodes;
  56. this.masks = masks;
  57. encode();
  58. }
  59. private void encode() {
  60. // create byte array taking into account data, point codes and
  61. // indicators;
  62. this.value = new byte[(pointCodes.length * 4)];
  63. int count = 0;
  64. int arrSize = 0;
  65. // encode routing context
  66. while (count < value.length) {
  67. value[count++] = (byte) (masks[arrSize]);
  68. value[count++] = (byte) (pointCodes[arrSize] >>> 16);
  69. value[count++] = (byte) (pointCodes[arrSize] >>> 8);
  70. value[count++] = (byte) (pointCodes[arrSize++]);
  71. }
  72. }
  73. @Override
  74. protected byte[] getValue() {
  75. return this.value;
  76. }
  77. public short[] getMasks() {
  78. return this.masks;
  79. }
  80. public int[] getPointCodes() {
  81. return this.pointCodes;
  82. }
  83. @Override
  84. public String toString() {
  85. return String
  86. .format("AffectedPointCode pointCode=%s mask=%s",
  87. Arrays.toString(this.pointCodes), Arrays
  88. .toString(this.masks));
  89. }
  90. }