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

http://mobicents.googlecode.com/ · Java · 132 lines · 80 code · 28 blank · 24 comment · 8 complexity · 6c50816b0d705e626b56b5ecc52ab456 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 javolution.text.TextBuilder;
  25. import org.mobicents.protocols.ss7.m3ua.parameter.LocalRKIdentifier;
  26. import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
  27. import org.mobicents.protocols.ss7.m3ua.parameter.RegistrationResult;
  28. import org.mobicents.protocols.ss7.m3ua.parameter.RegistrationStatus;
  29. import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
  30. public class RegistrationResultImpl extends ParameterImpl implements RegistrationResult {
  31. private LocalRKIdentifier localRKId;
  32. private RegistrationStatus status;
  33. private RoutingContext rc;
  34. private ByteBuffer buffer = ByteBuffer.allocate(24);
  35. private byte[] value;
  36. public RegistrationResultImpl(byte[] data) {
  37. this.tag = Parameter.Registration_Result;
  38. int pos = 0;
  39. while (pos < data.length) {
  40. short tag = (short) ((data[pos] & 0xff) << 8 | (data[pos + 1] & 0xff));
  41. short len = (short) ((data[pos + 2] & 0xff) << 8 | (data[pos + 3] & 0xff));
  42. byte[] value = new byte[len - 4];
  43. System.arraycopy(data, pos + 4, value, 0, value.length);
  44. pos += len;
  45. // parameters.put(tag, factory.createParameter(tag, value));
  46. switch (tag) {
  47. case ParameterImpl.Local_Routing_Key_Identifier:
  48. this.localRKId = new LocalRKIdentifierImpl(value);
  49. break;
  50. case ParameterImpl.Routing_Context:
  51. this.rc = new RoutingContextImpl(value);
  52. break;
  53. case ParameterImpl.Registration_Status:
  54. this.status = new RegistrationStatusImpl(value);
  55. break;
  56. }
  57. // The Parameter Length does not include any padding octets. We have
  58. // to consider padding here
  59. pos += (pos % 4);
  60. }// end of while
  61. }
  62. public RegistrationResultImpl(LocalRKIdentifier localRKId, RegistrationStatus status, RoutingContext rc) {
  63. this.tag = Parameter.Registration_Result;
  64. this.localRKId = localRKId;
  65. this.status = status;
  66. this.rc = rc;
  67. this.encode();
  68. }
  69. private void encode() {
  70. ((LocalRKIdentifierImpl) this.localRKId).write(buffer);
  71. ((RoutingContextImpl) rc).write(buffer);
  72. ((RegistrationStatusImpl) this.status).write(buffer);
  73. value = buffer.array();
  74. }
  75. @Override
  76. protected byte[] getValue() {
  77. return this.value;
  78. }
  79. public LocalRKIdentifier getLocalRKIdentifier() {
  80. return this.localRKId;
  81. }
  82. public RegistrationStatus getRegistrationStatus() {
  83. return this.status;
  84. }
  85. public RoutingContext getRoutingContext() {
  86. return this.rc;
  87. }
  88. @Override
  89. public String toString() {
  90. TextBuilder tb = TextBuilder.newInstance();
  91. tb.append("RegistrationResult(");
  92. if (localRKId != null) {
  93. tb.append(localRKId.toString());
  94. }
  95. if (status != null) {
  96. tb.append(status.toString());
  97. }
  98. if (rc != null) {
  99. tb.append(rc.toString());
  100. }
  101. tb.append(")");
  102. return tb.toString();
  103. }
  104. }