01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: RifeTransformer.java 3811 2007-06-25 15:06:16Z gbevin $
07: */
08: package com.uwyn.rife.instrument;
09:
10: import java.lang.instrument.ClassFileTransformer;
11: import java.lang.instrument.IllegalClassFormatException;
12: import java.security.ProtectionDomain;
13:
14: /**
15: * An abstract base class that will only execute the bytecode transformation
16: * when the class is considered to not be part of a core package, like for
17: * example the JDK or the standard XML parsers.
18: *
19: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
20: * @version $Revision: 3811 $
21: * @since 1.6
22: */
23: abstract public class RifeTransformer implements ClassFileTransformer {
24: final public byte[] transform(ClassLoader loader, String className,
25: Class<?> classBeingRedefined,
26: ProtectionDomain protectionDomain, byte[] classfileBuffer)
27: throws IllegalClassFormatException {
28: if (className.startsWith("java/")
29: || className.startsWith("javax/")
30: || className.startsWith("com/sun/")
31: || className.startsWith("sun/")
32: || className.startsWith("org/apache/")
33: || className.startsWith("org/xml/")
34: || className.startsWith("org/w3c/")
35: || (className.startsWith("com/uwyn/rife/") && !className
36: .startsWith("com/uwyn/rife/continuations/Test"))
37: || className.startsWith("com/tc/")) {
38: return classfileBuffer;
39: }
40:
41: return transformRife(loader, className, classBeingRedefined,
42: protectionDomain, classfileBuffer);
43: }
44:
45: /**
46: * This transform method will only be called when the class is not part of
47: * a core package.
48: * <p>For the rest it functions exactly as the regular
49: * {@code transform} method.
50: *
51: * @see #transform
52: * @since 1.6
53: */
54: abstract protected byte[] transformRife(ClassLoader loader,
55: String className, Class<?> classBeingRedefined,
56: ProtectionDomain protectionDomain, byte[] classfileBuffer)
57: throws IllegalClassFormatException;
58: }
|