KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > enhancer > InheritanceModifier


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

18 package org.objectweb.speedo.generation.enhancer;
19
20 import org.objectweb.asm.ClassVisitor;
21 import org.objectweb.util.monolog.api.Logger;
22 import org.objectweb.util.monolog.api.BasicLevel;
23 import org.objectweb.speedo.metadata.SpeedoClass;
24 import org.objectweb.speedo.generation.lib.NamingRules;
25
26 /**
27  * Modify the inheritance in order to permit the compilation.
28  * Before the compilation the parent of the children classes (classes
29  * inheriting from another persistent class) are setting to the Parent proxy
30  * class. After the compilation the inheritance link is coming back to the
31  * real class.<br/>
32  * ex: Kangaroo extends Animal <br/>
33  * Action before the compilation: Kangaroo extends AnimalProxy <br/>
34  * Action after the compilation: Kangaroo extends Animal <br/>
35  *
36  * @author S.Chassande-Barrioz
37  */

38 public class InheritanceModifier extends LoggedClassAdapter {
39
40     /**
41      * The name of the new super class claculated with the meta information.
42      * A null value means that the inheritance does not change.
43      */

44     private String JavaDoc newSuperClassName;
45
46     public InheritanceModifier(ClassVisitor classVisitor,
47                                Logger logger,
48                                SpeedoClass sc,
49                                boolean beforeCompilation) {
50         super(classVisitor, logger);
51         if (sc.superClassName != null
52                 && sc.superClassName.length() > 0) {
53             newSuperClassName = (beforeCompilation
54                     ? NamingRules.proxyName(sc.superClassName)
55                     : sc.superClassName);
56             newSuperClassName = newSuperClassName.replace('.','/');
57         } else {
58             newSuperClassName = null;
59         }
60         if (debug) {
61             logger.log(BasicLevel.DEBUG, "Inheritance modifier of the class "
62                 + sc.getFQName() + ": newSuperClassName=" + newSuperClassName);
63         }
64     }
65
66     public void visit(final int version, final int access,
67                       final String JavaDoc name,
68                       final String JavaDoc superName,
69                       final String JavaDoc[] interfaces,
70                       final String JavaDoc sourceFile) {
71         String JavaDoc inherit = (newSuperClassName == null
72                 ? superName : newSuperClassName);
73         if (debug) {
74             logger.log(BasicLevel.DEBUG, "InheritanceModifier.visit("
75                     + name + ", " + superName + "): " + inherit);
76         }
77         super.visit(version, access, name, inherit, interfaces, sourceFile);
78     }
79 }
80
Popular Tags