00001
00026 package org.objectweb.jonas_lib.genbase.generator;
00027
00028 import java.io.File;
00029 import java.io.FileFilter;
00030 import java.io.IOException;
00031 import java.util.Vector;
00032
00033 import org.objectweb.jonas_lib.I18n;
00034 import org.objectweb.jonas_lib.genbase.GenBaseException;
00035 import org.objectweb.jonas_lib.genbase.archive.Archive;
00036 import org.objectweb.jonas_lib.genbase.utils.TempRepository;
00037
00038 import org.objectweb.jonas.common.Log;
00039
00040 import org.objectweb.util.monolog.api.BasicLevel;
00041 import org.objectweb.util.monolog.api.Logger;
00042
00048 public abstract class AbsGenerator {
00049
00053 private static I18n i18n = I18n.getInstance(AbsGenerator.class);
00054
00058 private static Logger logger = Log.getLogger(Log.JONAS_GENBASE_PREFIX);
00059
00063 private Config config;
00064
00068 private File classes;
00069
00073 private File sources;
00074
00081 public AbsGenerator(Config config) throws GenBaseException {
00082 this.config = config;
00083
00084
00085 TempRepository tr = TempRepository.getInstance();
00086
00087 try {
00088 sources = tr.createDir();
00089 classes = tr.createDir();
00090 } catch (IOException ioe) {
00091 String err = i18n.getMessage("AbsGenerator.constr.ioe");
00092 logger.log(BasicLevel.ERROR, err);
00093 throw new GenBaseException(err, ioe);
00094 }
00095 }
00096
00101 public abstract void generate() throws GenBaseException;
00102
00107 public abstract void compile() throws GenBaseException;
00108
00114 protected void addJavaSources(File src, Vector list) {
00115
00116 File[] files = src.listFiles(new FileFilter() {
00117
00118 public boolean accept(File file) {
00119 return file.isFile() && file.getName().endsWith(".java");
00120 }
00121 });
00122
00123 for (int i = 0; i < files.length; i++) {
00124 list.add(files[i]);
00125 }
00126
00127
00128 files = src.listFiles(new FileFilter() {
00129
00130 public boolean accept(File file) {
00131 return file.isDirectory();
00132 }
00133 });
00134
00135 for (int i = 0; i < files.length; i++) {
00136 addJavaSources(files[i], list);
00137 }
00138 }
00139
00145 public abstract void addFiles(Archive archive) throws GenBaseException;
00146
00150 public Config getConfig() {
00151 return config;
00152 }
00153
00157 public static Logger getLogger() {
00158 return logger;
00159 }
00160
00164 public File getClasses() {
00165 return classes;
00166 }
00167
00171 public File getSources() {
00172 return sources;
00173 }
00174 }