01: package org.terracotta.modules.ehcache.commons_1_0;
02:
03: import com.tc.asm.ClassAdapter;
04: import com.tc.asm.ClassVisitor;
05: import com.tc.asm.Label;
06: import com.tc.asm.MethodAdapter;
07: import com.tc.asm.MethodVisitor;
08: import com.tc.asm.Opcodes;
09: import com.tc.object.bytecode.ClassAdapterFactory;
10:
11: public class EhcacheMemoryStoreAdapter extends ClassAdapter implements
12: ClassAdapterFactory, Opcodes {
13: public EhcacheMemoryStoreAdapter() {
14: super (null);
15: }
16:
17: private EhcacheMemoryStoreAdapter(ClassVisitor cv) {
18: super (cv);
19: }
20:
21: public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
22: return new EhcacheMemoryStoreAdapter(visitor);
23: }
24:
25: public MethodVisitor visitMethod(int access, String name,
26: String desc, String signature, String[] exceptions) {
27: MethodVisitor mv = super .visitMethod(access, name, desc,
28: signature, exceptions);
29: if ("create".equals(name)
30: && ("(Lnet/sf/ehcache/Ehcache;Lnet/sf/ehcache/store/DiskStore;)Lnet/sf/ehcache/store/MemoryStore;"
31: .equals(desc) || "(Lnet/sf/ehcache/Ehcache;Lnet/sf/ehcache/store/Store;)Lnet/sf/ehcache/store/MemoryStore;"
32: .equals(desc))) {
33: mv = new MemoryStoreCreateMethodAdapter(mv);
34: }
35: return mv;
36: }
37:
38: private static class MemoryStoreCreateMethodAdapter extends
39: MethodAdapter implements Opcodes {
40:
41: public MemoryStoreCreateMethodAdapter(MethodVisitor mv) {
42: super (mv);
43: }
44:
45: public void visitCode() {
46: super .visitCode();
47:
48: mv.visitVarInsn(ALOAD, 0);
49: mv
50: .visitMethodInsn(INVOKEINTERFACE,
51: "net/sf/ehcache/Ehcache",
52: "getMemoryStoreEvictionPolicy",
53: "()Lnet/sf/ehcache/store/MemoryStoreEvictionPolicy;");
54: mv.visitFieldInsn(GETSTATIC,
55: "net/sf/ehcache/store/MemoryStoreEvictionPolicy",
56: "DSO",
57: "Lnet/sf/ehcache/store/MemoryStoreEvictionPolicy;");
58: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object",
59: "equals", "(Ljava/lang/Object;)Z");
60: Label l1 = new Label();
61: mv.visitJumpInsn(IFEQ, l1);
62: mv.visitTypeInsn(NEW,
63: "net/sf/ehcache/store/TimeExpiryMemoryStore");
64: mv.visitInsn(DUP);
65: mv.visitVarInsn(ALOAD, 0);
66: mv.visitVarInsn(ALOAD, 1);
67: mv
68: .visitMethodInsn(
69: INVOKESPECIAL,
70: "net/sf/ehcache/store/TimeExpiryMemoryStore",
71: "<init>",
72: "(Lnet/sf/ehcache/Ehcache;Lnet/sf/ehcache/store/Store;)V");
73: mv.visitInsn(ARETURN);
74: mv.visitLabel(l1);
75: }
76: }
77: }
|