KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > protoactive > core > mop > StubCodeGenerator


1 /***
2  * Julia: France Telecom's implementation of the Fractal API
3  * Copyright (C) 2001-2002 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: Eric.Bruneton@rd.francetelecom.com
20  *
21  * Author: Eric Bruneton
22  */

23
24 package protoactive.core.mop;
25
26 import org.objectweb.fractal.julia.asm.MetaCodeGenerator;
27
28 /**
29  * A {@link CodeGenerator CodeGenerator} to generate interception code that
30  * reifies method calls and pass them to the MetaObject interface of the
31  * component. More precisely, the interception code generated for a method m:
32  * <pre>
33  * int m (int i, String s) {
34  * // original code
35  * }
36  * </pre>
37  * is the following:
38  * <pre>
39  * int m (int i, String s) {
40  * if (!AbstractMetaObject.isReflectedCall()) {
41  * return ((Integer)mo.handleMethodCall(new MethodCall(
42  * "I",
43  * "m",
44  * "(ILjava/lang/String;)I",
45  * new Object[] {new Integer(i), s}))).intValue();
46  * } else {
47  * // original code
48  * }
49  * }
50  * </pre>
51  * The {@link #generateInitCode generateInitCode} method generates code blocks
52  * of the following form:
53  * <pre>
54  * mo = (...)ic.getInterface("/meta-object");
55  * </pre>
56  * where <tt>mo</tt> is a field added to the class that is being generated (in
57  * fact, if the controller and interceptor classes are merged (see {@link
58  * InterceptorClassGenerator InterceptorClassGenerator}), the <tt>mo</tt> field
59  * is not generated and replaced by <tt>this</tt> in the above code).
60  */

61
62 public class StubCodeGenerator extends MetaCodeGenerator {
63
64   protected String JavaDoc getControllerInterfaceName () {
65     return "/meta-object";
66   }
67
68   protected String JavaDoc getHandleMethodCallMethodName () {
69     return "handleMethodCall";
70   }
71
72   protected boolean reifyInterfaceName () {
73     return true;
74   }
75
76   protected boolean reifyTargetObject () {
77     return true;
78   }
79
80   protected String JavaDoc getIsReflectedCallMethodName () {
81     return "isReflectedCall";
82   }
83 }
84
Popular Tags