1 25 26 package org.objectweb.jonas_lib.genbase.generator; 27 28 import java.io.File ; 29 import java.io.FileFilter ; 30 import java.io.IOException ; 31 import java.util.Vector ; 32 33 import org.objectweb.jonas_lib.I18n; 34 import org.objectweb.jonas_lib.genbase.GenBaseException; 35 import org.objectweb.jonas_lib.genbase.archive.Archive; 36 import org.objectweb.jonas_lib.genbase.utils.TempRepository; 37 38 import org.objectweb.jonas.common.Log; 39 40 import org.objectweb.util.monolog.api.BasicLevel; 41 import org.objectweb.util.monolog.api.Logger; 42 43 48 public abstract class AbsGenerator { 49 50 53 private static I18n i18n = I18n.getInstance(AbsGenerator.class); 54 55 58 private static Logger logger = Log.getLogger(Log.JONAS_GENBASE_PREFIX); 59 60 63 private Config config; 64 65 68 private File classes; 69 70 73 private File sources; 74 75 81 public AbsGenerator(Config config) throws GenBaseException { 82 this.config = config; 83 84 TempRepository tr = TempRepository.getInstance(); 86 87 try { 88 sources = tr.createDir(); 89 classes = tr.createDir(); 90 } catch (IOException ioe) { 91 String err = i18n.getMessage("AbsGenerator.constr.ioe"); 92 logger.log(BasicLevel.ERROR, err); 93 throw new GenBaseException(err, ioe); 94 } 95 } 96 97 101 public abstract void generate() throws GenBaseException; 102 103 107 public abstract void compile() throws GenBaseException; 108 109 114 protected void addJavaSources(File src, Vector list) { 115 File [] files = src.listFiles(new FileFilter () { 117 118 public boolean accept(File file) { 119 return file.isFile() && file.getName().endsWith(".java"); 120 } 121 }); 122 123 for (int i = 0; i < files.length; i++) { 124 list.add(files[i]); 125 } 126 127 files = src.listFiles(new FileFilter () { 129 130 public boolean accept(File file) { 131 return file.isDirectory(); 132 } 133 }); 134 135 for (int i = 0; i < files.length; i++) { 136 addJavaSources(files[i], list); 137 } 138 } 139 140 145 public abstract void addFiles(Archive archive) throws GenBaseException; 146 147 150 public Config getConfig() { 151 return config; 152 } 153 154 157 public static Logger getLogger() { 158 return logger; 159 } 160 161 164 public File getClasses() { 165 return classes; 166 } 167 168 171 public File getSources() { 172 return sources; 173 } 174 } | Popular Tags |