PageRenderTime 56ms CodeModel.GetById 45ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 112 lines | 63 code | 17 blank | 32 comment | 0 complexity | f873d4fae829cad2236080fbcc125381 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  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 javolution.xml.XMLFormat;
  24. import javolution.xml.XMLSerializable;
  25. import javolution.xml.stream.XMLStreamException;
  26. import org.mobicents.protocols.ss7.m3ua.parameter.LocalRKIdentifier;
  27. import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
  28. /**
  29. *
  30. * @author amit bhayani
  31. *
  32. */
  33. public class LocalRKIdentifierImpl extends ParameterImpl implements LocalRKIdentifier, XMLSerializable {
  34. private static final String ID = "id";
  35. private byte[] value;
  36. private long id;
  37. public LocalRKIdentifierImpl(){
  38. this.tag = Parameter.Local_Routing_Key_Identifier;
  39. }
  40. protected LocalRKIdentifierImpl(byte[] data) {
  41. this.tag = Parameter.Local_Routing_Key_Identifier;
  42. this.value = data;
  43. this.id = 0;
  44. this.id |= data[0] & 0xFF;
  45. this.id <<= 8;
  46. this.id |= data[1] & 0xFF;
  47. this.id <<= 8;
  48. this.id |= data[2] & 0xFF;
  49. this.id <<= 8;
  50. this.id |= data[3] & 0xFF;
  51. }
  52. protected LocalRKIdentifierImpl(long id) {
  53. this.tag = Parameter.Local_Routing_Key_Identifier;
  54. this.id = id;
  55. this.encode();
  56. }
  57. private void encode() {
  58. // create byte array taking into account data, point codes and
  59. // indicators;
  60. this.value = new byte[4];
  61. // encode routing context
  62. value[0] = (byte) (this.id >> 24);
  63. value[1] = (byte) (this.id >> 16);
  64. value[2] = (byte) (this.id >> 8);
  65. value[3] = (byte) (this.id);
  66. }
  67. @Override
  68. protected byte[] getValue() {
  69. return this.value;
  70. }
  71. public long getId() {
  72. return this.id;
  73. }
  74. @Override
  75. public String toString() {
  76. return String.format("LocalRKIdentifier id=%d", id);
  77. }
  78. /**
  79. * XML Serialization/Deserialization
  80. */
  81. protected static final XMLFormat<LocalRKIdentifierImpl> RC_XML = new XMLFormat<LocalRKIdentifierImpl>(
  82. LocalRKIdentifierImpl.class) {
  83. @Override
  84. public void read(javolution.xml.XMLFormat.InputElement xml, LocalRKIdentifierImpl localRkId)
  85. throws XMLStreamException {
  86. localRkId.id = xml.getAttribute(ID).toLong();
  87. localRkId.encode();
  88. }
  89. @Override
  90. public void write(LocalRKIdentifierImpl localRkId, javolution.xml.XMLFormat.OutputElement xml)
  91. throws XMLStreamException {
  92. xml.setAttribute(ID, localRkId.id);
  93. }
  94. };
  95. }