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: LazyLoadClassAdapter.java 3685 2007-03-08 13:00:42Z gbevin $
07: */
08: package com.uwyn.rife.database.querymanagers.generic.instrument;
09:
10: import static com.uwyn.rife.database.querymanagers.generic.instrument.LazyLoadAccessorsBytecodeTransformer.GQM_VAR_NAME;
11: import static com.uwyn.rife.database.querymanagers.generic.instrument.LazyLoadAccessorsBytecodeTransformer.LAZYLOADED_VAR_NAME;
12:
13: import java.util.Map;
14:
15: import com.uwyn.rife.asm.*;
16:
17: class LazyLoadClassAdapter extends ClassAdapter implements Opcodes {
18: private String mClassName = null;
19: private Map<String, String> mLazyLoadingMethods = null;
20:
21: LazyLoadClassAdapter(Map<String, String> lazyLoadingMethods,
22: ClassVisitor writer) {
23: super (writer);
24:
25: mLazyLoadingMethods = lazyLoadingMethods;
26: }
27:
28: public MethodVisitor visitMethod(int access, String name,
29: String desc, String signature, String[] exceptions) {
30: // retrieve the method from the previously detected lazy loading methods
31: String stored_desc = mLazyLoadingMethods.get(name);
32:
33: // check if it's the same method by comparing the description
34: if (stored_desc != null && stored_desc.equals(desc)) {
35: return new LazyLoadMethodAdapter(mClassName, name, desc,
36: super .visitMethod(access, name, desc, signature,
37: exceptions));
38: }
39:
40: return super .visitMethod(access, name, desc, signature,
41: exceptions);
42: }
43:
44: public void visit(int version, int access, String name,
45: String signature, String super Name, String[] interfaces) {
46: mClassName = name;
47:
48: // add a member variable that will be used to store the GenericQueryManager instance in when the bean instance is retrieved
49: cv
50: .visitField(
51: ACC_PRIVATE | ACC_SYNTHETIC,
52: GQM_VAR_NAME,
53: "Lcom/uwyn/rife/database/querymanagers/generic/GenericQueryManager;",
54: null, null);
55:
56: // add a member variable that will be used to store the lazily loaded values of many to one properties
57: cv.visitField(ACC_PRIVATE | ACC_SYNTHETIC, LAZYLOADED_VAR_NAME,
58: Type.getDescriptor(Map.class), null, null);
59:
60: super.visit(version, access, name, signature, superName,
61: interfaces);
62: }
63: }
|