01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package org.terracotta.modules.hibernate_3_1_2;
06:
07: import com.tc.asm.ClassAdapter;
08: import com.tc.asm.ClassVisitor;
09: import com.tc.asm.Label;
10: import com.tc.asm.MethodVisitor;
11: import com.tc.asm.Opcodes;
12: import com.tc.object.bytecode.ClassAdapterFactory;
13:
14: public class EhcacheClassAdapter extends ClassAdapter implements
15: ClassAdapterFactory, Opcodes {
16: public EhcacheClassAdapter() {
17: super (null);
18: }
19:
20: private EhcacheClassAdapter(ClassVisitor cv) {
21: super (cv);
22: }
23:
24: public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
25: return new EhcacheClassAdapter(visitor);
26: }
27:
28: public MethodVisitor visitMethod(int access, String name,
29: String desc, String signature, String[] exceptions) {
30: if ("destroy".equals(name)
31: && "()V".equals(desc)
32: && exceptions.length == 1
33: && "org/hibernate/cache/CacheException"
34: .equals(exceptions[0])) {
35: recreateDestroyMethod(access, name, desc, signature,
36: exceptions);
37: return null;
38: } else {
39: return super .visitMethod(access, name, desc, signature,
40: exceptions);
41: }
42: }
43:
44: private void recreateDestroyMethod(int access, String name,
45: String desc, String signature, String[] exceptions) {
46: MethodVisitor mv = cv.visitMethod(access, name, desc,
47: signature, exceptions);
48: mv.visitCode();
49: Label l0 = new Label();
50: mv.visitLabel(l0);
51: mv.visitLineNumber(150, l0);
52: mv.visitInsn(RETURN);
53: Label l1 = new Label();
54: mv.visitLabel(l1);
55: mv.visitLocalVariable("this", "Lorg/hibernate/cache/EhCache;",
56: null, l0, l1, 0);
57: mv.visitMaxs(0, 1);
58: mv.visitEnd();
59: }
60: }
|