KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > resource > ResourceException


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package javax.resource;
25
26 /**
27  * This is the root interface of the exception hierarchy defined
28  * for the Connector architecture.
29  *
30  * The ResourceException provides the following information:
31  * <UL>
32  * <LI> A resource adapter vendor specific string describing the error.
33  * This string is a standard Java exception message and is available
34  * through getMessage() method.
35  * <LI> resource adapter vendor specific error code.
36  * <LI> reference to another exception. Often a resource exception
37  * will be result of a lower level problem. If appropriate, this
38  * lower level exception can be linked to the ResourceException.
39  * Note, this has been deprecated in favor of J2SE release 1.4 exception
40  * chaining facility.
41  * </UL>
42  *
43  * @version 1.0
44  * @author Rahul Sharma
45  * @author Ram Jeyaraman
46  */

47
48 public class ResourceException extends java.lang.Exception JavaDoc {
49
50     /** Vendor specific error code */
51     private String JavaDoc errorCode;
52
53     /** reference to another exception */
54     private Exception JavaDoc linkedException;
55
56     /**
57      * Constructs a new instance with null as its detail message.
58      */

59     public ResourceException() { super(); }
60
61     /**
62      * Constructs a new instance with the specified detail message.
63      *
64      * @param message the detail message.
65      */

66     public ResourceException(String JavaDoc message) {
67     super(message);
68     }
69
70     /**
71      * Constructs a new throwable with the specified cause.
72      *
73      * @param cause a chained exception of type <code>Throwable</code>.
74      */

75     public ResourceException(Throwable JavaDoc cause) {
76     super(cause);
77     }
78
79     /**
80      * Constructs a new throwable with the specified detail message and cause.
81      *
82      * @param message the detail message.
83      *
84      * @param cause a chained exception of type <code>Throwable</code>.
85      */

86     public ResourceException(String JavaDoc message, Throwable JavaDoc cause) {
87     super(message, cause);
88     }
89
90     /**
91      * Create a new throwable with the specified message and error code.
92      *
93      * @param message a description of the exception.
94      * @param errorCode a string specifying the vendor specific error code.
95      */

96     public ResourceException(String JavaDoc message, String JavaDoc errorCode) {
97     super(message);
98     this.errorCode = errorCode;
99     }
100
101     /**
102      * Set the error code.
103      *
104      * @param errorCode the error code.
105      */

106     public void setErrorCode(String JavaDoc errorCode) {
107     this.errorCode = errorCode;
108     }
109
110     /**
111      * Get the error code.
112      *
113      * @return the error code.
114      */

115     public String JavaDoc getErrorCode() {
116     return this.errorCode;
117     }
118
119     /**
120      * Get the exception linked to this ResourceException
121      *
122      * @return linked Exception, null if none
123      *
124      * @deprecated J2SE release 1.4 supports a chained exception facility
125      * that allows any throwable to know about another throwable, if any,
126      * that caused it to get thrown. Refer to <code>getCause</code> and
127      * <code>initCause</code> methods of the
128      * <code>java.lang.Throwable</code> class..
129      */

130     public Exception JavaDoc getLinkedException() {
131     return (linkedException);
132     }
133
134     /**
135      * Add a linked Exception to this ResourceException.
136      *
137      * @param ex linked Exception
138      *
139      * @deprecated J2SE release 1.4 supports a chained exception facility
140      * that allows any throwable to know about another throwable, if any,
141      * that caused it to get thrown. Refer to <code>getCause</code> and
142      * <code>initCause</code> methods of the
143      * <code>java.lang.Throwable</code> class.
144      */

145     public void setLinkedException(Exception JavaDoc ex) {
146     linkedException = ex;
147     }
148
149     /**
150      * Returns a detailed message string describing this exception.
151      *
152      * @return a detailed message string.
153      */

154     public String JavaDoc getMessage() {
155     String JavaDoc msg = super.getMessage();
156     String JavaDoc ec = getErrorCode();
157     if ((msg == null) && (ec == null)) {
158         return null;
159     }
160     if ((msg != null) && (ec != null)) {
161         return (msg + ", error code: " + ec);
162     }
163     return ((msg != null) ? msg : ("error code: " + ec));
164     }
165 }
166
Popular Tags