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

📄 jndiutil.java

📁 Junit in Action的随书原代码
💻 JAVA
字号:
package junitbook.ejb.util;

import javax.naming.InitialContext;
import javax.naming.NamingException;

public class JNDIUtil
{
    private static InitialContext jndiContext;

    private static InitialContext getInitialContext()
    {
        if (jndiContext == null)
        {
            try
            {
                jndiContext = new InitialContext();
            }
            catch (NamingException e)
            {
                throw new RuntimeException(
                    "Failed to create InitialContext [" 
                    + e.getMessage() + "]");
            }
        }
        return jndiContext;
    }

    public static Object lookup(String name)
    {
        Object object = null;
        try
        {
            object = getInitialContext().lookup(name);
        }
        catch (NamingException e)
        {
            throw new RuntimeException("JNDI lookup failure for [" 
                + name + "]. Reason [" + e.getMessage() + "]");
        }

        return object;
    }

}

⌨️ 快捷键说明

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