View Javadoc
1   /**
2    * Redistribution and use of this software and associated documentation ("Software"), with or
3    * without modification, are permitted provided that the following conditions are met:
4    *
5    * 1. Redistributions of source code must retain copyright statements and notices. Redistributions
6    * must also contain a copy of this document.
7    *
8    * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
9    * conditions and the following disclaimer in the documentation and/or other materials provided with
10   * the distribution.
11   *
12   * 3. The name "Exolab" must not be used to endorse or promote products derived from this Software
13   * without prior written permission of Intalio, Inc. For written permission, please contact
14   * info@exolab.org.
15   *
16   * 4. Products derived from this Software may not be called "Exolab" nor may "Exolab" appear in
17   * their names without prior written permission of Intalio, Inc. Exolab is a registered trademark of
18   * Intalio, Inc.
19   *
20   * 5. Due credit should be given to the Exolab Project (http://www.exolab.org/).
21   *
22   * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR
23   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
24   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTALIO, INC. OR ITS
25   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
29   * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30   *
31   * Copyright 2001 (C) Intalio, Inc. All Rights Reserved.
32   *
33   * $Id$
34   */
35  
36  
37  package org.exolab.castor.mapping;
38  
39  import org.castor.core.util.Messages;
40  
41  import java.io.PrintWriter;
42  import java.io.PrintStream;
43  
44  
45  /**
46   * An exception indicating an invalid mapping error. This exception extends IllegalStateException so
47   * that it can be used to replace current uses of IllegalStateException within the mapping
48   * framework. This exception is used when a nested exception needs to be reported.
49   *
50   * @author <a href="arkin@intalio.com">Assaf Arkin</a>
51   * @author <a href="kvisco@intalio.com">Keith Visco</a>
52   * @version $Revision$ $Date: 2006-04-10 16:39:24 -0600 (Mon, 10 Apr 2006) $
53   */
54  public class MappingRuntimeException extends IllegalStateException {
55    /** SerialVersionUID */
56    private static final long serialVersionUID = 238861866150334375L;
57  
58    /**
59     * The exception which caused this Exception
60     **/
61    private Throwable _exception;
62  
63  
64    /**
65     * Creates a new MappingRuntimeException
66     *
67     * @param message the error message
68     **/
69    public MappingRuntimeException(String message) {
70      super(Messages.message(message));
71    } // -- MappingRuntimeException
72  
73  
74    /**
75     * Creates a new MappingRuntimeException
76     *
77     * @param message the error message
78     **/
79    public MappingRuntimeException(String message, Object[] args) {
80      super(Messages.format(message, args));
81    } // -- MappingRuntimeException
82  
83  
84    /**
85     * Creates a new MappingRuntimeException
86     *
87     * @param exception the Exception which caused this Exception.
88     **/
89    public MappingRuntimeException(Throwable exception) {
90      super(Messages.format("mapping.nested", exception.toString()));
91      _exception = exception;
92    } // -- MappingRuntimeException
93  
94    /**
95     * Creates a new MappingRuntimeException
96     *
97     * @param exception the Exception which caused this Exception.
98     * @param message the error message
99     **/
100   public MappingRuntimeException(Throwable exception, String message) {
101     super(Messages.format("mapping.nested", message));
102     _exception = exception;
103   } // -- MappingRuntimeException
104 
105 
106   /**
107    * Returns the Exception which caused this Exception, or null if no nested exception exists.
108    *
109    * @return the nested Exception.
110    **/
111   public Throwable getException() {
112     return _exception;
113   } // -- getException
114 
115 
116   public void printStackTrace() {
117     if (_exception == null)
118       super.printStackTrace();
119     else
120       _exception.printStackTrace();
121   } // -- printStackTrace
122 
123 
124   public void printStackTrace(PrintStream print) {
125     if (_exception == null)
126       super.printStackTrace(print);
127     else
128       _exception.printStackTrace(print);
129   } // -- printStackTrace
130 
131 
132   public void printStackTrace(PrintWriter print) {
133     if (_exception == null)
134       super.printStackTrace(print);
135     else
136       _exception.printStackTrace(print);
137   } // -- printStackTrace
138 
139 
140 } // -- MappingRuntimeException
141