01: package com.uwyn.rife.instrument;
02:
03: import com.uwyn.rife.database.querymanagers.generic.instrument.LazyLoadAccessorsBytecodeTransformer;
04: import com.uwyn.rife.site.instrument.ConstrainedDetector;
05: import com.uwyn.rife.tools.ClassBytesLoader;
06: import java.lang.instrument.IllegalClassFormatException;
07: import java.security.ProtectionDomain;
08:
09: /**
10: * This is a bytecode transformer that will modify classes so that they
11: * receive the functionalities that are required to support lazy-loading
12: * of relationships when the {@code GenericQueryManager} is being used.
13: *
14: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
15: * @version $Revision: 3811 $
16: * @since 1.6
17: */
18: public class LazyLoadTransformer extends RifeTransformer {
19: protected byte[] transformRife(ClassLoader loader,
20: String className, Class<?> classBeingRedefined,
21: ProtectionDomain protectionDomain, byte[] classfileBuffer)
22: throws IllegalClassFormatException {
23: String classname_dotted_interned = className.replace('/', '.')
24: .intern();
25:
26: boolean is_constrained = false;
27:
28: try {
29: is_constrained = new ConstrainedDetector(
30: new ClassBytesLoader(loader)).isConstrained(
31: classname_dotted_interned, classfileBuffer);
32:
33: if (is_constrained) {
34: return LazyLoadAccessorsBytecodeTransformer
35: .addLazyLoadToBytes(classfileBuffer);
36: }
37: } catch (Throwable e) {
38: is_constrained = false;
39: }
40:
41: return classfileBuffer;
42: }
43: }
|