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.ehcache_1_3;
06:
07: import com.tc.asm.ClassAdapter;
08: import com.tc.asm.ClassVisitor;
09: import com.tc.asm.MethodAdapter;
10: import com.tc.asm.MethodVisitor;
11: import com.tc.asm.Opcodes;
12: import com.tc.object.bytecode.ClassAdapterFactory;
13:
14: public class EhcacheCacheManagerClassAdapter extends ClassAdapter
15: implements ClassAdapterFactory, Opcodes {
16: public EhcacheCacheManagerClassAdapter() {
17: super (null);
18: }
19:
20: private EhcacheCacheManagerClassAdapter(ClassVisitor cv) {
21: super (cv);
22: }
23:
24: public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
25: return new EhcacheCacheManagerClassAdapter(visitor);
26: }
27:
28: public MethodVisitor visitMethod(int access, String name,
29: String desc, String signature, String[] exceptions) {
30: MethodVisitor mv = super .visitMethod(access, name, desc,
31: signature, exceptions);
32: if ("init".equals(name)
33: && "(Lnet/sf/ehcache/config/Configuration;Ljava/lang/String;Ljava/net/URL;Ljava/io/InputStream;)V"
34: .equals(desc)) {
35: mv = new InitMethodAdapter(mv);
36: }
37: return mv;
38: }
39:
40: private static class InitMethodAdapter extends MethodAdapter
41: implements Opcodes {
42: public InitMethodAdapter(MethodVisitor mv) {
43: super (mv);
44: }
45:
46: public void visitMethodInsn(int opcode, String owner,
47: String name, String desc) {
48: if (INVOKESPECIAL == opcode
49: && "net/sf/ehcache/CacheManager".equals(owner)
50: && "addShutdownHookIfRequired".equals(name)
51: && "()V".equals(desc)) {
52: super.visitInsn(POP);
53: return;
54: } else {
55: super.visitMethodInsn(opcode, owner, name, desc);
56: }
57: }
58: }
59: }
|