KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JormcRunner


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

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 JavaDoc;
34
35 /**
36  *
37  * @author S.Chassande-Barrioz
38  */

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 JavaDoc 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 JavaDoc projectName, String JavaDoc 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.setupVerifier(); currently the verifier is not availlable
73
compiler.setupGenerator();
74         compiler.getCompilerParameter().projectName = projectName;
75         compiler.getCompilerParameter().output = output;
76         Collection JavaDoc 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 JavaDoc generate() throws PException {
81         return compiler.generateFiles(compiler.getMIManager().getJormObjects());
82     }
83
84     public static Exception JavaDoc getInner(Exception JavaDoc 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