001: /**
002: * Copyright (C) 2001-2005 France Telecom R&D
003: */package org.objectweb.speedo.generation;
004:
005: import org.objectweb.speedo.ant.AntSpeedoScriptGenerator;
006: import org.objectweb.speedo.api.SpeedoException;
007: import org.objectweb.speedo.api.SpeedoProperties;
008: import org.objectweb.speedo.generation.api.GeneratorComponent;
009: import org.objectweb.speedo.generation.api.SpeedoCompilerParameter;
010: import org.objectweb.speedo.generation.lib.AbstractGeneratorComponent;
011: import org.objectweb.speedo.lib.Personality;
012: import org.objectweb.speedo.metadata.SpeedoDefaults;
013: import org.objectweb.util.monolog.Monolog;
014: import org.objectweb.util.monolog.api.BasicLevel;
015:
016: import java.util.HashMap;
017:
018: /**
019: * Is the global engine of the Speedo enhancer/Compiler. This engine launches
020: * the different steps of the enhancement. Each step is realized by a
021: * GeneratorComponent implementation. This implementation is a GeneratorComponent
022: * itself. The list of used generator component is defined by the abstract
023: * method #getGeneratorComponents()
024: *
025: * @author S.Chassande-Barrioz
026: */
027: public abstract class AbstractEnhancer extends
028: AbstractGeneratorComponent {
029:
030: private final static String LOGGER_NAME = SpeedoProperties.LOGGER_NAME
031: + ".generation.SpeedoCompiler";
032:
033: /**
034: * @return the array of GeneratorComponent class to use. This array defines
035: * the different step of the Speedo enhancer.
036: * @see GeneratorComponent
037: */
038: protected abstract GeneratorComponent[] getGeneratorComponents();
039:
040: public AbstractEnhancer(Personality p) {
041: super (p);
042: }
043:
044: // IMPLEMENTATION OF THE GeneratorComponent INTERFACE //
045: //----------------------------------------------------//
046: public SpeedoCompilerParameter getSpeedoCompilerParameter() {
047: if (scp == null) {
048: scp = new SpeedoCompilerParameter();
049: scp.personality = personality;
050: }
051: return scp;
052: }
053:
054: public boolean init() throws SpeedoException {
055: // Initialize the logger factory if necessary
056: if (scp.loggerFactory == null) {
057: if (scp.logPropFile == null) {
058: scp.loggerFactory = Monolog.initialize();
059: } else {
060: scp.loggerFactory = Monolog
061: .getMonologFactory(scp.logPropFile);
062: }
063: logger = scp.loggerFactory.getLogger(LOGGER_NAME);
064: } else if (logger == null) {
065: logger = scp.loggerFactory.getLogger(LOGGER_NAME);
066: }
067: scp.nmf.setLogger(scp.loggerFactory
068: .getLogger(SpeedoProperties.LOGGER_NAME + ".naming"));
069: scp.setXmldescriptor(new HashMap());
070: SpeedoDefaults.init(scp.personality);
071: return true;
072: }
073:
074: public void process() throws SpeedoException {
075: if (scp.xml.isEmpty())
076: return;
077: long time = System.currentTimeMillis();
078: final GeneratorComponent[] gcs = getGeneratorComponents();
079:
080: // Launch all steps of the speedo compiler
081: boolean run = true;
082: for (int i = 0; i < gcs.length && run; i++) {
083: long actionTime = System.currentTimeMillis();
084: gcs[i].setSpeedoCompilerParameter(scp);
085: if (gcs[i].init()) {
086: final String title = gcs[i].getTitle();
087: if (title != null) {
088: logger.log(BasicLevel.INFO, title);
089: }
090: gcs[i].process();
091: final String summary = gcs[i].getSummary();
092: if (summary != null) {
093: actionTime = System.currentTimeMillis()
094: - actionTime;
095: logger.log(BasicLevel.DEBUG, "=>"
096: + summary
097: + ", "
098: + AntSpeedoScriptGenerator
099: .duration2str(actionTime));
100: }
101: } else {
102: run = false;
103: }
104: }
105: time = System.currentTimeMillis() - time;
106: logger.log(BasicLevel.INFO, "All Done in "
107: + AntSpeedoScriptGenerator.duration2str(time));
108: }
109:
110: }
|