KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > util > ExceptionList


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

18 package org.apache.geronimo.interop.util;
19
20 import java.lang.reflect.Constructor JavaDoc;
21 import java.lang.reflect.Method JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25
26 public class ExceptionList extends ArrayList JavaDoc {
27     public ExceptionList() {
28     }
29
30     public ExceptionList(Constructor JavaDoc template) {
31         Class JavaDoc[] types = template.getExceptionTypes();
32         add(types);
33     }
34
35     public ExceptionList(Method JavaDoc template) {
36         Class JavaDoc[] types = template.getExceptionTypes();
37         add(types);
38     }
39
40     public ExceptionList(Class JavaDoc[] types) {
41         add(types);
42     }
43
44     public void add(Class JavaDoc[] types) {
45         int n = types.length;
46         for (int i = 0; i < n; i++) {
47             Class JavaDoc type = types[i];
48             if (ExceptionUtil.isUserException(type)) {
49                 add(type);
50             }
51         }
52     }
53
54     public ExceptionList add(String JavaDoc type) {
55         super.add(type);
56         return this;
57     }
58
59     public ExceptionList add(Class JavaDoc type) {
60         return add(JavaType.getName(type));
61     }
62
63     public String JavaDoc toString() {
64         if (size() == 0) {
65             return "";
66         }
67         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(" throws ");
68         int comma = 0;
69         for (Iterator JavaDoc i = iterator(); i.hasNext(); comma++) {
70             String JavaDoc type = (String JavaDoc) i.next();
71             if (comma > 0) {
72                 sb.append(", ");
73             }
74             sb.append(type);
75         }
76         return sb.toString();
77     }
78 }
79
Popular Tags