ex7_6.txt
来自「j2ee core design patterns」· 文本 代码 · 共 54 行
TXT
54 行
Example 7.6 ServiceLocator.java: Implementing JMS Topic Service Locator
Strategy
package com.corej2eepatterns.servicelocator;
// imports
public class ServiceLocator {
. . .
// lookup and return a TopicConnectionFactory
public TopicConnectionFactory getTopicConnectionFactory(
String topicConnectionFactoryName)
throws ServiceLocatorException {
TopicConnectionFactory topicFactory = null;
try {
if (cache.containsKey(topicConnectionFactoryName)) {
topicFactory = (TopicConnectionFactory)
cache.get(topicConnectionFactoryName);
} else {
topicFactory = (TopicConnectionFactory)
initialContext.
lookup(topicConnectionFactoryName);
cache.put(topicConnectionFactoryName,
topicFactory);
}
} catch (NamingException nex) {
throw new ServiceLocatorException(nex);
} catch (Exception ex) {
throw new ServiceLocatorException(ex);
}
return topicFactory;
}
// lookup and return a TopicConnectionFactory
public Topic getTopic(String topicName)
throws ServiceLocatorException {
Topic topic = null;
try {
if (cache.containsKey(topicName)) {
topic = (Topic) cache.get(topicName);
} else {
topic =
(Topic)initialContext.lookup(topicName);
cache.put(topicName, topic);
}
} catch (NamingException nex) {
throw new ServiceLocatorException(nex);
} catch (Exception ex) {
throw new ServiceLocatorException(ex);
}
return topic;
}
. . .
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?