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

http://mobicents.googlecode.com/ · Java · 104 lines · 55 code · 20 blank · 29 comment · 2 complexity · c72cdda778bb99eb8b468f4afd0cb52f 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.nio.ByteBuffer;
  24. import org.mobicents.protocols.ss7.m3ua.parameter.DeregistrationResult;
  25. import org.mobicents.protocols.ss7.m3ua.parameter.DeregistrationStatus;
  26. import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
  27. import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
  28. /**
  29. *
  30. * @author amit bhayani
  31. *
  32. */
  33. public class DeregistrationResultImpl extends ParameterImpl implements
  34. DeregistrationResult {
  35. private RoutingContext rc;
  36. private DeregistrationStatus status;
  37. private byte[] value;
  38. private ByteBuffer buffer = ByteBuffer.allocate(16);
  39. public DeregistrationResultImpl(RoutingContext rc,
  40. DeregistrationStatus status) {
  41. this.tag = Parameter.Deregistration_Result;
  42. this.rc = rc;
  43. this.status = status;
  44. this.encode();
  45. }
  46. public DeregistrationResultImpl(byte[] data) {
  47. this.tag = Parameter.Deregistration_Result;
  48. int pos = 0;
  49. while (pos < data.length) {
  50. short tag = (short) ((data[pos] & 0xff) << 8 | (data[pos + 1] & 0xff));
  51. short len = (short) ((data[pos + 2] & 0xff) << 8 | (data[pos + 3] & 0xff));
  52. byte[] value = new byte[len - 4];
  53. System.arraycopy(data, pos + 4, value, 0, value.length);
  54. pos += len;
  55. // parameters.put(tag, factory.createParameter(tag, value));
  56. switch (tag) {
  57. case ParameterImpl.Routing_Context:
  58. this.rc = new RoutingContextImpl(value);
  59. break;
  60. case ParameterImpl.Deregistration_Status:
  61. this.status = new DeregistrationStatusImpl(value);
  62. break;
  63. }
  64. // The Parameter Length does not include any padding octets. We have
  65. // to consider padding here
  66. pos += (pos % 4);
  67. }// end of while
  68. }
  69. private void encode() {
  70. ((RoutingContextImpl) this.rc).write(buffer);
  71. ((DeregistrationStatusImpl) this.status).write(buffer);
  72. value = buffer.array();
  73. }
  74. @Override
  75. protected byte[] getValue() {
  76. return this.value;
  77. }
  78. public DeregistrationStatus getDeregistrationStatus() {
  79. return this.status;
  80. }
  81. public RoutingContext getRoutingContext() {
  82. return this.rc;
  83. }
  84. }