⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultwebconfig.java

📁 一个简单的java邮件系统源码
💻 JAVA
字号:
package com.easyjf.web.config;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import com.easyjf.util.StringUtils;
import com.easyjf.web.Module;
import com.easyjf.web.WebConfig;

/**
 * 
 * <p>
 * Title:配置信息
 * </p>
 * <p>
 * Description:调用配置信息处理类,处理并存放easyjf-web.xml中的配置信息
 * </p>
 * <p>
 * Copyright:Copyright (c) 2006
 * </p>
 * <p>
 * Company: www.easyjf.com
 * </p>
 * 
 * @author 蔡世友
 * @version 1.0
 */
public class DefaultWebConfig implements WebConfig {
	private final Map modules = new HashMap();

	private final Map forms = new HashMap();

	private final Map pages = new HashMap();

	private final List initApps = new ArrayList();

	private final Map interceptors = new HashMap();

	private final Map errorHandler = new HashMap();

	private List beanDefinitions = new ArrayList();

	private List configManagers=new ArrayList();
	private String templateBasePath;

	private boolean debug = false;

	private int maxUploadFileSize = 1024 * 1024 * 5;

	private int uploadSizeThreshold = 1024 * 30;

	private java.io.InputStream[] configures;

	private static final Logger logger = Logger
			.getLogger(DefaultWebConfig.class);

	public DefaultWebConfig() {
		configManagers.add(com.easyjf.web.ajax.AjaxConfigManager.getInstance());
	}

	public void init() {
		//清空配置信息 
		modules.clear();
		forms.clear();
		pages.clear();
		initApps.clear();
		interceptors.clear();
		errorHandler.clear();
		beanDefinitions.clear();
		templateBasePath = "";
		try {
			logger.info("系统初始化!");
			for (int k = 0; k < configures.length; k++) {
				java.io.BufferedInputStream is=new java.io.BufferedInputStream(configures[k]);
				IConfigFactory icf = new XMLConfigFactory(is);// (IConfigFactory)																			// Class.forName(
				// Globals.CONFIG_FACTORY_CLASS).newInstance();
				//高用配置工厂方法
				icf.initForm(forms);//表单
				icf.initModule(modules);//模块
				icf.initPage(pages);//页面模块配置
				Map map = icf.initOther();//基本配置信息
				if (map != null) {
					if (map.get("TemplateBasePath") != null)
						templateBasePath = (String) map.get("TemplateBasePath");
					if (map.get(IConfigFactory.DEBUG) != null) {
						debug = Boolean.valueOf(
								(String) map.get(IConfigFactory.DEBUG))
								.booleanValue();
					}
					if (map.get(IConfigFactory.MaxUploadFileSize) != null) {
						int maxSize = Integer.valueOf(
								(String) map
										.get(IConfigFactory.MaxUploadFileSize))
								.intValue();
						if (maxSize > 0)
							maxUploadFileSize = maxSize;
					}
					if (map.get(IConfigFactory.UploadSizeThreshold) != null) {
						int maxSize = Integer
								.valueOf(
										(String) map
												.get(IConfigFactory.UploadSizeThreshold))
								.intValue();
						if (maxSize > 0)
							uploadSizeThreshold = maxSize;
					}
					handleInitApp((List) icf.initOther().get("initApp"));

					handleInterceptors((List) icf.initOther().get(
							"interceptors"));
					logger.debug("interceptors.Size:" + interceptors.size());

					handleErrorHandler((List) icf.initOther().get(
							"errorHandler"));
					//增加Bean配置信息
					beanDefinitions.addAll((List)map.get("beanDefinitions"));
					beanDefinitions.addAll(BeanConfigReader.parseBeansFromModules(modules));
					//把Module及WebForm等相关对象转换成Bean存入到容器中
					
				}				
				java.util.Iterator ocs=configManagers.iterator();
				while(ocs.hasNext())
				{
					ConfigManager cfm=(ConfigManager)ocs.next();
					cfm.parseConfig(icf.getDoc());
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
    private List transferModuleToBean()
    {
    	List list=new java.util.ArrayList();
    	
    	return list;
    }
	private void handleInitApp(List list) throws Exception {
		if (list != null) {
			for (int i = 0; i < list.size(); i++) {
				// String[] appParms = ((String) list.get(i)).split(";");
				Map appMap = (Map) list.get(i);
				String classname = (String) appMap.get("class");
				String initmethod = (String) appMap.get("init-method");
				String destroymethod = (String) appMap.get("destroy-method");
				Object obj = null;
				Method init_method = null;
				Map app = new HashMap();
				if (StringUtils.hasLength(classname)) {
					obj = Class.forName(classname).newInstance();
					app.put("classname", obj);
					if (StringUtils.hasLength(initmethod)) {
						init_method = obj.getClass()
								.getMethod(initmethod, null);
						app.put("init-method", init_method);
					}
					if (StringUtils.hasLength(destroymethod)) {
						Method destroy_method = obj.getClass().getMethod(
								destroymethod, null);
						app.put("destroy-method", destroy_method);
					}
				}
				initApps.add(app);
				logger.debug("initApps.size:" + initApps.size());
			}
		}
	}

	private void handleInterceptors(List list) throws Exception {
		if (list != null) {
			for (int i = 0; i < list.size(); i++) {
				try {
					Map app = (Map) list.get(i);
					String name = (String) app.get("name");
					String clz = (String) app.get("class");
					if (StringUtils.hasLength(clz)) {
						Object obj = Class.forName(clz).newInstance();
						if (name == null || "".equals(name))
							name = obj.getClass().getName();
						interceptors.put(name, obj);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	private void handleErrorHandler(List list) throws Exception {
		if (list != null) {

		}
	}

	public String getTemplateBasePath() {
		return templateBasePath;
	}

	public void setTemplateBasePath(String templateBasePath) {
		this.templateBasePath = templateBasePath;
	}

	public boolean isDebug() {
		return debug;
	}

	public void setDebug(boolean debug) {
		this.debug = debug;
	}

	public Map getForms() {
		return forms;
	}

	public Map getModules() {
		return modules;
	}

	public Map getPages() {
		return pages;
	}

	public List getInitApps() {
		return initApps;
	}

	public Map getInterceptors() {
		return interceptors;
	}

	public int getMaxUploadFileSize() {
		return maxUploadFileSize;
	}

	public void setMaxUploadFileSize(int maxUploadFileSize) {
		this.maxUploadFileSize = maxUploadFileSize;
	}

	public int getUploadSizeThreshold() {
		return uploadSizeThreshold;
	}

	public void setUploadSizeThreshold(int uploadSizeThreshold) {
		this.uploadSizeThreshold = uploadSizeThreshold;
	}

	public InputStream[] getConfigures() {
		return configures;
	}

	public Map getErrorHandler() {
		return errorHandler;
	}

	public void setConfigures(InputStream[] configures) {
		this.configures = configures;
	}

	public List getBeanDefinitions() {
		return beanDefinitions;
	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -