1 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 ; 52 53 57 public class SpeedoCompiler extends AbstractGeneratorComponent { 58 59 public final static String LOGGER_NAME = 60 SpeedoProperties.LOGGER_NAME + ".generation.SpeedoCompiler"; 61 62 public Object [][] actions = null; 63 64 public SpeedoCompilerParameter getSpeedoCompilerParameter() { 67 if (scp == null) 68 scp = new SpeedoCompilerParameter(); 69 return scp; 70 } 71 72 public boolean init() throws SpeedoException { 73 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 [][]{ 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 (), "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 ()); 105 return true; 106 } 107 108 public void process() throws SpeedoException { 109 if (scp.jdo.isEmpty()) 110 return; 111 112 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 |