01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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: * @author Juergen Hoeller
37: * @since 2.0
38: */
39: public class OC4JLoadTimeWeaver implements LoadTimeWeaver {
40:
41: private final ClassLoader classLoader;
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
56: */
57: public OC4JLoadTimeWeaver(ClassLoader classLoader) {
58: Assert.notNull(classLoader, "ClassLoader must not be null");
59: this .classLoader = classLoader;
60: }
61:
62: public void addTransformer(ClassFileTransformer transformer) {
63: Assert.notNull(transformer, "Transformer must not be null");
64: // Since OC4J 10.1.3's PolicyClassLoader is going to be removed,
65: // we rely on the ClassLoaderUtilities API instead.
66: OC4JClassPreprocessorAdapter processor = new OC4JClassPreprocessorAdapter(
67: transformer);
68: ClassLoaderUtilities.addPreprocessor(this .classLoader,
69: processor);
70: }
71:
72: public ClassLoader getInstrumentableClassLoader() {
73: return this .classLoader;
74: }
75:
76: public ClassLoader getThrowawayClassLoader() {
77: return ClassLoaderUtilities.copy(this.classLoader);
78: }
79:
80: }
|