KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mdarad > framework > exception > ChainedException


1 /*
2     Mdarad-Toolobox is a collection of tools for Architected RAD
3     (Rapid Application Development) based on an MDA approach.
4     The toolbox contains frameworks and generators for many environments
5     (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
6     applications from a design Model
7     Copyright (C) 2004-2005 Elapse Technologies Inc.
8
9     This library is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public
11     License as published by the Free Software Foundation; either
12     version 2.1 of the License, or (at your option) any later version.
13
14     This library is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17     General Public License for more details.
18
19     You should have received a copy of the GNU General Public
20     License along with this library; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */

23 package org.mdarad.framework.exception;
24
25 import java.io.PrintStream JavaDoc;
26 import java.io.PrintWriter JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Vector JavaDoc;
29
30 public class ChainedException extends SystemException {
31     Vector JavaDoc exceptions = new Vector JavaDoc();
32
33     public ChainedException() {
34         super();
35     }
36
37     public ChainedException(String JavaDoc message) {
38         super(message);
39     }
40
41     public ChainedException(Throwable JavaDoc cause) {
42         super(cause);
43     }
44
45     public ChainedException(String JavaDoc message, Throwable JavaDoc cause) {
46         super(message, cause);
47     }
48
49     public void chain(Throwable JavaDoc cause) {
50         chain(null, cause);
51     }
52
53     public void chain(String JavaDoc message, Throwable JavaDoc cause) {
54         if (message == null)
55             exceptions.add(new SystemException(message, cause));
56     }
57
58     public void printStackTrace() {
59         Iterator JavaDoc iterator = exceptions.iterator();
60
61         while (iterator.hasNext()) {
62             Throwable JavaDoc throwable = (Throwable JavaDoc) iterator.next();
63             throwable.printStackTrace();
64         }
65     }
66
67     public void printStackTrace(PrintWriter JavaDoc s) {
68         Iterator JavaDoc iterator = exceptions.iterator();
69
70         while (iterator.hasNext()) {
71             Throwable JavaDoc throwable = (Throwable JavaDoc) iterator.next();
72             throwable.printStackTrace(s);
73         }
74     }
75
76     public void printStackTrace(PrintStream JavaDoc s) {
77         Iterator JavaDoc iterator = exceptions.iterator();
78
79         while (iterator.hasNext()) {
80             Throwable JavaDoc throwable = (Throwable JavaDoc) iterator.next();
81             throwable.printStackTrace(s);
82         }
83     }
84
85     public Throwable JavaDoc getThrowable(int index) {
86         return (Throwable JavaDoc) exceptions.get(index);
87     }
88 }
89
Popular Tags