1 /* 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Intalio, Inc. For written permission, 18 * please contact info@exolab.org. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Intalio, Inc. Exolab is a registered 23 * trademark of Intalio, Inc. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 2002 (C) Intalio Inc. All Rights Reserved. 42 * 43 * $Id$ 44 */ 45 package org.exolab.castor.builder.binding; 46 47 /** 48 * The base exception for the <tt>binding</tt> package. This exception is 49 * nested in order to keep a correct stack trace while nesting the exception 50 * that causes the call to BindingException. 51 * 52 * @author <a href="mailto:blandin@intalio.com">Arnaud Blandin</a> 53 * @version $Version:$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ 54 */ 55 public final class BindingException extends Exception { 56 57 /** We add this field because an Exception is serializable. */ 58 private static final long serialVersionUID = 1726983206974247107L; 59 /** The embedded exception if tunnelling, or null. */ 60 private Exception _exception; 61 62 /** 63 * Creates a new BindingException. 64 * 65 * @param message The error or warning message. 66 */ 67 public BindingException(final String message) { 68 super(message); 69 _exception = null; 70 } 71 72 /** 73 * Creates a new BindingException wrapping an existing Exception. 74 * <p> 75 * The existing Exception will be embedded in the new one, and its message 76 * will become the default message for the BindingException. 77 * 78 * @param exception The Exception to be wrapped in a BindingException. 79 */ 80 public BindingException(final Exception exception) { 81 super(); 82 _exception = exception; 83 } 84 85 /** 86 * Creates a new BindingException from an existing exception. 87 * <p> 88 * The existing Exception will be embedded in the new one, but the new 89 * Exception will have its own message. 90 * 91 * @param message The detail message. 92 * @param exception The Exception to be wrapped in a BindingException. 93 */ 94 public BindingException(final String message, final Exception exception) { 95 super(message); 96 _exception = exception; 97 } 98 99 /** 100 * Returns a detailed message for this Exception. 101 * <p> 102 * If there is an embedded Exception, and if the BindingException has no 103 * detail message of its own, this method will return the detail message 104 * from the embedded Exception. 105 * 106 * @return String The error or warning message. 107 */ 108 public String getMessage() { 109 String message = super.getMessage(); 110 111 if (message == null && _exception != null) { 112 return _exception.getMessage(); 113 } 114 return message; 115 } 116 117 /** 118 * Returns the embedded Exception, if any. 119 * 120 * @return Exception The embedded Exception, or null if there is none. 121 */ 122 public Exception getException() { 123 return _exception; 124 } 125 126 /** 127 * Overrides printStackTrace to keep the stack trace of the embedded 128 * Exception. 129 */ 130 public void printStackTrace() { 131 if (_exception != null) { 132 System.out.println("--------------------------------"); 133 System.out.println("Stack Trace for :" + _exception); 134 _exception.printStackTrace(); 135 System.out.println("--------------------------------"); 136 } 137 super.printStackTrace(); 138 } 139 140 /** 141 * Overrides toString to pick up any embedded Exception. 142 * 143 * @return String A string representation of this Exception. 144 */ 145 public String toString() { 146 if (_exception != null) { 147 return _exception.toString(); 148 } 149 return super.toString(); 150 } 151 152 }