PageRenderTime 68ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 121 lines | 70 code | 19 blank | 32 comment | 0 complexity | 107c4640715dfc259c2398eb4f245add 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.DestinationPointCode;
  27. import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
  28. /**
  29. *
  30. * @author amit bhayani
  31. *
  32. */
  33. public class DestinationPointCodeImpl extends ParameterImpl implements DestinationPointCode, XMLSerializable {
  34. private static final String DPC = "dpc";
  35. private static final String MASK = "mask";
  36. private int destPC = 0;
  37. private short mask = 0;
  38. private byte[] value;
  39. public DestinationPointCodeImpl(){
  40. this.tag = Parameter.Destination_Point_Code;
  41. }
  42. protected DestinationPointCodeImpl(byte[] value) {
  43. this.tag = Parameter.Destination_Point_Code;
  44. this.value = value;
  45. this.mask = value[0];
  46. destPC = 0;
  47. destPC |= value[1] & 0xFF;
  48. destPC <<= 8;
  49. destPC |= value[2] & 0xFF;
  50. destPC <<= 8;
  51. destPC |= value[3] & 0xFF;
  52. }
  53. protected DestinationPointCodeImpl(int pc, short mask) {
  54. this.tag = Parameter.Destination_Point_Code;
  55. this.destPC = pc;
  56. this.mask = mask;
  57. encode();
  58. }
  59. private void encode() {
  60. // create byte array taking into account data, point codes and
  61. // indicators;
  62. this.value = new byte[4];
  63. // encode point code with mask
  64. value[0] = (byte) this.mask;// Mask
  65. value[1] = (byte) (destPC >> 16);
  66. value[2] = (byte) (destPC >> 8);
  67. value[3] = (byte) (destPC);
  68. }
  69. public int getPointCode() {
  70. return destPC;
  71. }
  72. @Override
  73. protected byte[] getValue() {
  74. return value;
  75. }
  76. public short getMask() {
  77. return this.mask;
  78. }
  79. @Override
  80. public String toString() {
  81. return String.format("DestinationPointCode dpc=%d mask=%d", destPC, mask);
  82. }
  83. /**
  84. * XML Serialization/Deserialization
  85. */
  86. protected static final XMLFormat<DestinationPointCodeImpl> RC_XML = new XMLFormat<DestinationPointCodeImpl>(
  87. DestinationPointCodeImpl.class) {
  88. @Override
  89. public void read(javolution.xml.XMLFormat.InputElement xml, DestinationPointCodeImpl dpc)
  90. throws XMLStreamException {
  91. dpc.destPC = xml.getAttribute(DPC).toInt();
  92. dpc.mask = (short) xml.getAttribute(MASK).toInt();
  93. dpc.encode();
  94. }
  95. @Override
  96. public void write(DestinationPointCodeImpl dpc, javolution.xml.XMLFormat.OutputElement xml)
  97. throws XMLStreamException {
  98. xml.setAttribute(DPC, dpc.destPC);
  99. xml.setAttribute(MASK, dpc.mask);
  100. }
  101. };
  102. }