001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: HttpPresentationIOException.java,v 1.2 2006-06-15 13:40:47 sinisa Exp $
022: */
023:
024: package com.lutris.appserver.server.httpPresentation;
025:
026: import java.io.IOException;
027:
028: import com.lutris.util.ChainedException;
029:
030: /**
031: * IOException derived class that is thrown when the presentation manager
032: * encounters an I/O error when talking to a client. This allows the methods
033: * to determine how the error should be handled, even though it was generated
034: * by a call that occured in presentation code.
035: */
036: public class HttpPresentationIOException extends IOException {
037: /**
038: * Static method that does the approriate conversion from an IOException
039: * to a HttpPresentationIOException If the exception is already an
040: * HttpPresentationIOException, it is simple rethrown. If it is another type of
041: * IOException, it is converted to a HttpPresentationIOException.
042: *
043: * @param except The exception to rethrow or encapsulate.
044: * @return An exception ready to throw.
045: */
046: public static IOException rethrow(IOException except)
047: throws IOException {
048: if (except instanceof HttpPresentationIOException) {
049: return except;
050: } else {
051: return new HttpPresentationIOException(except);
052: }
053: }
054:
055: /**
056: * Flag that indicates that this came from an a I/O operation
057: * rather than a generated exception.
058: */
059: private boolean trueIOException = false;
060:
061: /**
062: * Construct a new exception from an existing IOException.
063: *
064: * @param except The exception to encapsulate.
065: */
066: public HttpPresentationIOException(IOException except) {
067: super (except.getMessage());
068: trueIOException = true;
069: }
070:
071: /**
072: * Construct a new exception with a specific message.
073: *
074: * @param msg The error message
075: */
076: public HttpPresentationIOException(String msg) {
077: super (msg);
078: }
079:
080: /**
081: * Did this exception come from an a I/O operation
082: * rather than a generated exception.
083: * @return True if its an actual I/O exception.
084: */
085: public boolean isTrueIOException() {
086: return trueIOException;
087: }
088:
089: /**
090: * Given a exception or error, determine if its generated by a HTTP
091: * client I/O exception. This handles ChyainedExceptions that might
092: * contain a client I/O exception.
093: *
094: * @param except Exception to check.
095: * @return <CODE>true</CODE> if this is cause by the client socket,
096: * <CODE>false</CODE> if not.
097: */
098: public static boolean isClientIOException(Throwable except) {
099: Throwable scan = except;
100: while (scan != null) {
101: if ((scan instanceof HttpPresentationIOException)
102: && ((HttpPresentationIOException) scan)
103: .isTrueIOException()) {
104: return true;
105: }
106: if (scan instanceof ChainedException) {
107: scan = ((ChainedException) scan).getCause();
108: } else {
109: return false;
110: }
111: }
112: return false;
113: }
114:
115: }
|