01: /**************************************************************************************
02: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package org.codehaus.aspectwerkz.util;
08:
09: import java.util.List;
10: import java.util.ArrayList;
11: import java.util.Iterator;
12:
13: /**
14: * Utility methods for dealing with stack traces.
15: *
16: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
17: */
18: public final class StackTraceHelper {
19:
20: /**
21: * Removes the AspectWerkz specific elements from the stack trace.
22: *
23: * @param exception the Throwable to modify the stack trace on
24: * @param className the name of the fake origin class of the exception
25: */
26: public static void hideFrameworkSpecificStackTrace(
27: final Throwable exception, final String className) {
28: if (exception == null) {
29: throw new IllegalArgumentException(
30: "exception can not be null");
31: }
32: if (className == null) {
33: throw new IllegalArgumentException(
34: "class name can not be null");
35: }
36: final List newStackTraceList = new ArrayList();
37: final StackTraceElement[] stackTrace = exception
38: .getStackTrace();
39: int i;
40: for (i = 1; i < stackTrace.length; i++) {
41: if (stackTrace[i].getClassName().equals(className)) {
42: break;
43: }
44: }
45: for (int j = i; j < stackTrace.length; j++) {
46: newStackTraceList.add(stackTrace[j]);
47: }
48: final StackTraceElement[] newStackTrace = new StackTraceElement[newStackTraceList
49: .size()];
50: int k = 0;
51: for (Iterator it = newStackTraceList.iterator(); it.hasNext(); k++) {
52: final StackTraceElement element = (StackTraceElement) it
53: .next();
54: newStackTrace[k] = element;
55: }
56: exception.setStackTrace(newStackTrace);
57: }
58: }
|