1 23 24 import org.objectweb.jorm.compiler.lib.JormCompiler; 25 import org.objectweb.jorm.lib.JormConfigurator; 26 import org.objectweb.jorm.compiler.lib.JormCompilerParameter; 27 import org.objectweb.jorm.api.PException; 28 import org.objectweb.util.monolog.api.LoggerFactory; 29 import org.objectweb.util.monolog.api.Logger; 30 import org.objectweb.util.monolog.api.BasicLevel; 31 import org.objectweb.util.monolog.Monolog; 32 33 import java.util.Collection ; 34 35 39 public class JormcRunner { 40 41 static { 42 if (!isAvaillable(JormConfigurator.DEFAULT_JORM_CONFIGURATION_FILE)) { 43 System.out.println("File jormcOpts.properties is not availlable in the classpath"); 44 System.exit(-1); 45 } 46 if (!isAvaillable("jorm.properties")) { 47 System.out.println("File jorm.properties is not availlable in the classpath"); 48 System.exit(-1); 49 } 50 } 51 52 private static boolean isAvaillable(String fileName) { 53 return OneOneBi.class.getClassLoader().getResourceAsStream(fileName)!=null; 54 } 55 56 public JormCompiler compiler = null; 57 public static Logger logger = null; 58 59 public JormcRunner(String projectName, String output) throws PException { 60 compiler = new JormCompiler(); 61 JormCompilerParameter jcp = compiler.getCompilerParameter(); 62 JormConfigurator jcc = compiler.getCompilerConfigurator(); 63 jcc.configure(); 64 jcp.loadConfFile(jcc.getGlobalJormcOptsFile(), jcc.knownMappers()); 65 66 LoggerFactory loggerFactory = Monolog.init("jorm.properties"); 67 jcc.setLoggerFactory(loggerFactory); 68 compiler.setupLogger(); 69 logger = compiler.getCompilerConfigurator().getLoggerFactory() 70 .getLogger("orb.objectweb.jorm.examples.metainfo"); 71 compiler.setupMIManager(); 72 compiler.setupGenerator(); 74 compiler.getCompilerParameter().projectName = projectName; 75 compiler.getCompilerParameter().output = output; 76 Collection c = jcp.getSubMappers("rdb"); 77 logger.log(BasicLevel.DEBUG, "jormcOpts file:" + compiler.getCompilerConfigurator().getJormcOptsFile()); 78 logger.log(BasicLevel.DEBUG, "rdb sub mappers: " + c); 79 } 80 public Collection generate() throws PException { 81 return compiler.generateFiles(compiler.getMIManager().getJormObjects()); 82 } 83 84 public static Exception getInner(Exception e) { 85 if (e instanceof PException 86 && ((PException) e).getNestedException()!=null) { 87 return getInner(((PException) e).getNestedException()); 88 } 89 return e; 90 } 91 } 92 | Popular Tags |