package com.winsun.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;


/**
 * 加载系统配置
 * @author czl
 * @date 2014-3-21
 */
@Slf4j
public class PropertiesInit {

	private static boolean initFlag = false;
	/**
	 * 系统配置保存集合
	 */
	private static Map<String, String> propertiesMap = null;
	
	/**
	 * 初始化系统配置
	 */
	public static synchronized void initProperties(){
		if(initFlag){
			return;
		}
		log.info("initProperties..");
		initFlag  = true;
		propertiesMap = new HashMap<String, String>();
		String[] pros = new String[]{"/META-INF/config/application.properties", "/META-INF/config/zjinfoDetail.properties"};
		
		Set<Map.Entry<Object, Object>>  set = null;
		Iterator<Map.Entry<Object, Object>> itr = null;
		Map.Entry<Object, Object>  obj = null;
		String tempkey = null;
		String tempValue = null;
		for (int i = 0; i < pros.length; i++) {
			set = CommonPropertiesUtil.getEntrySet(pros[i]);
	    	itr = set.iterator();
	    	while(itr.hasNext()){
	    		obj = itr.next();
	    		tempkey = (String)obj.getKey();
	    		tempValue = (String)obj.getValue();
	    		propertiesMap.put(tempkey, tempValue);
	    	}
		}
	}
	
	/**
	 * 获取系统配置值
	 * @param key
	 * @return
	 */
	public static String getProperties(String key){
		return propertiesMap.get(key);
	}
	
	public static void main(String[] args) {
		initProperties();
		log.info(getProperties("cookieMaxAge"));
	}

}
