001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package javax.resource;
023:
024: import org.jboss.util.id.SerialVersion;
025:
026: /**
027: * This is the root exception for the exception hierarchy defined for the
028: * connector architecture.
029: *
030: * A ResourceException contains three items, the first two of which are set from
031: * the constructor. The first is a standard message string which is accessed via
032: * the getMessage() method. The second is an errorCode which is accessed via the
033: * getErrorCode() method. The third is a linked exception which provides more
034: * information from a lower level in the resource manager. Linked exceptions are
035: * accessed via get/setLinkedException.
036: */
037: public class ResourceException extends Exception {
038: /** @since 4.0.2 */
039: static final long serialVersionUID;
040: static {
041: if (SerialVersion.version == SerialVersion.LEGACY)
042: serialVersionUID = 4770679801401540475L;
043: else
044: serialVersionUID = 547071213627824490L;
045: }
046:
047: /**
048: * The error code
049: */
050: private String errorCode;
051:
052: /**
053: * The linked exception
054: */
055: private Exception linkedException;
056:
057: /**
058: * Create an exception with a null reason.
059: */
060: public ResourceException() {
061: super ();
062: }
063:
064: /**
065: * Create an exception with a reason.
066: * @param reason the reason
067: */
068: public ResourceException(String reason) {
069: super (reason);
070: }
071:
072: /**
073: * Create an exception with a reason and an errorCode.
074: * @param reason the reason
075: * @param errorCode the error code
076: */
077: public ResourceException(String reason, String errorCode) {
078: super (reason);
079: this .errorCode = errorCode;
080: }
081:
082: /**
083: * Create an exception with a reason and an errorCode.
084: * @param reason the reason
085: * @param throwable the linked error
086: */
087: public ResourceException(String reason, Throwable throwable) {
088: super (reason, throwable);
089: }
090:
091: /**
092: * Create an exception with a reason and an errorCode.
093: * @param throwable the linked error
094: */
095: public ResourceException(Throwable throwable) {
096: super (throwable);
097: }
098:
099: /**
100: * Get the error code.
101: * @return the error code
102: */
103: public String getErrorCode() {
104: return errorCode;
105: }
106:
107: /**
108: * Get any linked exception.
109: * @return the linked exception
110: */
111: public Exception getLinkedException() {
112: return linkedException;
113: }
114:
115: /**
116: * Get the message composed of the reason and error code.
117: *
118: * @return message composed of the reason and error code.
119: */
120: public String getMessage() {
121: String msg = super .getMessage();
122: String ec = getErrorCode();
123: if ((msg == null) && (ec == null)) {
124: return null;
125: }
126: if ((msg != null) && (ec != null)) {
127: return (msg + ", error code: " + ec);
128: }
129: return ((msg != null) ? msg : ("error code: " + ec));
130: }
131:
132: /**
133: * Set the error code.
134: * @param errorCode code the error code
135: */
136: public void setErrorCode(String errorCode) {
137: this .errorCode = errorCode;
138: }
139:
140: /**
141: * Set a linked exception.
142: * @param linkedException the linked exception
143: * @deprecated use initCause
144: */
145: public void setLinkedException(Exception linkedException) {
146: this.linkedException = linkedException;
147: initCause(linkedException);
148: }
149: }
|