view gnv/src/main/java/de/intevation/gnv/propertiesreader/PropertiesReaderFactory.java @ 1022:28a0628b11b0

Added license file and license header. gnv/trunk@1258 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 02 Nov 2010 17:15:08 +0000
parents 89ade245ca7a
children
line wrap: on
line source
/*
 * Copyright (c) 2010 by Intevation GmbH
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LGPL.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 */

package de.intevation.gnv.propertiesreader;

import java.util.Map;

import javax.servlet.ServletConfig;

import org.apache.log4j.Logger;

/**
 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
 *
 */
public class PropertiesReaderFactory {

    /**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = Logger.getLogger(PropertiesReaderFactory.class);

    /**
     * The singleton Instance of this Factory.
     */
    private static PropertiesReaderFactory instance = null;

    /**
     * The ConnectionPool providing the Connections to the DatabaseBackends
     */
    private PropertiesReader propertiesReader = null;

    /**
     * Constructor
     */
    private PropertiesReaderFactory() {
        super();
    }

    /**
     * This Method provides an singleton Instance of this Class.
     *
     * @return an singleton Instance of this Class
     */
    public static PropertiesReaderFactory getInstance() {
        if (instance == null) {
            instance = new PropertiesReaderFactory();
        }
        return instance;
    }

    /**
     * Getting the ConnectionPool
     *
     * @return the ConnectionPool
     */
    public PropertiesReader getPropertiesReader() {
        return this.propertiesReader;
    }

    /**
     * Getting the ConnectionPool
     *
     * @param config The Config that should be read
     */
    public void initPropertiesReader(Object config) {
        if (config instanceof ServletConfig) {
            this.propertiesReader = new ServletPropertiesReader(
                    (ServletConfig) config);
        } else if (config instanceof Map) {
            this.propertiesReader = new MapPropertiesReader(
                    (Map<String, String>) config);
        } else {
            log.error("No PropertiesReader for Instance "
                      + config.getClass().getName());
        }

    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org