1 16 package net.sf.cglib.proxy; 17 18 import java.util.*; 19 import net.sf.cglib.core.*; 20 import org.objectweb.asm.Type; 21 22 class DispatcherGenerator implements CallbackGenerator { 23 public static final DispatcherGenerator INSTANCE = 24 new DispatcherGenerator(false); 25 public static final DispatcherGenerator PROXY_REF_INSTANCE = 26 new DispatcherGenerator(true); 27 28 private static final Type DISPATCHER = 29 TypeUtils.parseType("net.sf.cglib.proxy.Dispatcher"); 30 private static final Type PROXY_REF_DISPATCHER = 31 TypeUtils.parseType("net.sf.cglib.proxy.ProxyRefDispatcher"); 32 private static final Signature LOAD_OBJECT = 33 TypeUtils.parseSignature("Object loadObject()"); 34 private static final Signature PROXY_REF_LOAD_OBJECT = 35 TypeUtils.parseSignature("Object loadObject(Object)"); 36 37 private boolean proxyRef; 38 39 private DispatcherGenerator(boolean proxyRef) { 40 this.proxyRef = proxyRef; 41 } 42 43 public void generate(ClassEmitter ce, Context context, List methods) { 44 for (Iterator it = methods.iterator(); it.hasNext();) { 45 MethodInfo method = (MethodInfo)it.next(); 46 if (!TypeUtils.isProtected(method.getModifiers())) { 47 CodeEmitter e = context.beginMethod(ce, method); 48 context.emitCallback(e, context.getIndex(method)); 49 if (proxyRef) { 50 e.load_this(); 51 e.invoke_interface(PROXY_REF_DISPATCHER, PROXY_REF_LOAD_OBJECT); 52 } else { 53 e.invoke_interface(DISPATCHER, LOAD_OBJECT); 54 } 55 e.checkcast(method.getClassInfo().getType()); 56 e.load_args(); 57 e.invoke(method); 58 e.return_value(); 59 e.end_method(); 60 } 61 } 62 } 63 64 public void generateStatic(CodeEmitter e, Context context, List methods) { } 65 } 66 | Popular Tags |