KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > fortress > util > CompositeException


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.avalon.fortress.util;
18
19 import org.apache.avalon.framework.CascadingException;
20
21 /**
22  * This is an exception made up of one or more subexceptions.
23  */

24 public final class CompositeException extends CascadingException
25 {
26     private final Exception JavaDoc[] m_ex;
27     private final String JavaDoc m_message;
28
29     public CompositeException( final Exception JavaDoc[] ex )
30     {
31         this( ex, null );
32     }
33
34     public CompositeException( final Exception JavaDoc[] ex, final String JavaDoc message )
35     {
36         super( message, null );
37         m_ex = ex;
38         if ( ex == null || ex.length < 1 )
39         {
40             throw new IllegalArgumentException JavaDoc( "you must specify a contained exception!" );
41         }
42         if ( message == null )
43         {
44             final StringBuffer JavaDoc msg = new StringBuffer JavaDoc();
45             for ( int i = 0; i < ex.length; i++ )
46             {
47                 if (i > 0) msg.append('\n');
48                 msg.append( ex[i].getMessage() );
49             }
50             m_message = msg.toString();
51         }
52         else
53             m_message = message;
54     }
55
56     public String JavaDoc getMessage()
57     {
58         return m_message;
59     }
60
61     public Exception JavaDoc[] getExceptions()
62     {
63         return m_ex;
64     }
65 }
66
Popular Tags