001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package javax.xml.bind;
018    
019    import java.io.IOException;
020    import java.io.PrintStream;
021    import java.io.PrintWriter;
022    
023    public class JAXBException extends Exception {
024    
025        private static final long serialVersionUID = 0x5dd94775L;
026    
027        private String errorCode;
028        private Throwable linkedException;
029    
030        public JAXBException(String message) {
031            this(message, null, null);
032        }
033    
034        public JAXBException(String message, String errorCode) {
035            this(message, errorCode, null);
036        }
037    
038        public JAXBException(String message, String errorCode, Throwable cause) {
039            super(message);
040            this.errorCode = errorCode;
041            this.linkedException = cause;
042        }
043    
044        public JAXBException(String message, Throwable cause) {
045            this(message, null, cause);
046        }
047    
048        public JAXBException(Throwable cause) {
049            this(null, null, cause);
050        }
051    
052        public String getErrorCode() {
053            return errorCode;
054        }
055    
056        public Throwable getLinkedException() {
057            return getCause();
058        }
059    
060        public synchronized void setLinkedException(Throwable linkedException) {
061            this.linkedException = linkedException;
062        }
063    
064        public String toString() {
065            return linkedException != null ?
066                    super.toString() + "\n - with linked exception:\n[" + linkedException.toString() + "]" : 
067                    super.toString();
068        }
069    
070        @Override
071        public Throwable getCause() {
072            return linkedException;
073        }
074    
075        public void printStackTrace() {
076            super.printStackTrace();
077        }
078    
079        public void printStackTrace(PrintStream ps) {
080            super.printStackTrace(ps);
081        }
082    
083        public void printStackTrace(PrintWriter pw) {
084            super.printStackTrace(pw);
085        }
086    
087    }