dtu.ds.warnme.utils.PropertiesUtils.java Source code

Java tutorial

Introduction

Here is the source code for dtu.ds.warnme.utils.PropertiesUtils.java

Source

/**
 * Project:   warnme-server
 * File:      PropertiesUtils.java
 * License: 
 *            This file is licensed under GNU General Public License version 3
 *            http://www.gnu.org/licenses/gpl-3.0.txt
 *
 * Copyright: Bartosz Cichecki [ cichecki.bartosz@gmail.com ]
 * Date:      19-03-2014
 */

package dtu.ds.warnme.utils;

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

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * @author Bartosz Cichecki
 */
public class PropertiesUtils extends PropertyPlaceholderConfigurer {

    private static Map<String, String> PROPERTIES;

    public static String getProperty(String name) {
        return PROPERTIES.get(name);
    }

    private int springSystemPropertiesMode = SYSTEM_PROPERTIES_MODE_FALLBACK;

    @Override
    protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
            throws BeansException {
        super.processProperties(beanFactory, props);

        PROPERTIES = new HashMap<String, String>();
        for (Object key : props.keySet()) {
            String keyStr = key.toString();
            String valueStr = resolvePlaceholder(keyStr, props, springSystemPropertiesMode);
            PROPERTIES.put(keyStr, valueStr);
        }
    }

    @Override
    public void setSystemPropertiesMode(int systemPropertiesMode) {
        super.setSystemPropertiesMode(systemPropertiesMode);
        springSystemPropertiesMode = systemPropertiesMode;
    }
}