configurator.java
来自「一个java 代码生成器」· Java 代码 · 共 148 行
JAVA
148 行
/**
* Copyright (c) 2002, Siddhartha P. Chandurkar siddhartha@visioncodified.com
* All rights reserved.
* Licensed under the Academic Free License version 1.1
* See the file LICENSE.TXT for details.
* LICENSE.txt is located in the directory <install-directory>\Jenerator
* of your Jenertaor Installation.
*
*/
package com.jenerator.util;
//<Imports>
import com.jenerator.struct.ConfigStructs;
import com.jenerator.struct.app.AppConfigStructFiller;
import com.jenerator.struct.ejb.EjbStructFiller;
import com.jenerator.struct.pattern.PatternStructFiller;
import com.jenerator.struct.views.ViewStructFiller;
import org.apache.log4j.Logger;
import java.io.File;
//</Imports>
/**
* Configurator
* This is a singleton class which holds all the configuration parameters needed
* for the application. It is the single place from where all the classes should access
* any type of configurable parameter. It minimizes the need to read the configuration
* file everytime when one needs any value. I call it the <i>Configurator Pattern</i>.
* It uses the GenericXmlParser to parse the XML files
* @author Siddhartha P. Chandurkar
* @version 0.1.o
* @see GenericXmlParser
*
*/
public class Configurator {
//ATTRIBUTES
// The Configurator singleton instance
private static Configurator _instance;
//The jenerator home e.g. C:\app\Jenerator
private String jenHome;
//The datastructure which will contain all the configurations
private ConfigStructs configStructs;
//The log4j logger for this class
private Logger log = Logger.getLogger(com.jenerator.util.Configurator.class.getName());
//CONSTRUCTORS
/**
* Configurator
* It instantiates an empty ConfigStructs data structure
*/
private Configurator() {
configStructs = new ConfigStructs();
}
/**
* getInstance
* Method which returns the singleton instance of the configurator
*/
public static Configurator getInstance() {
if (_instance == null)
_instance = new Configurator();
return _instance;
}
//Get / Set methods
public String getJenHome() {
return jenHome;
}
public void setJenHome(String _jenHome) {
jenHome = _jenHome;
}
public ConfigStructs getConfigStructs() {
return configStructs;
}
/**
* readConfiguration
* This method reads all the XML desriptor files i.e. config.xml and jen-desc.xml
* @param boolean bDesc Whether the Jenerator descriptor file has to be read
*/
public void readConfiguration(ArgumentParser argParser) throws ConfigurationException {
try {
if (argParser.isDesc()) {
GenericXmlParser parser = new GenericXmlParser(new AppConfigStructFiller(), getJenHome() + File.separator + "config" + File.separator + "config.xml");
parser.setRootParseElement("config");
parser.parse();
//Reading the SQL2JAVA Mappings
configStructs.setSql2JavaMappings((new PropertyReader(getJenHome() + File.separator + "config" + File.separator + "SQL2JAVA.properties")).getProperties());
log.debug("READING DONE");
} else if (argParser.isPATTERN()) {
GenericXmlParser parser = new GenericXmlParser(new AppConfigStructFiller(), getJenHome() + File.separator + "config" + File.separator + "config.xml");
parser.setRootParseElement("config");
parser.parse();
parser = new GenericXmlParser(new PatternStructFiller(), getJenHome() + File.separator + "config" + File.separator + "patterns.xml");
parser.setRootParseElement("gof-pattern");
parser.parse();
parser.setRootParseElement("ejb-pattern");
parser.parse();
} else if (argParser.isSERVLET()) {
GenericXmlParser parser = new GenericXmlParser(new AppConfigStructFiller(), getJenHome() + File.separator + "config" + File.separator + "config.xml");
parser.setRootParseElement("config");
parser.parse();
parser = new GenericXmlParser(new ViewStructFiller(), getJenHome() + File.separator + "config" + File.separator + "views.xml");
parser.setRootParseElement("servlet");
parser.parse();
} else {
try {
GenericXmlParser parser = new GenericXmlParser(new AppConfigStructFiller(), getJenHome() + File.separator + "config" + File.separator + "config.xml");
parser.setRootParseElement("config");
parser.parse();
parser = new GenericXmlParser(new EjbStructFiller(), getConfigStructs().getAppConfigStruct().getGenDir() + File.separator + "JEN-INF" + File.separator + "jen-desc.xml");
parser.setRootParseElement("entity");
parser.parse();
parser.setRootParseElement("session");
parser.parse();
parser.setRootParseElement("message-driven-bean");
parser.parse();
} catch (ConfigurationException e) {
log.fatal("The jen-desc.xml file has to be generated before using the options r,b,h,c. \nRun the Jenerator with the -d option first");
throw e;
}
}
} catch (ConfigurationException e) {
log.fatal(e);
throw e;
}
}//readConfiguratin
}//Configurator
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?