ex7_3.txt

来自「j2ee core design patterns」· 文本 代码 · 共 39 行

TXT
39
字号
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 + =
减小字号Ctrl + -
显示快捷键?