KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > common > NestedSlideException


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/NestedSlideException.java,v 1.7 2004/07/28 09:38:17 ib Exp $
3  * $Revision: 1.7 $
4  * $Date: 2004/07/28 09:38:17 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.common;
25
26 import java.util.Vector JavaDoc;
27 import java.util.Enumeration JavaDoc;
28
29 /**
30  * Nested Slide exception.
31  *
32  * @version $Revision: 1.7 $
33  */

34 public class NestedSlideException extends SlideException {
35     
36     
37     // ----------------------------------------------------------- Constructors
38

39     
40     /**
41      * Constructor.
42      */

43     public NestedSlideException(String JavaDoc message) {
44         super(message, false);
45         exceptions = new Vector JavaDoc();
46     }
47     
48     
49     // ----------------------------------------------------- Instance Variables
50

51     
52     /**
53      * Vector of exceptions which have been put in this exception.
54      */

55     protected Vector JavaDoc exceptions;
56     
57     
58     // ------------------------------------------------------------- Properties
59

60     
61     /**
62      * Add a new nested exception.
63      *
64      * @param exception Exception to be added
65      */

66     public void addException(SlideException exception) {
67         exceptions.addElement(exception);
68     }
69     
70     
71     /**
72      * Enumerate nested exceptions.
73      *
74      * @return Enumeration nested exceptions list
75      */

76     public Enumeration JavaDoc enumerateExceptions() {
77         return exceptions.elements();
78     }
79     
80     
81     /**
82      * Return the count of nested exceptions.
83      *
84      * @return int count of nested exceptions
85      */

86     public int getExceptionsCount() {
87         return exceptions.size();
88     }
89     
90     
91     
92     /**
93      * Return the count of nested exceptions.
94      *
95      * @return int count of nested exceptions
96      */

97     public SlideException unpackSingleException() {
98         if (getExceptionsCount() != 1) return null;
99         return (SlideException)enumerateExceptions().nextElement();
100     }
101     
102     
103     /**
104      * Returns true if no exceptions have been put in this exception.
105      *
106      * @return boolean
107      */

108     public boolean isEmpty() {
109         return exceptions.isEmpty();
110     }
111     
112     
113     // --------------------------------------------------------- Object Methods
114

115     
116     /**
117      * Displays the exception message.
118      *
119      * @return String exception message
120      */

121     public String JavaDoc toString() {
122         String JavaDoc result = new String JavaDoc();
123         if( exceptions != null ) {
124             Enumeration JavaDoc list = exceptions.elements();
125             while (list.hasMoreElements()) {
126                 SlideException e = (SlideException) list.nextElement();
127                 result = result + e.getMessage() + "\n";
128             }
129         }
130         return result;
131     }
132     
133 }
134
Popular Tags