KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > joseki > HttpException


1 /*
2  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.joseki;
7
8 /** Exception class for all operations in the Joseki client library.
9  * Error codes are as HTTP statsus codes.
10  *
11  * @version $Id: HttpException.java,v 1.4 2004/04/30 14:13:13 andy_seaborne Exp $
12  * @author Andy Seaborne
13  */

14 public class HttpException extends JosekiException
15 {
16     public static final int noResponseCode = -1234 ;
17     private int responseCode = noResponseCode ;
18     private String JavaDoc responseMessage = null ;
19
20     // Codes for extra errors. We use HTTP error codes so
21
// these are negative to avoid clashes
22
public static final int NoServer = -404 ;
23
24     /**
25      * Constructor for HttpException.
26      * @param responseCode
27      * @param responseMessage
28      */

29     public HttpException(int responseCode, String JavaDoc responseMessage)
30     {
31         super(responseMessage) ;
32         this.responseCode = responseCode ;
33         this.responseMessage = responseMessage ;
34     }
35     
36
37     /**
38      * Constructor for HttpException.
39      * @param responseCode
40      */

41     public HttpException(int responseCode)
42     {
43         super() ;
44         this.responseCode = responseCode ;
45         this.responseMessage = null ;
46     }
47     
48     /** The code for the reason for this exception
49      * @return responseCode
50      */

51     public int getResponseCode() { return responseCode ; }
52     
53     
54     /** The messge for the reason for this exception
55      * @return message
56      */

57     public String JavaDoc getResponseMessage() { return responseMessage ; }
58
59     /**
60      * Constructor for HttpException used for some unexpected execution error.
61      * @param cause
62      */

63     public HttpException(Throwable JavaDoc cause)
64     {
65         super(cause);
66         this.responseCode = noResponseCode ;
67         this.responseMessage = null ;
68     }
69     
70     public HttpException(String JavaDoc msg, Throwable JavaDoc cause)
71     {
72         super(msg, cause);
73         this.responseCode = noResponseCode ;
74         this.responseMessage = msg ;
75     }
76     
77     public String JavaDoc toString()
78     {
79         StringBuffer JavaDoc sb = new StringBuffer JavaDoc() ;
80         sb.append("HttpException: ") ;
81         int code = getResponseCode() ;
82         if ( code != HttpException.noResponseCode )
83         {
84             sb.append(code) ;
85             if ( getResponseMessage() != null )
86             {
87                 sb.append(" ") ;
88                 sb.append(getResponseMessage()) ;
89             }
90         }
91         else
92         {
93             sb.append(getCause().toString()+": "+getMessage()) ;
94         }
95         return sb.toString() ;
96     }
97 }
98
99
100 /*
101  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
102  * All rights reserved.
103  *
104  * Redistribution and use in source and binary forms, with or without
105  * modification, are permitted provided that the following conditions
106  * are met:
107  * 1. Redistributions of source code must retain the above copyright
108  * notice, this list of conditions and the following disclaimer.
109  * 2. Redistributions in binary form must reproduce the above copyright
110  * notice, this list of conditions and the following disclaimer in the
111  * documentation and/or other materials provided with the distribution.
112  * 3. The name of the author may not be used to endorse or promote products
113  * derived from this software without specific prior written permission.
114  *
115  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
116  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
117  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
118  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
119  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
120  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
121  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
122  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
123  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
124  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
125  */

126
Popular Tags