/*
 * Copyright 2002-2007 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.util.Assert;
import org.springframework.util.ClassUtils;

/**
 * LoadTimeWeaver that builds and exposes a {@link SimpleInstrumentableClassLoader}.
 * Mainly intended for testing environments, where it is sufficient to perform
 * all class transformation on a newly created ClassLoader instance.
 *
 * @author Rod Johnson
 * @author Juergen Hoeller
 * @since 2.0
 * @see #getInstrumentableClassLoader()
 * @see SimpleInstrumentableClassLoader
 * @see ReflectiveLoadTimeWeaver
 */
public class SimpleLoadTimeWeaver implements LoadTimeWeaver {

	private final SimpleInstrumentableClassLoader classLoader;


	/**
	 * Create a new SimpleLoadTimeWeaver for the current context class loader.
	 */
	public SimpleLoadTimeWeaver() {
		this.classLoader = new SimpleInstrumentableClassLoader(ClassUtils.getDefaultClassLoader());
	}

	/**
	 * Create a new SimpleLoadTimeWeaver for the given class loader.
	 * @param classLoader the ClassLoader to build an simple instrumentable
	 * ClassLoader on top of
	 */
	public SimpleLoadTimeWeaver(SimpleInstrumentableClassLoader classLoader) {
		Assert.notNull(classLoader, "ClassLoader must not be null");
		this.classLoader = classLoader;
	}


	public void addTransformer(ClassFileTransformer transformer) {
		this.classLoader.addTransformer(transformer);
	}

	public ClassLoader getInstrumentableClassLoader() {
		return this.classLoader;
	}

	/**
	 * This implementation builds a {@link SimpleThrowawayClassLoader}.
	 */
	public ClassLoader getThrowawayClassLoader() {
		return new SimpleThrowawayClassLoader(getInstrumentableClassLoader());
	}

}

@@ -812,16 +812,22 @@
 %0A/**%0A * 
+%3Ccode%3E
 LoadTime
@@ -832,16 +832,23 @@
 meWeaver
+%3C/code%3E
  that bu
@@ -865,16 +865,19 @@
 xposes a
+%0A *
  %7B@link 
@@ -912,17 +912,23 @@
 der%7D.%0A *
- 
+%0A * %3Cp%3E
 Mainly i
@@ -990,16 +990,19 @@
 t to
+%0A *
  perform
 %0A * 
@@ -997,19 +997,16 @@
  perform
-%0A *
  all cla
@@ -1041,17 +1041,26 @@
  created
- 
+%0A * %3Ccode%3E
 ClassLoa
@@ -1062,16 +1062,23 @@
 ssLoader
+%3C/code%3E
  instanc
@@ -1403,32 +1403,38 @@
  * Create a new 
+%3Ccode%3E
 SimpleLoadTimeWe
@@ -1429,32 +1429,39 @@
 leLoadTimeWeaver
+%3C/code%3E
  for the current
@@ -1468,30 +1468,87 @@
  context
- class l
+%0A%09 * %3Ccode%3EClassLoader%3C/code%3E.%0A%09 * @see SimpleInstrumentableClassL
 oader
-.
 %0A%09 */%0A%09p
@@ -1694,24 +1694,30 @@
 reate a new 
+%3Ccode%3E
 SimpleLoadTi
@@ -1724,16 +1724,23 @@
 meWeaver
+%3C/code%3E
  for the
@@ -1749,21 +1749,37 @@
 iven
- c
+%0A%09 * %3Ccode%3EC
 lass
- l
+L
 oader
+%3C/code%3E
 .%0A%09 
@@ -1803,16 +1803,22 @@
 der the 
+%3Ccode%3E
 ClassLoa
@@ -1820,16 +1820,23 @@
 ssLoader
+%3C/code%3E
  to buil
@@ -1842,16 +1842,19 @@
 ld a
-n
  simple
+%0A%09 *
  ins
@@ -1864,21 +1864,23 @@
 mentable
-%0A%09 * 
+ %3Ccode%3E
 ClassLoa
@@ -1882,16 +1882,23 @@
 ssLoader
+%3C/code%3E
  on top 

Polishing (while doing [SPR-3062]).