首页>代码>JAVA web宠物领养信息管理平台,SSH框架,mysql数据库>/chongwu/src/com/nd/listener/ProxoolListener.java
package com.nd.listener;

import java.io.File;
import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.logicalcobwebs.proxool.ProxoolException;
import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
import org.logicalcobwebs.proxool.configuration.PropertyConfigurator;

/**
 * @author wangtao
 */

public class ProxoolListener implements ServletContextListener
{
	private static final Log LOG = LogFactory.getLog(ProxoolListener.class);
    
	private static final String XML_FILE_PROPERTY = "xmlFile";

    private static final String PROPERTY_FILE_PROPERTY = "propertyFile";

    private static final String AUTO_SHUTDOWN_PROPERTY = "autoShutdown";
    
    @SuppressWarnings("unused")
	private boolean autoShutdown = true;
	
    public void contextDestroyed(ServletContextEvent arg0)
	{
		System.out.println("destroy database pool....");
	}

	@SuppressWarnings("rawtypes")
	public void contextInitialized(ServletContextEvent contextEvent)
	{
		ServletContext context = contextEvent.getServletContext(); 
		String appDir = contextEvent.getServletContext().getRealPath("/");
        Properties properties = new Properties();

        Enumeration names = context.getInitParameterNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            String value = context.getInitParameter(name);

            if (name.equals(XML_FILE_PROPERTY)) {
                try {
                    File file = new File(value);
                    if (file.isAbsolute()) {
                        JAXPConfigurator.configure(value, false);
                    } else {
                        JAXPConfigurator.configure(appDir + File.separator + value, false);
                    }
                } catch (ProxoolException e) {
                    LOG.error("Problem configuring " + value, e);
                }
            } else if (name.equals(PROPERTY_FILE_PROPERTY)) {
                try {
                    File file = new File(value);
                    if (file.isAbsolute()) {
                        PropertyConfigurator.configure(value);
                    } else {
                        PropertyConfigurator.configure(appDir + File.separator + value);
                    }
                } catch (ProxoolException e) {
                    LOG.error("Problem configuring " + value, e);
                }
            } else if (name.equals(AUTO_SHUTDOWN_PROPERTY)) {
                autoShutdown = Boolean.valueOf(value).booleanValue();
            } else if (name.startsWith("jdbc")) { 
                properties.setProperty(name, value);
            }
        }

        if (properties.size() > 0) {
            try {
                PropertyConfigurator.configure(properties);
            } catch (ProxoolException e) {
                LOG.error("Problem configuring using init properties", e);
            }
        }
	}

}
最近下载更多
15719908287  LV10 2024年5月30日
sdfddd  LV4 2024年5月16日
FF加菲猫  LV4 2024年2月13日
liuchang183  LV5 2023年12月12日
dj931127  LV4 2023年11月22日
ewan007  LV30 2023年4月7日
neuifgvf  LV2 2023年3月19日
SecretLj  LV3 2023年2月27日
忧麦紫  LV18 2023年2月24日
ningningnn  LV3 2023年2月23日
最近浏览更多
ytxyyay 5月21日
暂无贡献等级
ClintClint  LV1 3月31日
ryadmin123  LV2 2月7日
kiel22  LV2 2024年12月25日
郭宇航裹裹  LV5 2024年12月24日
571818771  LV3 2024年12月17日
微信网友_7293659494813696 2024年12月12日
暂无贡献等级
krispeng  LV15 2024年9月6日
848732002 2024年8月27日
暂无贡献等级
sfzmn_0812 2024年8月12日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友