01: /*
02: * Copyright 2006 Le Duc Bao, Ralf Joachim
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package org.castor.ddlgen;
17:
18: /**
19: * This class handles the creation for various databse generators.
20: *
21: * @author <a href="mailto:leducbao AT gmail DOT com">Le Duc Bao</a>
22: * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
23: * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
24: * @since 1.1
25: */
26: public final class GeneratorFactory {
27: //--------------------------------------------------------------------------
28:
29: /**
30: * Create DDL Generator for specified database engine with given global and specific
31: * configurations.
32: *
33: * @param engine Database engine.
34: * @param globalConf Global configuration file.
35: * @param specificConf Specific configuration file for database engine.
36: * @return DDL generator for database engine.
37: * @throws GeneratorException If database engine has not been specified or no
38: * generator is available for the database engine.
39: */
40: public static Generator createDDLGenerator(final String engine,
41: final String globalConf, final String specificConf)
42: throws GeneratorException {
43: DDLGenConfiguration config = new DDLGenConfiguration();
44:
45: // load default global configuration
46: config.addProperties(Generator.GLOBAL_CONFIG_PATH
47: + Generator.GLOBAL_CONFIG_NAME);
48: // overload with global configuration given on commandline
49: if (globalConf != null) {
50: config.addProperties(globalConf);
51: }
52:
53: GeneratorRegistry registry = new GeneratorRegistry(config);
54:
55: String eng = config.getStringValue(
56: DDLGenConfiguration.DEFAULT_ENGINE_KEY, "");
57: if (engine != null) {
58: eng = engine;
59: }
60: Generator gen = registry.getGenerator(eng.toLowerCase());
61:
62: // load default configuration for specific database engine
63: config.addProperties(gen.getEngineConfigPath()
64: + gen.getEngineConfigName());
65: // overload with specific configuration given on commandline
66: if (specificConf != null) {
67: config.addProperties(specificConf);
68: }
69:
70: // create key generator registry to be used by the generator
71: gen.setKeyGenRegistry(new KeyGeneratorRegistry(config));
72:
73: // initialize generator
74: gen.initialize();
75:
76: return gen;
77: }
78:
79: //--------------------------------------------------------------------------
80:
81: /**
82: * Hide constructor of utility class.
83: */
84: private GeneratorFactory() {
85: }
86:
87: //--------------------------------------------------------------------------
88: }
|