KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > instrument > classloading > SimpleInstrumentableClassLoader


1 /*
2  * Copyright 2002-2006 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.instrument.classloading;
18
19 import java.lang.instrument.ClassFileTransformer JavaDoc;
20
21 import org.springframework.core.OverridingClassLoader;
22
23 /**
24  * Simplistic implementation of an instrumentable ClassLoader.
25  * Usable in tests and standalone environments.
26  *
27  * @author Rod Johnson
28  * @author Costin Leau
29  * @since 2.0
30  */

31 public class SimpleInstrumentableClassLoader extends OverridingClassLoader {
32
33     private final WeavingTransformer weavingTransformer;
34
35
36     /**
37      * Create a new SimpleLoadTimeWeaver for the given class loader.
38      * @param parent the ClassLoader to build an simple instrumentable
39      * ClassLoader for
40      */

41     public SimpleInstrumentableClassLoader(ClassLoader JavaDoc parent) {
42         super(parent);
43         this.weavingTransformer = new WeavingTransformer(parent);
44     }
45
46
47     /**
48      * Add a class file transformer to be applied by this ClassLoader.
49      * @param transformer the class file transformer to register
50      */

51     public void addTransformer(ClassFileTransformer JavaDoc transformer) {
52         this.weavingTransformer.addTransformer(transformer);
53     }
54
55
56     @Override JavaDoc
57     protected byte[] transformIfNecessary(String JavaDoc name, byte[] bytes) {
58         return this.weavingTransformer.transformIfNecessary(name, bytes);
59     }
60
61 }
62
Popular Tags