All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.veraxsystems.vxipmi.common.PropertiesManager Maven / Gradle / Ivy

The newest version!
package com.veraxsystems.vxipmi.common;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.apache.log4j.Logger;

public final class PropertiesManager {

    private static PropertiesManager instance;

    private Map properties;

    private Logger logger = Logger.getLogger(PropertiesManager.class);

    private PropertiesManager() {
        properties = new HashMap();

        loadProperties("/connection.properties");
        loadProperties("/vxipmi.properties");
    }

    public static PropertiesManager getInstance() {
        if (instance == null) {
            instance = new PropertiesManager();
        }
        return instance;
    }

    private void loadProperties(String name) {
        try {
            Properties props = new Properties();
            props.load(getClass().getResourceAsStream(name));

            for (Object key : props.keySet()) {
                this.properties.put(key.toString(), props.getProperty(key.toString()));
            }

        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }

    public String getProperty(String key) {
        logger.info("Getting " + key + ": " + properties.get(key));
        return properties.get(key);
    }

    public void setProperty(String key, String value) {
        properties.put(key, value);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy