Java 类org.apache.log4j.chainsaw.Main 实例源码

项目:mucke    文件:ConfigurationManager.java   
/**
 * Extracts Run class (property "class") from the run configuration for the current manager.
 *
 * @param propertiesFilename The configuration file of the run
 */
public Run getRunClass(String propertiesFilename) {

    // first re-load properties
    this.loadPrimaryPropoerties();

    Run run = null;

    try {
        // load run configuration
        System.getProperties().load(Main.class.getClassLoader().getResourceAsStream(propertiesFilename));
        // extract Run class
        String runClass = System.getProperties().getProperty("class");

        // instantiate Run class by name (standard constructor)
        //Class<?> clazz = Class.forName(runClass);
        //run = (Run) clazz.newInstance();

        // instantiate Run class by name (non-standard constructor) that associates each run class with its ConfigurationManager
        Class<?> clazz = Class.forName(runClass);
        Constructor constructor = clazz.getConstructor(ConfigurationManager.class);
        run = (Run) constructor.newInstance(this);

    } catch (Exception e) {
        logger.error("Exception while reading and creating Run instance: " + e.getMessage());
        e.printStackTrace();
    }
    return run;
}
项目:mucke    文件:ConfigurationManager.java   
/**
 * Load properties based on system.properties and the secondary.properties file (as set in primiary.properties).
 *
 * @throws Exception if of the property files was not fully loaded
 */
public void loadPrimaryPropoerties() {

    try {

        // load primary properties file
        logger.debug("Loading primary properties...");

        System.getProperties().load(Main.class.getClassLoader().getResourceAsStream("system.properties"));
        logger.info("Primary properties successfully loaded.");

    } catch (Exception e) {

        logger.error("Failed to load 'system.properties' file. Check if it is included in the classpath. Exception: " + e.getMessage());
        e.printStackTrace();

    }
}