001: /*
002: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
003: * Reserved. Use is subject to license terms.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025:
026: package javax.microedition.sip;
027:
028: import java.io.IOException;
029:
030: /**
031: * This is an exception class for SIP specific errors.
032: * @see JSR180 spec, v 1.0.1, p 63-66
033: *
034: */
035: public class SipException extends IOException {
036: /**
037: * Other SIP error
038: */
039: public static final byte GENERAL_ERROR = 0;
040:
041: /**
042: * The requested transport is not supported
043: */
044: public static final byte TRANSPORT_NOT_SUPPORTED = 1;
045:
046: /**
047: * Thrown for example when SIP connection does not belong to any Dialog.
048: */
049: public static final byte DIALOG_UNAVAILABLE = 2;
050:
051: /**
052: * Used when for example Content-Type is not set before filling
053: * the message body.
054: */
055: public static final byte UNKNOWN_TYPE = 3;
056:
057: /**
058: * Used when for example Content-Length is not set before filling
059: * the message body
060: */
061: public static final byte UNKNOWN_LENGTH = 4;
062:
063: /**
064: * Method call not allowed, because of wrong state in SIP connection.
065: */
066: public static final byte INVALID_STATE = 5;
067:
068: /**
069: * The system does not allow particular operation. NOTICE! This error does
070: * not handle security exceptions.
071: */
072: public static final byte INVALID_OPERATION = 6;
073:
074: /**
075: * System can not open any new transactions.
076: */
077: public static final byte TRANSACTION_UNAVAILABLE = 7;
078:
079: /**
080: * The message to be sent has invalid format.
081: */
082: public static final byte INVALID_MESSAGE = 8;
083:
084: /**
085: * Current error code for this sip exception
086: */
087: private byte error_code;
088:
089: /**
090: * Construct SipException with error code.
091: * @param errorCode - error code. If the error code is none of
092: * the specified
093: * codes the Exception is initialized with default GENERAL_ERROR.
094: */
095: public SipException(byte errorCode) {
096: super ();
097:
098: if (errorCode > INVALID_MESSAGE || errorCode < GENERAL_ERROR) {
099: // If the error code is none of the specified codes
100: // the Exception is initialized with default GENERAL_ERROR.
101: errorCode = GENERAL_ERROR;
102: } else {
103: error_code = errorCode;
104: }
105: }
106:
107: /**
108: * Construct SipException with textual message and error code.
109: * @param message - error message.
110: * @param errorCode - error code. If the error code is none of
111: * the specified
112: * codes the Exception is initialized with default GENERAL_ERROR.
113: */
114: public SipException(java.lang.String message, byte errorCode) {
115: super (message);
116:
117: if (errorCode > INVALID_MESSAGE || errorCode < GENERAL_ERROR) {
118: // If the error code is none of the specified codes
119: // the Exception is initialized with default GENERAL_ERROR.
120: errorCode = GENERAL_ERROR;
121: } else {
122: error_code = errorCode;
123: }
124: }
125:
126: /**
127: * Gets the error code
128: * @return error code
129: */
130: public byte getErrorCode() {
131: return error_code;
132: }
133: }
|