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

http://mobicents.googlecode.com/ · Java · 160 lines · 95 code · 26 blank · 39 comment · 0 complexity · 7692c504a295de6945ca4da7224a5939 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 org.mobicents.protocols.ss7.m3ua.parameter.ProtocolData;
  24. import org.mobicents.protocols.ss7.mtp.Mtp3TransferPrimitive;
  25. /**
  26. * Implements Protocol Data parameter.
  27. *
  28. * @author amit bhayani
  29. * @author kulikov
  30. */
  31. public class ProtocolDataImpl extends ParameterImpl implements ProtocolData {
  32. private int opc;
  33. private int dpc;
  34. private int si;
  35. private int ni;
  36. private int mp;
  37. private int sls;
  38. private byte[] data;
  39. protected ProtocolDataImpl() {
  40. this.tag = ParameterImpl.Protocol_Data;
  41. }
  42. protected ProtocolDataImpl(Mtp3TransferPrimitive mtp3TransferPrimitive) {
  43. this();
  44. this.opc = mtp3TransferPrimitive.getOpc();
  45. this.dpc = mtp3TransferPrimitive.getDpc();
  46. this.si = mtp3TransferPrimitive.getSi();
  47. this.ni = mtp3TransferPrimitive.getNi();
  48. this.mp = mtp3TransferPrimitive.getMp();
  49. this.sls = mtp3TransferPrimitive.getSls();
  50. this.data = mtp3TransferPrimitive.getData();
  51. }
  52. protected ProtocolDataImpl(int opc, int dpc, int si, int ni, int mp, int sls, byte[] data) {
  53. this();
  54. this.opc = opc;
  55. this.dpc = dpc;
  56. this.si = si;
  57. this.ni = ni;
  58. this.mp = mp;
  59. this.sls = sls;
  60. this.data = data;
  61. encode();
  62. }
  63. /**
  64. * Creates new parameter with specified value.
  65. *
  66. * @param valueData
  67. * the value of this parameter
  68. */
  69. protected ProtocolDataImpl(byte[] valueData) {
  70. this();
  71. this.opc = ((valueData[0] & 0xff) << 24) | ((valueData[1] & 0xff) << 16) | ((valueData[2] & 0xff) << 8)
  72. | (valueData[3] & 0xff);
  73. this.dpc = ((valueData[4] & 0xff) << 24) | ((valueData[5] & 0xff) << 16) | ((valueData[6] & 0xff) << 8)
  74. | (valueData[7] & 0xff);
  75. this.si = valueData[8] & 0xff;
  76. this.ni = valueData[9] & 0xff;
  77. this.mp = valueData[10] & 0xff;
  78. this.sls = valueData[11] & 0xff;
  79. this.data = new byte[valueData.length - 12];
  80. System.arraycopy(valueData, 12, data, 0, valueData.length - 12);
  81. }
  82. private byte[] encode() {
  83. // create byte array taking into account data, point codes and
  84. // indicators;
  85. byte[] value = new byte[data.length + 12];
  86. // insert data
  87. System.arraycopy(data, 0, value, 12, data.length);
  88. // encode originated point codes
  89. value[0] = (byte) (opc >> 24);
  90. value[1] = (byte) (opc >> 16);
  91. value[2] = (byte) (opc >> 8);
  92. value[3] = (byte) (opc);
  93. // encode destination point code
  94. value[4] = (byte) (dpc >> 24);
  95. value[5] = (byte) (dpc >> 16);
  96. value[6] = (byte) (dpc >> 8);
  97. value[7] = (byte) (dpc);
  98. // encode indicators
  99. value[8] = (byte) (si);
  100. value[9] = (byte) (ni);
  101. value[10] = (byte) (mp);
  102. value[11] = (byte) (sls);
  103. return value;
  104. }
  105. public int getOpc() {
  106. return opc;
  107. }
  108. public int getDpc() {
  109. return dpc;
  110. }
  111. public int getSI() {
  112. return si;
  113. }
  114. public int getNI() {
  115. return ni;
  116. }
  117. public int getMP() {
  118. return mp;
  119. }
  120. public int getSLS() {
  121. return sls;
  122. }
  123. public byte[] getData() {
  124. return data;
  125. }
  126. @Override
  127. protected byte[] getValue() {
  128. return this.encode();
  129. }
  130. @Override
  131. public String toString() {
  132. return String.format("Protocol opc=%d dpc=%d si=%d ni=%d sls=%d", opc, dpc, si, ni, sls);
  133. }
  134. }