/*
 * Copyright 2003 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.sf.cglib.transform.impl;

import net.sf.cglib.core.*;
import net.sf.cglib.transform.*;
import org.objectweb.asm.Attribute;

/**
 * A {@link GeneratorStrategy} suitable for use with {@link net.sf.cglib.Enhancer} which
 * causes all undeclared exceptions thrown from within a proxied method to be wrapped
 * in an alternative exception of your choice.
 */
public class UndeclaredThrowableStrategy extends DefaultGeneratorStrategy {
    private ClassTransformer t;

    /**
     * Create a new instance of this strategy.
     * @param wrapper a class which extends either directly or
     * indirectly from <code>Throwable</code> and which has at least one
     * constructor that takes a single argument of type
     * <code>Throwable</code>, for example
     * <code>java.lang.reflect.UndeclaredThrowableException.class</code>
     */
    public UndeclaredThrowableStrategy(Class wrapper) {
        t = new UndeclaredThrowableTransformer(wrapper);
        t = new MethodFilterTransformer(TRANSFORM_FILTER, t);
    }
    
    private static final MethodFilter TRANSFORM_FILTER = new MethodFilter() {
        public boolean accept(int access, String name, String desc, String signature, String[] exceptions) {
            return !TypeUtils.isPrivate(access) && name.indexOf('$') < 0;
        }
    };

    protected ClassGenerator transform(ClassGenerator cg) throws Exception {
        return new TransformingClassGenerator(cg, t);
    }
}


@@ -673,17 +673,30 @@
 ib.core.
-*
+ClassGenerator
 ;%0Aimport
@@ -713,55 +713,322 @@
 lib.
-transform.*;%0Aimport org.objectweb.asm.Attribute
+core.DefaultGeneratorStrategy;%0Aimport net.sf.cglib.core.GeneratorStrategy;%0Aimport net.sf.cglib.core.TypeUtils;%0Aimport net.sf.cglib.transform.ClassTransformer;%0Aimport net.sf.cglib.transform.MethodFilter;%0Aimport net.sf.cglib.transform.MethodFilterTransformer;%0Aimport net.sf.cglib.transform.TransformingClassGenerator
 ;%0A%0A/
@@ -1332,16 +1332,22 @@
 ategy %7B%0A
+    %0A%0A
     priv
@@ -1359,28 +1359,20 @@
 lass
-Transformer t;%0A%0A    
+ wrapper;%0A%0A%09
 /**%0A
@@ -1801,118 +1801,30 @@
     
- t = new UndeclaredThrowableTransformer(wrapper);%0A        t = new MethodFilterTransformer(TRANSFORM_FILTER, t)
+this.wrapper = wrapper
 ;%0A  
@@ -2188,16 +2188,156 @@
 ption %7B%0A
+    %09 ClassTransformer   tr = new UndeclaredThrowableTransformer(wrapper);%0A         tr = new MethodFilterTransformer(TRANSFORM_FILTER, tr);%0A
         
@@ -2379,16 +2379,17 @@
 or(cg, t
+r
 );%0A    %7D

fix memory leak