KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > instrument > classloading > oc4j > OC4JLoadTimeWeaver


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.oc4j;
18
19 import java.lang.instrument.ClassFileTransformer JavaDoc;
20
21 import oracle.classloader.util.ClassLoaderUtilities;
22
23 import org.springframework.instrument.classloading.LoadTimeWeaver;
24 import org.springframework.util.Assert;
25 import org.springframework.util.ClassUtils;
26
27 /**
28  * {@link LoadTimeWeaver} implementation for OC4J's instrumentable ClassLoader.
29  *
30  * <p><b>NOTE:</b> Requires Oracle OC4J version 10.1.3.1 or higher.
31  *
32  * <p>Many thanks to <a HREF="mailto:mike.keith@oracle.com">Mike Keith</a>
33  * for his assistance.
34  *
35  * @author Costin Leau
36  * @since 2.0
37  */

38 public class OC4JLoadTimeWeaver implements LoadTimeWeaver {
39
40     private final ClassLoader JavaDoc classLoader;
41
42
43     /**
44      * Creates a new instance of thie {@link OC4JLoadTimeWeaver} class
45      * using the default {@link ClassLoader class loader}.
46      * @see org.springframework.util.ClassUtils#getDefaultClassLoader()
47      */

48     public OC4JLoadTimeWeaver() {
49         this(ClassUtils.getDefaultClassLoader());
50     }
51     
52     /**
53      * Creates a new instance of the {@link OC4JLoadTimeWeaver} class
54      * using the supplied {@link ClassLoader}.
55      * @param classLoader the <code>ClassLoader</code> to delegate to for weaving (must not be <code>null</code>)
56      * @throws IllegalArgumentException if the supplied <code>ClassLoader</code> is <code>null</code>
57      * @see #getInstrumentableClassLoader()
58      */

59     public OC4JLoadTimeWeaver(ClassLoader JavaDoc classLoader) {
60         Assert.notNull(classLoader, "ClassLoader must not be null");
61         this.classLoader = classLoader;
62     }
63
64
65     public void addTransformer(ClassFileTransformer JavaDoc transformer) {
66         Assert.notNull(transformer, "Transformer must not be null");
67         // Since OC4J 10.1.3's PolicyClassLoader is going to be removed,
68
// we rely on the ClassLoaderUtilities API instead.
69
OC4JClassPreprocessorAdapter processor = new OC4JClassPreprocessorAdapter(transformer);
70         ClassLoaderUtilities.addPreprocessor(this.classLoader, processor);
71     }
72
73     public ClassLoader JavaDoc getInstrumentableClassLoader() {
74         return this.classLoader;
75     }
76
77     public ClassLoader JavaDoc getThrowawayClassLoader() {
78         return ClassLoaderUtilities.copy(this.classLoader);
79     }
80
81 }
82
Popular Tags