package cn.base.listener;

import javax.servlet.ServletContextEvent;

import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.log4j.Logger;
import cn.aleader.MainPoint;
import cn.base.bean.BeanHelper;
import cn.bsystem.ptmenu.util.MenuXml;

public class MySpringListener extends org.springframework.web.context.ContextLoaderListener{
	static Logger logger = Logger.getLogger(MySpringListener.class);
	public void contextInitialized(ServletContextEvent event){
		MenuXml.getInstance().parseMenuXml();
        super.contextInitialized(event);
        boolean ret= true;//ChangeConf.changConfXml();
        try {  
        	if(ret==true){
        		BasicDataSource basicDS = (BasicDataSource) BeanHelper.getBean("dataSource");   
        		//basicDS.close();
//        		basicDS.setDriverClassName(BeanHelper.getModuleConfFactory().getDb().getDriverClassName());
//        		basicDS.setUrl(BeanHelper.getModuleConfFactory().getDb().getUrl());
//        	    basicDS.setUsername(BeanHelper.getModuleConfFactory().getDb().getUserName());
//        	    basicDS.setPassword(BeanHelper.getModuleConfFactory().getDb().getPassword());
//        	    basicDS.setInitialSize(BeanHelper.getModuleConfFactory().getDb().getInitialSize());
//        	    basicDS.setMinIdle(BeanHelper.getModuleConfFactory().getDb().getMinIdle());
//        	    basicDS.setMaxIdle(BeanHelper.getModuleConfFactory().getDb().getMaxIdle());
//        	    //basicDS.setMaxTotal(BeanHelper.getModulePropsService().getDataBase().getMaxActive());
//        	    //basicDS.setRemoveAbandonedOnBorrow(BeanHelper.getModulePropsService().getDataBase().getRemoveAbandoned());
//        	    basicDS.setRemoveAbandonedTimeout(BeanHelper.getModuleConfFactory().getDb().getRemoveAbandonedTimeout());
//        	    basicDS.setLogAbandoned(BeanHelper.getModuleConfFactory().getDb().getLogAbandoned());
//        	    basicDS.setValidationQuery("SELECT 1 from dual"); //oracle
//        	    //basicDS.setValidationQuery("SELECT 1");
//        	    basicDS.setTestOnBorrow(false);
//        	    basicDS.setTimeBetweenEvictionRunsMillis(300000);
//        	    basicDS.setMinEvictableIdleTimeMillis(1800000);
        	    /**/
        	    //System.out.println("=========getUrl================="+BeanHelper.getModulePropsService().getDataBase().getUrl());
        	}
        	MainPoint.init();        	
        } catch (Exception e) {   
        	//logger.error(TinyHelper.getStackTraceAsString(e));
        }   
    }
	
}
