jenerator.java
来自「一个java 代码生成器」· Java 代码 · 共 115 行
JAVA
115 行
/**
* 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;
//<Imports>
import com.jenerator.transformer.StrategyFactory;
import com.jenerator.transformer.StrategyNotFoundException;
import com.jenerator.transformer.TransformFailedException;
import com.jenerator.transformer.TransformStrategy;
import com.jenerator.util.ArgumentParser;
import com.jenerator.util.ConfigurationException;
import com.jenerator.util.Configurator;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import java.io.File;
import java.util.Vector;
//</Imports>
/**
* Jenerator
* This is the main class of the Jenerator. The responsibility of this class is
* to initialize the Jenerator, parse the command line arguments and invoke
* the respective strategy class, invoke the transform method on the strategies.
*
* @author Siddhartha P. Chandurkar
* @version 0.9.0
*/
public class Jenerator {
//ATTRBUTES
//Log4j's logger
private static Logger log = Logger.getLogger(com.jenerator.Jenerator.class.getName());
//METHODS
/**
* The method should initialize all the things needed of the Jenerator
* to function e.g. It intializes the JEN_HOME, Log4j and dynamically builds
* the java classpath based on the libraries found in lib/ext.
*/
private void init() throws InitializationFailedException {
try {
String jenHome = System.getProperty("JEN_HOME");
if (jenHome == null)
throw new JenHomeNotDefinedException();
Configurator.getInstance().setJenHome(jenHome);
PropertyConfigurator.configure(Configurator.getInstance().getJenHome() + File.separator + "config" + File.separator + "log4j.properties");
log.info("Setting Classpath ... ");
/** This code is for dynamic jar loading of jar from the lib/ext directory.
* This has to be taken care in the next release.
* new LoadResources().makeClasspath();
*/
} catch (Exception e) {
log.fatal("Initialization failed !!! " + e);
throw new InitializationFailedException();
}
}//init()
/**
* main
* The main method of the Application
*/
public static void main(String args[]) {
try {
Jenerator jenerator = new Jenerator();
//Parses the Arguments past to the main through the command line.
ArgumentParser argParser = new ArgumentParser();
argParser.parseArgs(args);
//Initializes the Jenerator.
jenerator.init();
log.info("Jenerator generating ... ");
log.info("Reading Configuration ... ");
Configurator.getInstance().readConfiguration(argParser);
log.info("Configuration reading done");
StrategyFactory stratFact = new StrategyFactory();
//Gets a collection of Strategies depending upon the values set
//in the command line;
Vector strategies = stratFact.getStrategies(argParser);
for (int i = 0; i < strategies.size(); i++)
((TransformStrategy) strategies.elementAt(i)).transform();
log.info("Generation Complete");
} catch (TransformFailedException e) {
e.printStackTrace();
log.error(e, e);
} catch (ConfigurationException e) {
e.printStackTrace();
log.error(e);
} catch (StrategyNotFoundException e) {
e.printStackTrace();
log.error(e);
} catch (Exception e) {
e.printStackTrace();
log.error(e);
}
}//main
}//Jenerator
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?