PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms 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
  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
 23package org.mobicents.protocols.ss7.m3ua.impl.parameter;
 24
 25import org.mobicents.protocols.ss7.m3ua.parameter.ErrorCode;
 26import org.mobicents.protocols.ss7.m3ua.parameter.Parameter;
 27
 28/**
 29 * 
 30 * @author amit bhayani
 31 * 
 32 */
 33public class ErrorCodeImpl extends ParameterImpl implements ErrorCode {
 34
 35	private int code;
 36
 37	public ErrorCodeImpl(int code) {
 38		this.code = code;
 39		this.tag = Parameter.Error_Code;
 40	}
 41
 42	public ErrorCodeImpl(byte[] data) {
 43		this.code = 0;
 44		this.code |= data[0] & 0xFF;
 45		this.code <<= 8;
 46		this.code |= data[1] & 0xFF;
 47		this.code <<= 8;
 48		this.code |= data[2] & 0xFF;
 49		this.code <<= 8;
 50		this.code |= data[3] & 0xFF;
 51		this.tag = Parameter.Error_Code;
 52	}
 53
 54	@Override
 55	protected byte[] getValue() {
 56		byte[] data = new byte[4];
 57		data[0] = (byte) (code >>> 24);
 58		data[1] = (byte) (code >>> 16);
 59		data[2] = (byte) (code >>> 8);
 60		data[3] = (byte) (code);
 61
 62		return data;
 63	}
 64
 65	public int getCode() {
 66		return this.code;
 67	}
 68
 69	@Override
 70	public String toString() {
 71		return String.format("ErrorCode code=%d Error=%s", code, this.getErrorMessage(this.code));
 72	}
 73
 74	private String getErrorMessage(int code) {
 75		switch (code) {
 76		case Invalid_Version:
 77			return "Invalid_Version";
 78
 79		case Unsupported_Message_Class:
 80			return "Unsupported_Message_Class";
 81
 82		case Unsupported_Message_Type:
 83			return "Unsupported_Message_Type";
 84
 85		case Unsupported_Traffic_Mode_Type:
 86			return "Unsupported_Traffic_Mode_Type";
 87
 88		case Unexpected_Message:
 89			return "Unexpected_Message";
 90
 91		case Protocol_Error:
 92			return "Protocol_Error";
 93
 94		case Invalid_Stream_Identifier:
 95			return "Invalid_Stream_Identifier";
 96
 97		case Refused_Management_Blocking:
 98			return "Refused_Management_Blocking";
 99
100		case ASP_Identifier_Required:
101			return "ASP_Identifier_Required";
102
103		case Invalid_ASP_Identifier:
104			return "Invalid_ASP_Identifier";
105
106		case Invalid_Parameter_Value:
107			return "Invalid_Parameter_Value";
108
109		case Parameter_Field_Error:
110			return "Parameter_Field_Error";
111
112		case Unexpected_Parameter:
113			return "Unexpected_Parameter";
114
115		case Destination_Status_Unknown:
116			return "Destination_Status_Unknown";
117
118		case Invalid_Network_Appearance:
119			return "Invalid_Network_Appearance";
120
121		case Missing_Parameter:
122			return "Missing_Parameter";
123
124		case Invalid_Routing_Context:
125			return "Invalid_Routing_Context";
126
127		case No_Configured_AS_for_ASP:
128			return "No_Configured_AS_for_ASP";
129
130		default:
131			return Integer.toString(code);
132		}
133	}
134
135}