package com.ejie.m62fb.utils.properties;

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;
import org.springframework.stereotype.Component;

/**
 * Clase de utilidades para el acceso al fichero 'm62fb.properties'.
 * 
XXXX
 * 
 */
@Component(value = "appProperties")
public class UtilProperties extends PropertyPlaceholderConfigurer {

	private static Map<String, String> propertiesMap;

	@Override
	protected void processProperties(
			ConfigurableListableBeanFactory beanFactory, Properties props)
			throws BeansException {
		super.processProperties(beanFactory, props);
		UtilProperties.propertiesMap = new HashMap<String, String>();
		for (Object key : props.keySet()) {
			String keyStr = key.toString();
			UtilProperties.propertiesMap.put(keyStr, props.getProperty(keyStr));
		}
	}

	/**
	 * Obtiene el valor de una propiedad definida en el fichero
	 * 'm62fb.properties'.
	 * 
	 * @param name
	 *            String
	 * @return String
	 */
	public static String getProperty(String name) {
		return UtilProperties.propertiesMap.get(name);
	}
}