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

http://mobicents.googlecode.com/ · Java · 95 lines · 48 code · 18 blank · 29 comment · 0 complexity · d767561d36caf5c8e5c144c3e3053e72 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 org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
  24. import org.mobicents.protocols.ss7.m3ua.parameter.UserCause;
  25. /**
  26. *
  27. * @author amit bhayani
  28. *
  29. */
  30. public class UserCauseImpl extends ParameterImpl implements UserCause {
  31. private int user = 0;
  32. private int cause = 0;
  33. private byte[] value;
  34. protected UserCauseImpl(byte[] value) {
  35. this.tag = Parameter.User_Cause;
  36. this.user = 0;
  37. this.user |= value[0] & 0xFF;
  38. this.user <<= 8;
  39. this.user |= value[1] & 0xFF;
  40. this.cause = 0;
  41. this.cause |= value[2] & 0xFF;
  42. this.cause <<= 8;
  43. this.cause |= value[3] & 0xFF;
  44. this.value = value;
  45. }
  46. protected UserCauseImpl(int user, int cause) {
  47. this.tag = Parameter.User_Cause;
  48. this.user = user;
  49. this.cause = cause;
  50. encode();
  51. }
  52. private void encode() {
  53. // create byte array taking into account data, point codes and
  54. // indicators;
  55. this.value = new byte[4];
  56. // encode routing context
  57. value[0] = (byte) (this.user >> 8);
  58. value[1] = (byte) (this.user);
  59. value[2] = (byte) (this.cause >> 8);
  60. value[3] = (byte) (this.cause);
  61. }
  62. @Override
  63. protected byte[] getValue() {
  64. return value;
  65. }
  66. public int getCause() {
  67. return this.cause;
  68. }
  69. public int getUser() {
  70. return this.user;
  71. }
  72. @Override
  73. public String toString() {
  74. return String.format("UserCause cause = %d user = %d", this.cause,
  75. this.user);
  76. }
  77. }