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

📄 ex7_3.txt

📁 j2ee core design patterns
💻 TXT
字号:
Example 7.3 	ServiceLocator.java: Implementing a Service Locator
package com.corej2eepatterns.servicelocator;

// imports
public class ServiceLocator {

    private InitialContext initialContext;
    private Map cache;

    private static ServiceLocator _instance;

    static {
        try {
            _instance = new ServiceLocator();
        } catch (ServiceLocatorException se) {
            System.err.println(se);
            se.printStackTrace(System.err);
        }
    }

    private ServiceLocator() throws ServiceLocatorException {
        try {
            initialContext = new InitialContext();
            cache = Collections.
                synchronizedMap(new HashMap());
        } catch (NamingException ne) {
            throw new ServiceLocatorException(ne);
        } catch (Exception e) {
            throw new ServiceLocatorException(e);
        }
    }

    static public ServiceLocator getInstance() {
        return _instance;
    }

    // implement lookup methods here
    . . .
}

⌨️ 快捷键说明

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