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

http://mobicents.googlecode.com/ · Java · 103 lines · 58 code · 17 blank · 28 comment · 0 complexity · 1b7ba26d09f061e9587d9eabe67df961 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 javolution.xml.XMLFormat;
  24. import javolution.xml.XMLSerializable;
  25. import javolution.xml.stream.XMLStreamException;
  26. import org.mobicents.protocols.ss7.m3ua.parameter.NetworkAppearance;
  27. import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
  28. /**
  29. * @author amit bhayani
  30. * @author kulikov
  31. */
  32. public class NetworkAppearanceImpl extends ParameterImpl implements NetworkAppearance, XMLSerializable {
  33. private static final String VALUE = "value";
  34. private static final long UNSIGNED_INT_MAX_VALUE = 0xFFFFFFFF;
  35. private long value;
  36. public NetworkAppearanceImpl(){
  37. this.tag = Parameter.Network_Appearance;
  38. }
  39. protected NetworkAppearanceImpl(long value) {
  40. this.value = value;
  41. this.tag = Parameter.Network_Appearance;
  42. }
  43. protected NetworkAppearanceImpl(byte[] data) {
  44. this.value = 0;
  45. this.value |= data[0] & 0xFF;
  46. this.value <<= 8;
  47. this.value |= data[1] & 0xFF;
  48. this.value <<= 8;
  49. this.value |= data[2] & 0xFF;
  50. this.value <<= 8;
  51. this.value |= data[3] & 0xFF;
  52. this.tag = Parameter.Network_Appearance;
  53. }
  54. public long getNetApp() {
  55. return value;
  56. }
  57. @Override
  58. protected byte[] getValue() {
  59. byte[] data = new byte[4];
  60. data[0] = (byte) (value >>> 24);
  61. data[1] = (byte) (value >>> 16);
  62. data[2] = (byte) (value >>> 8);
  63. data[3] = (byte) (value);
  64. return data;
  65. }
  66. @Override
  67. public String toString() {
  68. return String.format("NetworkAppearance value=%d", value);
  69. }
  70. /**
  71. * XML Serialization/Deserialization
  72. */
  73. protected static final XMLFormat<NetworkAppearanceImpl> RC_XML = new XMLFormat<NetworkAppearanceImpl>(
  74. NetworkAppearanceImpl.class) {
  75. @Override
  76. public void read(javolution.xml.XMLFormat.InputElement xml, NetworkAppearanceImpl localRkId)
  77. throws XMLStreamException {
  78. localRkId.value = xml.getAttribute(VALUE).toLong();
  79. }
  80. @Override
  81. public void write(NetworkAppearanceImpl localRkId, javolution.xml.XMLFormat.OutputElement xml)
  82. throws XMLStreamException {
  83. xml.setAttribute(VALUE, localRkId.value);
  84. }
  85. };
  86. }