?? servicelocator.java
字號:
package com.ibm.ta.webservice;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.transaction.UserTransaction;
public class ServiceLocator {
private InitialContext ic;
private Map cache;
private static ServiceLocator sl = null;
private ServiceLocator() throws TAServiceException {
cache = Collections.synchronizedMap(new HashMap());
try {
ic = new InitialContext();
} catch (NamingException ne) {
throw new TAServiceException(ne.getMessage(), ne);
}
}
static public void initializeInstance() throws TAServiceException {
if (sl == null) {
sl = new ServiceLocator();
}
}
static public ServiceLocator getInstance() {
return sl;
}
public DataSource getDataSource(String dataSourceName)
throws TAServiceException {
DataSource dataSource = null;
try {
if (cache.containsKey(dataSourceName)) {
dataSource = (DataSource) cache.get(dataSourceName);
} else {
dataSource = (DataSource) ic.lookup(dataSourceName);
cache.put(dataSourceName, dataSource);
}
} catch (NamingException ne) {
throw new TAServiceException(ne.getMessage(), ne);
}
return dataSource;
}
public UserTransaction getUserTransaction() throws TAServiceException {
try {
return (UserTransaction) ic.lookup("java:comp/UserTransaction");
} catch (NamingException ne) {
throw new TAServiceException(ne.getMessage(), ne);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -