001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.http;
027:
028: import org.jicarilla.lang.CascadingException;
029:
030: import java.io.Serializable;
031:
032: /**
033: * Base exception for all exceptions that occur when handling
034: * HTTP communication. Provides support for getting and setting
035: * the HTTP response code associated with the exception. Instead
036: * of subclassing this exception for every response code, simply
037: * use a constructore which takes a response code.
038: *
039: * If <code>code</code> is not set, 500 is assumed. If you
040: * provde a code bigger than 999, but no message, you're in trouble
041: * as you'll be slapped with an ArrayIndexOutOfBoundsException.
042: *
043: * @author <a href="mailto: lsimons at jicarilla dot org">Leo Simons</a>
044: * @version $Id: HTTPException.java,v 1.5 2004/03/23 13:37:48 lsimons Exp $
045: */
046: public class HTTPException extends CascadingException implements
047: Serializable {
048: // ----------------------------------------------------------------------
049: // Properties
050: // ----------------------------------------------------------------------
051: public final static String DEFAULT_MESSAGE = HTTPEncoding.STATUS_500_MSG;
052: public final static int DEFAULT_CODE = HTTPEncoding.STATUS_500_Internal_Server_Error;
053: protected int m_code = DEFAULT_CODE;
054:
055: // ----------------------------------------------------------------------
056: // Constructors
057: // ----------------------------------------------------------------------
058: public HTTPException() {
059: super (HTTPEncoding.STATUS_MSG[DEFAULT_CODE]);
060: }
061:
062: public HTTPException(final int code) {
063: super (HTTPEncoding.STATUS_MSG[code]);
064:
065: m_code = code;
066: }
067:
068: public HTTPException(final String message) {
069: super (message);
070: }
071:
072: public HTTPException(final int code, final Throwable t) {
073: super (HTTPEncoding.STATUS_MSG[code], t);
074:
075: m_code = code;
076: }
077:
078: public HTTPException(final String message, final Throwable t) {
079: super (message, t);
080: }
081:
082: public HTTPException(final int code, final String message) {
083: super (message);
084:
085: m_code = code;
086: }
087:
088: public HTTPException(final int code, final String message,
089: final Throwable t) {
090: super (message, t);
091:
092: m_code = code;
093: }
094:
095: // ----------------------------------------------------------------------
096: // Work Interface: HTTPException
097: // ----------------------------------------------------------------------
098: public int getCode() {
099: return m_code;
100: }
101:
102: // ----------------------------------------------------------------------
103: // Equals and HashCode
104: // ----------------------------------------------------------------------
105:
106: public boolean equals(final Object o) {
107: if (this == o)
108: return true;
109: if (!(o instanceof HTTPException))
110: return false;
111:
112: final HTTPException httpException = (HTTPException) o;
113:
114: if (m_code != httpException.m_code)
115: return false;
116:
117: return true;
118: }
119:
120: public int hashCode() {
121: return m_code;
122: }
123: }
|