01: /*
02: * Copyright 2002-2006 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: * @since 2.0
37: */
38: public class OC4JLoadTimeWeaver implements LoadTimeWeaver {
39:
40: private final ClassLoader classLoader;
41:
42: /**
43: * Creates a new instance of thie {@link OC4JLoadTimeWeaver} class
44: * using the default {@link ClassLoader class loader}.
45: * @see org.springframework.util.ClassUtils#getDefaultClassLoader()
46: */
47: public OC4JLoadTimeWeaver() {
48: this (ClassUtils.getDefaultClassLoader());
49: }
50:
51: /**
52: * Creates a new instance of the {@link OC4JLoadTimeWeaver} class
53: * using the supplied {@link ClassLoader}.
54: * @param classLoader the <code>ClassLoader</code> to delegate to for weaving (must not be <code>null</code>)
55: * @throws IllegalArgumentException if the supplied <code>ClassLoader</code> is <code>null</code>
56: * @see #getInstrumentableClassLoader()
57: */
58: public OC4JLoadTimeWeaver(ClassLoader classLoader) {
59: Assert.notNull(classLoader, "ClassLoader must not be null");
60: this .classLoader = classLoader;
61: }
62:
63: public void addTransformer(ClassFileTransformer transformer) {
64: Assert.notNull(transformer, "Transformer must not be null");
65: // Since OC4J 10.1.3's PolicyClassLoader is going to be removed,
66: // we rely on the ClassLoaderUtilities API instead.
67: OC4JClassPreprocessorAdapter processor = new OC4JClassPreprocessorAdapter(
68: transformer);
69: ClassLoaderUtilities.addPreprocessor(this .classLoader,
70: processor);
71: }
72:
73: public ClassLoader getInstrumentableClassLoader() {
74: return this .classLoader;
75: }
76:
77: public ClassLoader getThrowawayClassLoader() {
78: return ClassLoaderUtilities.copy(this.classLoader);
79: }
80:
81: }
|