KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > httpPresentation > HttpPresentationIOException


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: HttpPresentationIOException.java,v 1.1 2005/07/13 11:09:06 slobodan Exp $
23  */

24
25
26
27
28
29 package com.lutris.appserver.server.httpPresentation;
30 import java.io.IOException JavaDoc;
31
32 import com.lutris.util.ChainedException;
33
34
35 /**
36  * IOException derived class that is thrown when the presentation manager
37  * encounters an I/O error when talking to a client. This allows the methods
38  * to determine how the error should be handled, even though it was generated
39  * by a call that occured in presentation code.
40  */

41 public class HttpPresentationIOException extends IOException JavaDoc {
42     /**
43      * Static method that does the approriate conversion from an IOException
44      * to a HttpPresentationIOException If the exception is already an
45      * HttpPresentationIOException, it is simple rethrown. If it is another type of
46      * IOException, it is converted to a HttpPresentationIOException.
47      *
48      * @param except The exception to rethrow or encapsulate.
49      * @return An exception ready to throw.
50      */

51     public static IOException JavaDoc rethrow(IOException JavaDoc except)
52             throws IOException JavaDoc {
53         if (except instanceof HttpPresentationIOException) {
54             return except;
55         } else {
56             return new HttpPresentationIOException(except);
57         }
58     }
59
60
61     /**
62      * Flag that indicates that this came from an a I/O operation
63      * rather than a generated exception.
64      */

65     private boolean trueIOException = false;
66
67     /**
68      * Construct a new exception from an existing IOException.
69      *
70      * @param except The exception to encapsulate.
71      */

72     public HttpPresentationIOException(IOException JavaDoc except) {
73         super(except.getMessage());
74         trueIOException = true;
75     }
76
77     /**
78      * Construct a new exception with a specific message.
79      *
80      * @param msg The error message
81      */

82     public HttpPresentationIOException(String JavaDoc msg) {
83         super(msg);
84     }
85
86     /**
87      * Did this exception come from an a I/O operation
88      * rather than a generated exception.
89      * @return True if its an actual I/O exception.
90      */

91     public boolean isTrueIOException() {
92         return trueIOException;
93     }
94
95     /**
96      * Given a exception or error, determine if its generated by a HTTP
97      * client I/O exception. This handles ChyainedExceptions that might
98      * contain a client I/O exception.
99      *
100      * @param except Exception to check.
101      * @return <CODE>true</CODE> if this is cause by the client socket,
102      * <CODE>false</CODE> if not.
103      */

104     public static boolean isClientIOException(Throwable JavaDoc except) {
105         Throwable JavaDoc scan = except;
106         while (scan != null) {
107             if ((scan instanceof HttpPresentationIOException)
108                 && ((HttpPresentationIOException)scan).isTrueIOException()) {
109                 return true;
110             }
111             if (scan instanceof ChainedException) {
112                 scan = ((ChainedException)scan).getCause();
113             } else {
114                 return false;
115             }
116         }
117         return false;
118     }
119
120 }
121
Popular Tags