PageRenderTime 35ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 135 lines | 79 code | 30 blank | 26 comment | 1 complexity | 1852460d0817c094280b5de125ece8b3 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 org.mobicents.protocols.ss7.m3ua.parameter.ErrorCode;
  24. import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
  25. /**
  26. *
  27. * @author amit bhayani
  28. *
  29. */
  30. public class ErrorCodeImpl extends ParameterImpl implements ErrorCode {
  31. private int code;
  32. public ErrorCodeImpl(int code) {
  33. this.code = code;
  34. this.tag = Parameter.Error_Code;
  35. }
  36. public ErrorCodeImpl(byte[] data) {
  37. this.code = 0;
  38. this.code |= data[0] & 0xFF;
  39. this.code <<= 8;
  40. this.code |= data[1] & 0xFF;
  41. this.code <<= 8;
  42. this.code |= data[2] & 0xFF;
  43. this.code <<= 8;
  44. this.code |= data[3] & 0xFF;
  45. this.tag = Parameter.Error_Code;
  46. }
  47. @Override
  48. protected byte[] getValue() {
  49. byte[] data = new byte[4];
  50. data[0] = (byte) (code >>> 24);
  51. data[1] = (byte) (code >>> 16);
  52. data[2] = (byte) (code >>> 8);
  53. data[3] = (byte) (code);
  54. return data;
  55. }
  56. public int getCode() {
  57. return this.code;
  58. }
  59. @Override
  60. public String toString() {
  61. return String.format("ErrorCode code=%d Error=%s", code, this.getErrorMessage(this.code));
  62. }
  63. private String getErrorMessage(int code) {
  64. switch (code) {
  65. case Invalid_Version:
  66. return "Invalid_Version";
  67. case Unsupported_Message_Class:
  68. return "Unsupported_Message_Class";
  69. case Unsupported_Message_Type:
  70. return "Unsupported_Message_Type";
  71. case Unsupported_Traffic_Mode_Type:
  72. return "Unsupported_Traffic_Mode_Type";
  73. case Unexpected_Message:
  74. return "Unexpected_Message";
  75. case Protocol_Error:
  76. return "Protocol_Error";
  77. case Invalid_Stream_Identifier:
  78. return "Invalid_Stream_Identifier";
  79. case Refused_Management_Blocking:
  80. return "Refused_Management_Blocking";
  81. case ASP_Identifier_Required:
  82. return "ASP_Identifier_Required";
  83. case Invalid_ASP_Identifier:
  84. return "Invalid_ASP_Identifier";
  85. case Invalid_Parameter_Value:
  86. return "Invalid_Parameter_Value";
  87. case Parameter_Field_Error:
  88. return "Parameter_Field_Error";
  89. case Unexpected_Parameter:
  90. return "Unexpected_Parameter";
  91. case Destination_Status_Unknown:
  92. return "Destination_Status_Unknown";
  93. case Invalid_Network_Appearance:
  94. return "Invalid_Network_Appearance";
  95. case Missing_Parameter:
  96. return "Missing_Parameter";
  97. case Invalid_Routing_Context:
  98. return "Invalid_Routing_Context";
  99. case No_Configured_AS_for_ASP:
  100. return "No_Configured_AS_for_ASP";
  101. default:
  102. return Integer.toString(code);
  103. }
  104. }
  105. }