/*
 * Copyright 2002-2006 the original author or authors.
 *
 * 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 org.springframework.instrument.classloading;

import java.lang.instrument.ClassFileTransformer;

import org.springframework.core.OverridingClassLoader;

/**
 * Simplistic implementation of an instrumentable ClassLoader.
 * Usable in tests and standalone environments.
 *
 * @author Rod Johnson
 * @author Costin Leau
 * @since 2.0
 */
public class SimpleInstrumentableClassLoader extends OverridingClassLoader  {

	private final WeavingTransformer weavingTransformer;


	/**
	 * Create a new SimpleLoadTimeWeaver for the given class loader.
	 * @param parent the ClassLoader to build an simple instrumentable
	 * ClassLoader for
	 */
	public SimpleInstrumentableClassLoader(ClassLoader parent) {
		super(parent);
		this.weavingTransformer = new WeavingTransformer(parent);
	}


	/**
	 * Add a class file transformer to be applied by this ClassLoader.
	 * @param transformer the class file transformer to register
	 */
	public void addTransformer(ClassFileTransformer transformer) {
		this.weavingTransformer.addTransformer(transformer);
	}


	@Override
	protected byte[] transformIfNecessary(String name, byte[] bytes) {
		return this.weavingTransformer.transformIfNecessary(name, bytes);
	}

}

@@ -21,9 +21,9 @@
 -200
-6
+7
  the
@@ -830,16 +830,22 @@
 entable 
+%3Ccode%3E
 ClassLoa
@@ -847,21 +847,34 @@
 ssLoader
-.%0A * 
+%3C/code%3E.%0A *%0A * %3Cp%3E
 Usable i
@@ -1134,16 +1134,22 @@
 e a new 
+%3Ccode%3E
 SimpleLo
@@ -1160,16 +1160,23 @@
 meWeaver
+%3C/code%3E
  for the
@@ -1185,21 +1185,37 @@
 iven
- c
+%0A%09 * %3Ccode%3EC
 lass
- l
+L
 oader
+%3C/code%3E
 .%0A%09 
@@ -1234,16 +1234,22 @@
 ent the 
+%3Ccode%3E
 ClassLoa
@@ -1251,16 +1251,23 @@
 ssLoader
+%3C/code%3E
  to buil
@@ -1273,16 +1273,19 @@
 ld a
-n
  simple
+%0A%09 *
  ins
@@ -1295,21 +1295,23 @@
 mentable
-%0A%09 * 
+ %3Ccode%3E
 ClassLoa
@@ -1313,16 +1313,23 @@
 ssLoader
+%3C/code%3E
  for%0A%09 *
@@ -1489,28 +1489,32 @@
 * Add a 
-c
+%3Ccode%3EC
 lass
- file t
+FileT
 ransform
@@ -1511,24 +1511,31 @@
 eTransformer
+%3C/code%3E
  to be appli
@@ -1544,17 +1544,27 @@
  by this
- 
+%0A%09 * %3Ccode%3E
 ClassLoa
@@ -1566,16 +1566,23 @@
 ssLoader
+%3C/code%3E
 .%0A%09 * @p
@@ -1606,20 +1606,24 @@
 the 
-c
+%3Ccode%3EC
 lass
- file t
+FileT
 rans
@@ -1628,16 +1628,23 @@
 nsformer
+%3C/code%3E
  to regi

Polishing (while doing [SPR-3062]).