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: MetaDataDefaultConstructorAdapter.java 3678 2007-03-01 10:40:23Z gbevin $
07: */
08: package com.uwyn.rife.site.instrument;
09:
10: import com.uwyn.rife.asm.*;
11: import com.uwyn.rife.site.MetaDataBeanAware;
12:
13: class MetaDataDefaultConstructorAdapter extends MethodAdapter implements
14: Opcodes {
15: private String mBaseInternalName = null;
16: private String mMetaDataInternalName = null;
17:
18: MetaDataDefaultConstructorAdapter(String baseInternalName,
19: String metaDataInternalName, MethodVisitor visitor) {
20: super (visitor);
21:
22: mBaseInternalName = baseInternalName;
23: mMetaDataInternalName = metaDataInternalName;
24: }
25:
26: public void visitMethodInsn(int opcode, String owner, String name,
27: String desc) {
28: super .visitMethodInsn(opcode, owner, name, desc);
29:
30: if (INVOKESPECIAL == opcode && "<init>".equals(name)
31: && "()V".equals(desc)) {
32: mv.visitVarInsn(ALOAD, 0);
33: mv.visitTypeInsn(NEW, mMetaDataInternalName);
34: mv.visitInsn(DUP);
35: mv.visitMethodInsn(INVOKESPECIAL, mMetaDataInternalName,
36: "<init>", "()V");
37: mv.visitFieldInsn(PUTFIELD, mBaseInternalName,
38: MetaDataClassAdapter.DELEGATE_VAR_NAME, "L"
39: + mMetaDataInternalName + ";");
40:
41: mv.visitVarInsn(ALOAD, 0);
42: mv.visitFieldInsn(GETFIELD, mBaseInternalName,
43: MetaDataClassAdapter.DELEGATE_VAR_NAME, "L"
44: + mMetaDataInternalName + ";");
45: mv.visitTypeInsn(INSTANCEOF, Type
46: .getInternalName(MetaDataBeanAware.class));
47: Label not_aware = new Label();
48: mv.visitJumpInsn(IFEQ, not_aware);
49: mv.visitVarInsn(ALOAD, 0);
50: mv.visitFieldInsn(GETFIELD, mBaseInternalName,
51: MetaDataClassAdapter.DELEGATE_VAR_NAME, "L"
52: + mMetaDataInternalName + ";");
53: mv.visitTypeInsn(CHECKCAST, Type
54: .getInternalName(MetaDataBeanAware.class));
55: mv.visitVarInsn(ALOAD, 0);
56: mv.visitMethodInsn(INVOKEINTERFACE, Type
57: .getInternalName(MetaDataBeanAware.class),
58: "setMetaDataBean", "(Ljava/lang/Object;)V");
59: mv.visitLabel(not_aware);
60: }
61: }
62: }
|