1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can obtain
10 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
11 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
12 * language governing permissions and limitations under the License.
13 *
14 * When distributing the software, include this License Header Notice in each
15 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
16 * Sun designates this particular file as subject to the "Classpath" exception
17 * as provided by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the License
19 * Header, with the fields enclosed by brackets [] replaced by your own
20 * identifying information: "Portions Copyrighted [year]
21 * [name of copyright owner]"
22 *
23 * Contributor(s):
24 *
25 * If you wish your version of this file to be governed by only the CDDL or
26 * only the GPL Version 2, indicate your decision by adding "[Contributor]
27 * elects to include this software in this distribution under the [CDDL or GPL
28 * Version 2] license." If you don't indicate a single choice of license, a
29 * recipient has the option to distribute your version of this file under
30 * either the CDDL, the GPL Version 2 or to extend the choice of license to
31 * its licensees as provided above. However, if you add GPL Version 2 code
32 * and therefore, elected the GPL Version 2 license, then the option applies
33 * only if the new code is made subject to such option by the copyright
34 * holder.
35 */
36
37 package javax.resource;
38
39 /**
40 * This is the root interface of the exception hierarchy defined
41 * for the Connector architecture.
42 *
43 * The ResourceException provides the following information:
44 * <UL>
45 * <LI> A resource adapter vendor specific string describing the error.
46 * This string is a standard Java exception message and is available
47 * through getMessage() method.
48 * <LI> resource adapter vendor specific error code.
49 * <LI> reference to another exception. Often a resource exception
50 * will be result of a lower level problem. If appropriate, this
51 * lower level exception can be linked to the ResourceException.
52 * Note, this has been deprecated in favor of J2SE release 1.4 exception
53 * chaining facility.
54 * </UL>
55 *
56 * @version 1.0
57 * @author Rahul Sharma
58 * @author Ram Jeyaraman
59 */
60
61 public class ResourceException extends java.lang.Exception {
62
63 /** Vendor specific error code */
64 private String errorCode;
65
66 /** reference to another exception */
67 private Exception linkedException;
68
69 /**
70 * Constructs a new instance with null as its detail message.
71 */
72 public ResourceException() { super(); }
73
74 /**
75 * Constructs a new instance with the specified detail message.
76 *
77 * @param message the detail message.
78 */
79 public ResourceException(String message) {
80 super(message);
81 }
82
83 /**
84 * Constructs a new throwable with the specified cause.
85 *
86 * @param cause a chained exception of type <code>Throwable</code>.
87 */
88 public ResourceException(Throwable cause) {
89 super(cause);
90 }
91
92 /**
93 * Constructs a new throwable with the specified detail message and cause.
94 *
95 * @param message the detail message.
96 *
97 * @param cause a chained exception of type <code>Throwable</code>.
98 */
99 public ResourceException(String message, Throwable cause) {
100 super(message, cause);
101 }
102
103 /**
104 * Create a new throwable with the specified message and error code.
105 *
106 * @param message a description of the exception.
107 * @param errorCode a string specifying the vendor specific error code.
108 */
109 public ResourceException(String message, String errorCode) {
110 super(message);
111 this.errorCode = errorCode;
112 }
113
114 /**
115 * Set the error code.
116 *
117 * @param errorCode the error code.
118 */
119 public void setErrorCode(String errorCode) {
120 this.errorCode = errorCode;
121 }
122
123 /**
124 * Get the error code.
125 *
126 * @return the error code.
127 */
128 public String getErrorCode() {
129 return this.errorCode;
130 }
131
132 /**
133 * Get the exception linked to this ResourceException
134 *
135 * @return linked Exception, null if none
136 *
137 * @deprecated J2SE release 1.4 supports a chained exception facility
138 * that allows any throwable to know about another throwable, if any,
139 * that caused it to get thrown. Refer to <code>getCause</code> and
140 * <code>initCause</code> methods of the
141 * <code>java.lang.Throwable</code> class..
142 */
143 public Exception getLinkedException() {
144 return (linkedException);
145 }
146
147 /**
148 * Add a linked Exception to this ResourceException.
149 *
150 * @param ex linked Exception
151 *
152 * @deprecated J2SE release 1.4 supports a chained exception facility
153 * that allows any throwable to know about another throwable, if any,
154 * that caused it to get thrown. Refer to <code>getCause</code> and
155 * <code>initCause</code> methods of the
156 * <code>java.lang.Throwable</code> class.
157 */
158 public void setLinkedException(Exception ex) {
159 linkedException = ex;
160 }
161
162 /**
163 * Returns a detailed message string describing this exception.
164 *
165 * @return a detailed message string.
166 */
167 public String getMessage() {
168 String msg = super.getMessage();
169 String ec = getErrorCode();
170 if ((msg == null) && (ec == null)) {
171 return null;
172 }
173 if ((msg != null) && (ec != null)) {
174 return (msg + ", error code: " + ec);
175 }
176 return ((msg != null) ? msg : ("error code: " + ec));
177 }
178 }