01: /*
02: * Copyright 2003,2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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 = new DispatcherGenerator(
24: false);
25: public static final DispatcherGenerator PROXY_REF_INSTANCE = new DispatcherGenerator(
26: true);
27:
28: private static final Type DISPATCHER = TypeUtils
29: .parseType("net.sf.cglib.proxy.Dispatcher");
30: private static final Type PROXY_REF_DISPATCHER = TypeUtils
31: .parseType("net.sf.cglib.proxy.ProxyRefDispatcher");
32: private static final Signature LOAD_OBJECT = TypeUtils
33: .parseSignature("Object loadObject()");
34: private static final Signature PROXY_REF_LOAD_OBJECT = TypeUtils
35: .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,
52: PROXY_REF_LOAD_OBJECT);
53: } else {
54: e.invoke_interface(DISPATCHER, LOAD_OBJECT);
55: }
56: e.checkcast(method.getClassInfo().getType());
57: e.load_args();
58: e.invoke(method);
59: e.return_value();
60: e.end_method();
61: }
62: }
63: }
64:
65: public void generateStatic(CodeEmitter e, Context context,
66: List methods) {
67: }
68: }
|