001/* ========================================================================
002 * JCommon : a free general purpose class library for the Java(tm) platform
003 * ========================================================================
004 *
005 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006 * 
007 * Project Info:  http://www.jfree.org/jcommon/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it 
010 * under the terms of the GNU Lesser General Public License as published by 
011 * the Free Software Foundation; either version 2.1 of the License, or 
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but 
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022 * USA.  
023 *
024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025 * in the United States and other countries.]
026 * 
027 * ------------------------------
028 * ElementDefinitionException.java
029 * ------------------------------
030 * (C)opyright 2002-2004, by Object Refinery Limited.
031 *
032 * $Id: ElementDefinitionException.java,v 1.3 2005/10/18 13:25:44 mungady Exp $
033 *
034 * Changes
035 * -------
036 * 24-Apr-2002 : Initial version
037 * 31-Aug-2002 : Documentation; changed PrintStackTrace for better tracing
038 * 29-Apr-2003 : Distilled from the JFreeReport project and moved into JCommon
039 */
040package org.jfree.xml;
041
042import java.io.PrintStream;
043import java.io.PrintWriter;
044
045import org.xml.sax.Locator;
046
047/**
048 * A reportdefinition exception is thrown when the parsing of the report definition
049 * failed because invalid or missing attributes are encountered.
050 *
051 * @author Thomas Morgner
052 */
053public class ElementDefinitionException extends ParseException {
054
055    /** The parent exception. */
056    private Exception parent;
057
058    /**
059     * Creates a new ElementDefinitionException without an parent exception and with the given
060     * message as explanation.
061     *
062     * @param message a detail message explaining the reasons for this exception.
063     */
064    public ElementDefinitionException(final String message) {
065        super(message);
066    }
067
068    /**
069     * Creates a new ElementDefinitionException with an parent exception and with the parents
070     * message as explaination.
071     *
072     * @param e the parentException that caused this exception
073     */
074    public ElementDefinitionException(final Exception e) {
075        this(e, e.getMessage());
076    }
077
078    /**
079     * Creates a new ElementDefinitionException with an parent exception and with the given
080     * message as explaination.
081     *
082     * @param e the parentException that caused this exception
083     * @param message a detail message explaining the reasons for this exception
084     */
085    public ElementDefinitionException(final Exception e, final String message) {
086        this(message);
087        this.parent = e;
088    }
089
090    /**
091     * Creates a new ParseException with the given root exception
092     * and the locator.
093     *
094     * @param e       the exception
095     * @param locator the locator of the parser
096     */
097    public ElementDefinitionException(final Exception e, final Locator locator) {
098        super(e, locator);
099        this.parent = e;
100    }
101
102    /**
103     * Creates a new ParseException with the given message and the locator.
104     *
105     * @param message the message
106     * @param locator the locator of the parser
107     */
108    public ElementDefinitionException(final String message, final Locator locator) {
109        super(message, locator);
110    }
111
112    /**
113     * Creates a new ParseException with the given message, root exception
114     * and the locator.
115     *
116     * @param s       the message
117     * @param e       the exception
118     * @param locator the locator of the parser
119     */
120    public ElementDefinitionException(final String s, final Exception e, final Locator locator) {
121        super(s, e, locator);
122        this.parent = e;
123    }
124
125    /**
126     * Returns the parent exception.
127     *
128     * @return the parent exception.
129     */
130    public Exception getParentException() {
131        return this.parent;
132    }
133
134    /**
135     * Prints the stack trace.  If an inner exception exists, use
136     * its stack trace.
137     *
138     * @param s  the stream for writing to.
139     */
140    public void printStackTrace(final PrintStream s) {
141        super.printStackTrace(s);
142        if (this.parent != null) {
143            s.print("ParentException:");
144            this.parent.printStackTrace(s);
145        }
146        else {
147            s.println("ParentException: <null>");
148        }
149    }
150
151    /**
152     * Prints the stack trace.  If an inner exception exists, use
153     * its stack trace.
154     *
155     * @param s  the stream for writing to.
156     */
157    public void printStackTrace(final PrintWriter s) {
158        super.printStackTrace(s);
159        if (this.parent != null) {
160            s.print("ParentException:");
161            this.parent.printStackTrace(s);
162        }
163        else {
164            s.println("ParentException: <null>");
165        }
166    }
167
168}