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: MetaDataCloneableAdapter.java 3678 2007-03-01 10:40:23Z gbevin $
07: */
08: package com.uwyn.rife.site.instrument;
09:
10: import com.uwyn.rife.asm.MethodAdapter;
11: import com.uwyn.rife.asm.MethodVisitor;
12: import com.uwyn.rife.asm.Opcodes;
13:
14: class MetaDataCloneableAdapter extends MethodAdapter implements Opcodes {
15: private String mBaseInternalName = null;
16: private String mMetaDataInternalName = null;
17:
18: MetaDataCloneableAdapter(String baseInternalName,
19: String metaDataInternalName, MethodVisitor visitor) {
20: super (visitor);
21:
22: mBaseInternalName = baseInternalName;
23: mMetaDataInternalName = metaDataInternalName;
24: }
25:
26: public void visitInsn(int opcode) {
27: if (ARETURN == opcode) {
28: mv.visitTypeInsn(CHECKCAST, mBaseInternalName);
29: mv.visitVarInsn(ASTORE, 1);
30:
31: mv.visitVarInsn(ALOAD, 1);
32: mv.visitVarInsn(ALOAD, 0);
33: mv.visitFieldInsn(GETFIELD, mBaseInternalName,
34: MetaDataClassAdapter.DELEGATE_VAR_NAME, "L"
35: + mMetaDataInternalName + ";");
36: mv.visitMethodInsn(INVOKEVIRTUAL, mMetaDataInternalName,
37: "clone", "()Ljava/lang/Object;");
38: mv.visitTypeInsn(CHECKCAST, mMetaDataInternalName);
39: mv.visitFieldInsn(PUTFIELD, mBaseInternalName,
40: MetaDataClassAdapter.DELEGATE_VAR_NAME, "L"
41: + mMetaDataInternalName + ";");
42:
43: mv.visitVarInsn(ALOAD, 1);
44: mv.visitFieldInsn(GETFIELD, mBaseInternalName,
45: MetaDataClassAdapter.DELEGATE_VAR_NAME, "L"
46: + mMetaDataInternalName + ";");
47:
48: mv.visitVarInsn(ALOAD, 1);
49: mv.visitMethodInsn(INVOKEVIRTUAL, mMetaDataInternalName,
50: "setMetaDataBean", "(Ljava/lang/Object;)V");
51:
52: mv.visitVarInsn(ALOAD, 1);
53: }
54:
55: super.visitInsn(opcode);
56: }
57: }
|