java服务定位器(3)

/**
* 得到主题工厂
*
* @param topicConnFactoryName
* @throws ServiceLocatorException
*/
public TopicConnectionFactory getTopicConnectionFactory(
String topicConnFactoryName) throws ServiceLocatorException {
TopicConnectionFactory factory = null;
try {
if (handlers.containsKey(topicConnFactoryName)) {
factory = (TopicConnectionFactory) handlers
.get(topicConnFactoryName);
} else {
factory = (TopicConnectionFactory) context
.lookup(topicConnFactoryName);
handlers.put(topicConnFactoryName, factory);
}
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return factory;
}
/**
* 得到主题
*
* @param topicName
* @throws ServiceLocatorException
*/
public Topic getTopic(String topicName) throws ServiceLocatorException {
Topic topic = null;
try {
if (handlers.containsKey(topicName)) {
topic = (Topic) handlers.get(topicName);
} else {
topic = (Topic) context.lookup(topicName);
handlers.put(topicName, topic);
}
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return topic;
}
/**
* 得到数据源
*
* @param dataSourceName
* @throws ServiceLocatorException
*/
public DataSource getDataSource(String dataSourceName)
throws ServiceLocatorException {
DataSource dataSource = null;
try {
if (handlers.containsKey(dataSourceName)) {
dataSource = (DataSource) handlers.get(dataSourceName);
} else {
dataSource = (DataSource) context.lookup(dataSourceName);
handlers.put(dataSourceName, dataSource);
}
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return dataSource;
}

/**
* 得到URL
*
* @param envName
* @throws ServiceLocatorException
*/
public URL getUrl(String envName) throws ServiceLocatorException {
URL url = null;
try {
url = (URL) context.lookup(envName);
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}

return url;
}

/**
* 上下文是否存在环境变量
*
* @param envName
* @throws ServiceLocatorException
*/
public boolean getBoolean(String envName) throws ServiceLocatorException {
Boolean bool = null;
try {
bool = (Boolean) context.lookup(envName);
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return bool.booleanValue();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值