|  | 
|  | 1 | +/* | 
|  | 2 | + * Copyright 2002-2014 the original author or authors. | 
|  | 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.springframework.cglib.transform.impl; | 
|  | 18 | + | 
|  | 19 | +import org.springframework.cglib.core.ClassGenerator; | 
|  | 20 | +import org.springframework.cglib.core.DefaultGeneratorStrategy; | 
|  | 21 | +import org.springframework.cglib.core.TypeUtils; | 
|  | 22 | +import org.springframework.cglib.transform.ClassTransformer; | 
|  | 23 | +import org.springframework.cglib.transform.MethodFilter; | 
|  | 24 | +import org.springframework.cglib.transform.MethodFilterTransformer; | 
|  | 25 | +import org.springframework.cglib.transform.TransformingClassGenerator; | 
|  | 26 | + | 
|  | 27 | +/** | 
|  | 28 | + * Memory-safe variant of {@link UndeclaredThrowableStrategy} ported from CGLIB 3.1, | 
|  | 29 | + * introduced for using it in Spring before it was officially released in CGLIB. | 
|  | 30 | + * | 
|  | 31 | + * @author Phillip Webb | 
|  | 32 | + * @since 3.2.4 | 
|  | 33 | + * @deprecated as of Spring 4.0.2, in favor of CGLIB 3.1's default strategy. | 
|  | 34 | + * Kept around for external code depending on it; to be removed in Spring 4.1. | 
|  | 35 | + */ | 
|  | 36 | +@Deprecated | 
|  | 37 | +public class MemorySafeUndeclaredThrowableStrategy extends DefaultGeneratorStrategy { | 
|  | 38 | + | 
|  | 39 | +	private static final MethodFilter TRANSFORM_FILTER = new MethodFilter() { | 
|  | 40 | +		public boolean accept(int access, String name, String desc, String signature, String[] exceptions) { | 
|  | 41 | +			return (!TypeUtils.isPrivate(access) && name.indexOf('$') < 0); | 
|  | 42 | +		} | 
|  | 43 | +	}; | 
|  | 44 | + | 
|  | 45 | + | 
|  | 46 | +	private Class<?> wrapper; | 
|  | 47 | + | 
|  | 48 | + | 
|  | 49 | +	public MemorySafeUndeclaredThrowableStrategy(Class<?> wrapper) { | 
|  | 50 | +		this.wrapper = wrapper; | 
|  | 51 | +	} | 
|  | 52 | + | 
|  | 53 | + | 
|  | 54 | +	protected ClassGenerator transform(ClassGenerator cg) throws Exception { | 
|  | 55 | +		ClassTransformer tr = new UndeclaredThrowableTransformer(wrapper); | 
|  | 56 | +		tr = new MethodFilterTransformer(TRANSFORM_FILTER, tr); | 
|  | 57 | +		return new TransformingClassGenerator(cg, tr); | 
|  | 58 | +	} | 
|  | 59 | + | 
|  | 60 | +} | 
0 commit comments