📄 examcontext.java
字号:
package com.nc21.exam.util;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.log4j.Logger;
/**
* 系统上下文,可以在容器中获取资源对象
*
* @author Administrator
*
*/
public class ExamContext {
private final static Logger log = Logger.getLogger(Config.class);
private static Context initContext;
static {
try {
initContext = new InitialContext();
} catch (NamingException e) {
e.printStackTrace();
log.error(e.getMessage());
}
}
/**
* 查询并返回容器中的资源对象
*
* @param subName
* 对象jndi的子名称
* @return
*/
public static Object find(String subName) {
if (subName == null) {
throw new IllegalArgumentException("Illegal Argument");
}
Object obj = null;
try {
Context envContext = (Context) initContext.lookup(Config
.getValue("jndi.env"));
obj = envContext.lookup(subName);
} catch (NamingException e) {
e.printStackTrace();
log.error(e.getMessage());
return null;
}
return obj;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -