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

📄 initsystem.java

📁 Java开发的权限管理的例子
💻 JAVA
字号:
package org.artemis.manager.common;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.gsta.eshore.framework.exeception.ClientException;
import com.gsta.eshore.framework.jcf.ErrorCode;
import com.gsta.eshore.framework.service.impl.ContextServiceLocator;
import com.gsta.eshore.framework.servicerepository.ServiceLocator;

public class InitSystem {
    private static boolean state = false;
    private static Logger logger = Logger.getLogger(InitSystem.class);
	private static InitSystem instance;
	public static InitSystem getInstance(){
		if(instance==null)
			instance=new InitSystem();
		return instance;
}
    public InitSystem() {}


    public  boolean execute()
    {
		if (state) {
			return state;
		}
		state=initlog4j();
        if(state==false){
        	throw new ClientException("warning:初始化log4j出错",ErrorCode.SYSTEM_ERROR);
        }
       
        state=initspring();
             if(state==false){
        	     throw new ClientException("warning:初始化spring配置文件出错",ErrorCode.SYSTEM_ERROR);
                 }
    	return true;
    }
	public boolean initspring() {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		if (ctx == null) {
			state = false;
		} else {
			state = true;
		}
		ContextServiceLocator.getInstance().setContext(ctx);
		logger.debug("ContextServiceLocator context = "
				+ ContextServiceLocator.getInstance().getContext());
		return state;
	}

	public boolean initlog4j() {
		String logFile=(String)ServiceLocator.getInstance().getOne("log4j");
			SimpleDateFormat formatter = new SimpleDateFormat(
					"yyyy-MM-dd H:mm:ss a z");
			Date today = new Date();
			String output = "<" + formatter.format(today) + "> <Debug> ";
			logger.info(output + "application log4j properties file is: " + logFile);
		if (logFile != null) {
			if (logFile.toString().toLowerCase().endsWith(".xml")) {
				DOMConfigurator.configure(logFile);
			} else {
				PropertyConfigurator.configure(logFile);
			}
			return true;
		} else {
			return false;
		}
	}

}

⌨️ 快捷键说明

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