ex7_8.txt

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

TXT
28
字号
Example 7.8 	ServiceLocator.java: Implementing JDBC DataSource Service Locator Strategy
package com.corej2eepatterns.servicelocator;

// imports
public class ServiceLocator {
    . . . 

    public DataSource getDataSource(String dataSourceName) 
    throws ServiceLocatorException {
        DataSource dataSource = null;
        try {
            if (cache.containsKey(dataSourceName)) {
                dataSource =
                    (DataSource) cache.get(dataSourceName);
            } else {
                dataSource = (DataSource) 
                    initialContext.lookup(dataSourceName);
                cache.put(dataSourceName, dataSource );
            }
        } catch (NamingException nex) {
            throw new ServiceLocatorException(nex);
        } catch (Exception ex) {
            throw new ServiceLocatorException(ex);
        }
        return dataSource;
    }
    . . .
}

⌨️ 快捷键说明

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