01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.system.main;
17:
18: import java.util.ArrayList;
19:
20: /**
21: * @version $Rev: 513482 $ $Date: 2007-03-01 12:19:42 -0800 (Thu, 01 Mar 2007) $
22: */
23: public class ExceptionUtil {
24:
25: private static final String[] excludedPackages = {
26: "org.apache.geronimo.gbean.jmx.", "net.sf.cglib.reflect.",
27: "sun.reflect." };
28:
29: private static final String[] excludedStrings = {
30: "$$EnhancerByCGLIB$$", "$$FastClassByCGLIB$$" };
31:
32: public static void trimStackTrace(Throwable t) {
33: if (t == null) {
34: return;
35: }
36:
37: StackTraceElement[] trace = t.getStackTrace();
38: ArrayList list = new ArrayList();
39:
40: boolean skip = true;
41:
42: int i = 0;
43:
44: // If the start of the stack trace is something
45: // on the exclude list, don't exclude it.
46: for (; i < trace.length && skip; i++) {
47: skip = skip && isExcluded(trace[i].getClassName());
48: }
49: list.add(trace[i - 1]);
50:
51: for (; i < trace.length; i++) {
52: if (!isExcluded(trace[i].getClassName())) {
53: list.add(trace[i]);
54: }
55: }
56:
57: t.setStackTrace((StackTraceElement[]) list
58: .toArray(new StackTraceElement[0]));
59: trimStackTrace(t.getCause());
60: }
61:
62: private static boolean isExcluded(String className) {
63: for (int j = 0; j < excludedPackages.length; j++) {
64: if (className.startsWith(excludedPackages[j])) {
65: return true;
66: }
67: }
68: for (int j = 0; j < excludedStrings.length; j++) {
69: if (className.indexOf(excludedStrings[j]) != -1) {
70: return true;
71: }
72: }
73: return false;
74: }
75: }
|