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 2001 (C) Intalio, Inc. All Rights Reserved. 42 * 43 * $Id$ 44 */ 45 46 47 package org.exolab.castor.mapping; 48 49 import org.castor.core.util.Messages; 50 51 import java.io.PrintWriter; 52 import java.io.PrintStream; 53 54 55 /** 56 * An exception indicating an invalid mapping error. This 57 * exception extends IllegalStateException so that it can 58 * be used to replace current uses of IllegalStateException 59 * within the mapping framework. This exception is used 60 * when a nested exception needs to be reported. 61 * 62 * @author <a href="arkin@intalio.com">Assaf Arkin</a> 63 * @author <a href="kvisco@intalio.com">Keith Visco</a> 64 * @version $Revision$ $Date: 2006-04-10 16:39:24 -0600 (Mon, 10 Apr 2006) $ 65 */ 66 public class MappingRuntimeException extends IllegalStateException { 67 /** SerialVersionUID */ 68 private static final long serialVersionUID = 238861866150334375L; 69 70 /** 71 * The exception which caused this Exception 72 **/ 73 private Throwable _exception; 74 75 76 /** 77 * Creates a new MappingRuntimeException 78 * 79 * @param message the error message 80 **/ 81 public MappingRuntimeException( String message ) { 82 super( Messages.message( message ) ); 83 } //-- MappingRuntimeException 84 85 86 /** 87 * Creates a new MappingRuntimeException 88 * 89 * @param message the error message 90 **/ 91 public MappingRuntimeException( String message, Object[] args) { 92 super( Messages.format( message, args ) ); 93 } //-- MappingRuntimeException 94 95 96 /** 97 * Creates a new MappingRuntimeException 98 * 99 * @param exception the Exception which caused this Exception. 100 **/ 101 public MappingRuntimeException(Throwable exception) { 102 super( Messages.format( "mapping.nested", exception.toString() ) ); 103 _exception = exception; 104 } //-- MappingRuntimeException 105 106 /** 107 * Creates a new MappingRuntimeException 108 * 109 * @param exception the Exception which caused this Exception. 110 * @param message the error message 111 **/ 112 public MappingRuntimeException(Throwable exception, String message) { 113 super( Messages.format( "mapping.nested", message ) ); 114 _exception = exception; 115 } //-- MappingRuntimeException 116 117 118 /** 119 * Returns the Exception which caused this Exception, or null if 120 * no nested exception exists. 121 * 122 * @return the nested Exception. 123 **/ 124 public Throwable getException() { 125 return _exception; 126 } //-- getException 127 128 129 public void printStackTrace() { 130 if ( _exception == null ) 131 super.printStackTrace(); 132 else 133 _exception.printStackTrace(); 134 } //-- printStackTrace 135 136 137 public void printStackTrace( PrintStream print ) { 138 if ( _exception == null ) 139 super.printStackTrace( print ); 140 else 141 _exception.printStackTrace( print ); 142 } //-- printStackTrace 143 144 145 public void printStackTrace( PrintWriter print ) { 146 if ( _exception == null ) 147 super.printStackTrace( print ); 148 else 149 _exception.printStackTrace( print ); 150 } //-- printStackTrace 151 152 153 } //-- MappingRuntimeException 154