DefaultEnvironment.java :  » Testing » jacareto » jacareto » system » Java Open Source

Java Open Source » Testing » jacareto 
jacareto » jacareto » system » DefaultEnvironment.java
/*
 * Jacareto Copyright (c) 2002-2005
 * Applied Computer Science Research Group, Darmstadt University of
 * Technology, Institute of Mathematics & Computer Science,
 * Ludwigsburg University of Education, and Computer Based
 * Learning Research Group, Aachen University. All rights reserved.
 *
 * Jacareto is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * Jacareto is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with Jacareto; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

package jacareto.system;


import jacareto.toolkit.HashtableException;

import org.apache.log4j.Logger;

import java.io.File;
import java.io.IOException;

/**
 * An environment with the default Jacareto instances.
 *
 * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
 * @version 1.00
 */
public class DefaultEnvironment extends Environment {
    /**
     * Creates a new default environment.
     */
    public DefaultEnvironment () {
        super();

        Files files = new Files();

        String log4jProperties = files.getDir ("CUSTOMIZATION_DIR").getAbsolutePath () +
            File.separator + "log4j" + File.separator + "default.properties";
        org.apache.log4j.PropertyConfigurator.configure (log4jProperties);

        Logger logger = null;

        try {
            logger = Logger.getLogger ("Jacareto");
        } catch (VerifyError v) {
            System.err.println ("VerifyError    : " + v.getMessage ());
            System.err.println ("Properties File: " + log4jProperties);
            System.exit (1);
        }

        Customization customization = null;
        Language language = null;

        String customizationFilename = files.getDir ("CUSTOMIZATION_DIR").getAbsolutePath () +
            File.separator + "default.xml";

        try {
            customization = new Customization(customizationFilename);
        } catch (IOException i) {
            logger.fatal ("Cannot read customization file: " + customizationFilename);
        }

        try {
            language = new Language(customization,
                    files.getDir ("JACARETO_HOME").getAbsolutePath () + File.separator + "lang",
                    "en", logger);
        } catch (IOException i) {
            logger.fatal ("Cannot read language file!", i);
            System.exit (-1);
        } catch (HashtableException h) {
            logger.fatal ("Error: Cannot find the entry for the chosen language in the language map!",
                h);
            System.exit (-1);
        }

        setCustomization (customization);
        setLanguage (language);
        setLogger (logger);
        setFiles (files);
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.