KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > SpeedoCompiler


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  * Authors: S.Chassande-Barrioz
25  *
26  */

27
28 package org.objectweb.speedo.generation;
29
30 import org.objectweb.speedo.api.SpeedoException;
31 import org.objectweb.speedo.api.SpeedoProperties;
32 import org.objectweb.speedo.generation.api.GeneratorComponent;
33 import org.objectweb.speedo.generation.api.SpeedoCompilerParameter;
34 import org.objectweb.speedo.generation.compiler.Compiler;
35 import org.objectweb.speedo.generation.enhancer.PersistentClassEnhancer;
36 import org.objectweb.speedo.generation.enhancer.PersistenceAwareEnhancer;
37 import org.objectweb.speedo.generation.enhancer.AroundCompilation;
38 import org.objectweb.speedo.generation.generator.SpeedoGenerator;
39 import org.objectweb.speedo.generation.lib.AbstractGeneratorComponent;
40 import org.objectweb.speedo.generation.parser.JdoParser;
41 import org.objectweb.speedo.generation.jdo.SequenceGenerator;
42 import org.objectweb.speedo.generation.jorm.JormGenerator;
43 import org.objectweb.speedo.generation.mivisitor.MetaInfoVisitors;
44 import org.objectweb.speedo.generation.mivisitor.JMICleanerVisitor;
45 import org.objectweb.speedo.generation.recompiler.UpToDateVisitor;
46 import org.objectweb.speedo.generation.recompiler.Recompiler;
47 import org.objectweb.speedo.generation.serializer.MISerializer;
48 import org.objectweb.util.monolog.api.BasicLevel;
49 import org.objectweb.util.monolog.Monolog;
50
51 import java.util.HashMap JavaDoc;
52
53 /**
54  * TODO: put the file of the meta information into the jar file
55  * @author S.Chassande-Barrioz
56  */

57 public class SpeedoCompiler extends AbstractGeneratorComponent {
58
59     public final static String JavaDoc LOGGER_NAME =
60             SpeedoProperties.LOGGER_NAME + ".generation.SpeedoCompiler";
61
62     public Object JavaDoc[][] actions = null;
63
64     // IMPLEMENTATION OF THE GeneratorComponent INTERFACE //
65
//----------------------------------------------------//
66
public SpeedoCompilerParameter getSpeedoCompilerParameter() {
67         if (scp == null)
68             scp = new SpeedoCompilerParameter();
69         return scp;
70     }
71
72     public boolean init() throws SpeedoException {
73         // Initialize the logger factory if necessary
74
if (scp.loggerFactory == null) {
75             if (scp.logPropFile == null) {
76                 scp.loggerFactory = Monolog.initialize();
77             } else {
78                 scp.loggerFactory = Monolog.getMonologFactory(scp.logPropFile);
79             }
80             logger = scp.loggerFactory.getLogger(LOGGER_NAME);
81         } else if (logger == null) {
82             logger = scp.loggerFactory.getLogger(LOGGER_NAME);
83         }
84         scp.nmf.setLogger(scp.loggerFactory.getLogger(SpeedoProperties.LOGGER_NAME + ".naming"));
85
86         if (actions == null) {
87             actions = new Object JavaDoc[][]{
88                 {new JdoParser(), "Loading jdo files..."},
89                 {new UpToDateVisitor(), "Computing classes requiring enhancement ..."},
90                 {new Recompiler(), "Recompiling classes ..."},
91                 {new MetaInfoVisitors(), "Completing the meta data..."},
92                 {new JormGenerator(), "Generating Jorm files..."},
93                 {new SequenceGenerator(), null},
94                 {new MISerializer(), "Serializing Meta Info..."},
95                 {new SpeedoGenerator(), "Generating Java files..."},
96                 {new JMICleanerVisitor(), null},
97                 {new AroundCompilation(true), null},
98                 {new Compiler JavaDoc(), "Compiling Java files..."},
99                 {new AroundCompilation(false), null},
100                 {new PersistentClassEnhancer(), "Enhancing Persistent classes..."},
101                 {new PersistenceAwareEnhancer(), "Enhancing Persistent aware classes..."}
102             };
103         }
104         scp.setXmldescriptor(new HashMap JavaDoc());
105         return true;
106     }
107
108     public void process() throws SpeedoException {
109         if (scp.jdo.isEmpty())
110             return;
111
112         // Launch the 5 steps of the speedo compiler
113
GeneratorComponent gc = null;
114         boolean run = true;
115         for (int i = 0; i < actions.length && run; i++) {
116             gc = (GeneratorComponent) actions[i][0];
117             gc.setSpeedoCompilerParameter(scp);
118             if (gc.init()) {
119                 if (actions[i][1] != null) {
120                     logger.log(BasicLevel.INFO, actions[i][1]);
121                 }
122                 gc.process();
123             } else {
124                 run = false;
125             }
126             actions[i][0] = null;
127             actions[i][1] = null;
128             System.gc();
129         }
130         logger.log(BasicLevel.INFO, "Done.");
131     }
132 }
133
Popular Tags