KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > apps > FOPException


1 /*
2  * $Id: FOPException.java,v 1.9.2.2 2003/04/11 00:24:36 pietsch Exp $
3  * ============================================================================
4  * The Apache Software License, Version 1.1
5  * ============================================================================
6  *
7  * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modifica-
10  * tion, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if any, must
20  * include the following acknowledgment: "This product includes software
21  * developed by the Apache Software Foundation (http://www.apache.org/)."
22  * Alternately, this acknowledgment may appear in the software itself, if
23  * and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "FOP" and "Apache Software Foundation" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * apache@apache.org.
29  *
30  * 5. Products derived from this software may not be called "Apache", nor may
31  * "Apache" appear in their name, without prior written permission of the
32  * Apache Software Foundation.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39  * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  * ============================================================================
45  *
46  * This software consists of voluntary contributions made by many individuals
47  * on behalf of the Apache Software Foundation and was originally created by
48  * James Tauber <jtauber@jtauber.com>. For more information on the Apache
49  * Software Foundation, please see <http://www.apache.org/>.
50  */

51 package org.apache.fop.apps;
52
53 import org.xml.sax.SAXException JavaDoc;
54
55
56 /**
57  * Exception thrown when FOP has a problem
58  */

59 public class FOPException extends Exception JavaDoc {
60
61     private static final String JavaDoc EXCEPTION_SEPARATOR = "\n---------\n";
62
63     private Throwable JavaDoc _exception;
64     private String JavaDoc systemId;
65     private int line;
66     private int column;
67
68     /**
69      * create a new FOP Exception
70      *
71      * @param message descriptive message
72      */

73     public FOPException(String JavaDoc message) {
74         super(message);
75         systemId = null;
76         line = -1;
77         column = -1;
78     }
79
80     public FOPException(String JavaDoc message, String JavaDoc systemId, int line, int column) {
81         super(message);
82         this.systemId = systemId;
83         this.line = line;
84         this.column = column;
85     }
86
87     public FOPException(Throwable JavaDoc e) {
88         super(e.getMessage());
89         setException(e);
90         systemId = null;
91         line = -1;
92         column = -1;
93     }
94
95     public FOPException(Throwable JavaDoc e, String JavaDoc systemId, int line, int column) {
96         super(e.getMessage());
97         setException(e);
98         this.systemId = systemId;
99         this.line = line;
100         this.column = column;
101     }
102
103     public FOPException(String JavaDoc message, Throwable JavaDoc e) {
104         super(message);
105         setException(e);
106         systemId = null;
107         line = -1;
108         column = -1;
109     }
110
111     public FOPException(String JavaDoc message, Throwable JavaDoc e, String JavaDoc systemId, int line, int column) {
112         super(message);
113         setException(e);
114         this.systemId = systemId;
115         this.line = line;
116         this.column = column;
117     }
118
119     protected void setException(Throwable JavaDoc t) {
120         _exception = t;
121     }
122
123     public Throwable JavaDoc getException() {
124         return _exception;
125     }
126
127     public void setLocation(String JavaDoc systemId, int line, int column) {
128         this.systemId = systemId;
129         this.line = line;
130         this.column = column;
131     }
132
133     public boolean isLocationSet() {
134         return line>=0;
135     }
136
137     protected Throwable JavaDoc getRootException() {
138         Throwable JavaDoc result = _exception;
139
140         if (result instanceof SAXException JavaDoc) {
141             result = ((SAXException JavaDoc)result).getException();
142         }
143         if (result instanceof java.lang.reflect.InvocationTargetException JavaDoc) {
144             result =
145                 ((java.lang.reflect.InvocationTargetException JavaDoc)result).getTargetException();
146         }
147         if (result != _exception) {
148             return result;
149         }
150         return null;
151     }
152
153     public String JavaDoc getMessage() {
154         if (line>=0) {
155             return systemId+':'+line+':'+column+' '+super.getMessage();
156         } else {
157             return super.getMessage();
158         }
159     }
160     
161     public void printStackTrace() {
162         synchronized (System.err) {
163             super.printStackTrace();
164             if (_exception != null) {
165                 System.err.println(EXCEPTION_SEPARATOR);
166                 _exception.printStackTrace();
167             }
168             if (getRootException() != null) {
169                 System.err.println(EXCEPTION_SEPARATOR);
170                 getRootException().printStackTrace();
171             }
172         }
173     }
174
175     public void printStackTrace(java.io.PrintStream JavaDoc stream) {
176         synchronized (stream) {
177             super.printStackTrace(stream);
178             if (_exception != null) {
179                 stream.println(EXCEPTION_SEPARATOR);
180                 _exception.printStackTrace(stream);
181             }
182             if (getRootException() != null) {
183                 stream.println(EXCEPTION_SEPARATOR);
184                 getRootException().printStackTrace(stream);
185             }
186         }
187     }
188
189     public void printStackTrace(java.io.PrintWriter JavaDoc writer) {
190         synchronized (writer) {
191             super.printStackTrace(writer);
192             if (_exception != null) {
193                 writer.println(EXCEPTION_SEPARATOR);
194                 _exception.printStackTrace(writer);
195             }
196             if (getRootException() != null) {
197                 writer.println(EXCEPTION_SEPARATOR);
198                 getRootException().printStackTrace(writer);
199             }
200         }
201     }
202
203 }
204
Popular Tags