package com.ejie.ab39a.util;

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;

/**
 * 
 */
@Component(value = "propertiesUtil")
public class PropertiesUtil extends PropertyPlaceholderConfigurer {

	// properties

	private static Map<String, String> propertiesMap;

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

		super.processProperties(beanFactory, props);
		PropertiesUtil.propertiesMap = new HashMap<String, String>();

		for (Object key : props.keySet()) {

			String keyStr = key.toString();
			PropertiesUtil.propertiesMap.put(keyStr,
					this.resolvePlaceholder(keyStr, props));
		}
	}

	/**
	 * 
	 * @param name
	 *            String
	 * @return String
	 */
	public static String getProperty(String name) {
		return PropertiesUtil.propertiesMap.get(name);
	}

}