📄 webservicelocator.java
字号:
//Source file: H:\\book\\case\\com\\j2eeapp\\cdstore\\util\\WebServiceLocator.java
package com.j2eeapp.cdstore.servicelocator;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.sql.DataSource;
import javax.ejb.EJBHome;
import javax.ejb.EJBLocalHome;
import javax.jms.QueueConnectionFactory;
import javax.jms.Queue;
import javax.jms.TopicConnectionFactory;
import javax.jms.Topic;
public class WebServiceLocator
{
private InitialContext ic;
public WebServiceLocator() throws ServiceLocatorException
{
try {
ic = new InitialContext();
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
}
/**
* @param name
* @return EJBLocalHome
*/
public EJBLocalHome getLocalHome(String name) throws ServiceLocatorException
{
EJBLocalHome home = null;
try {
home = (EJBLocalHome) ic.lookup(name);
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return home;
}
/**
* @param name
* @return EJBHome
*/
public EJBHome getRemoteHome(String name, Class className) throws ServiceLocatorException
{
EJBHome home = null;
try {
Object objref = ic.lookup(name);
Object obj = PortableRemoteObject.narrow(objref, className);
home = (EJBHome)obj;
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return home;
}
/**
* @param qConnFactoryName
* @return QueueConnectionFactory
*/
public QueueConnectionFactory getQueueConnectionFactory(String qConnFactoryName)
throws ServiceLocatorException
{
QueueConnectionFactory factory = null;
try {
factory = (QueueConnectionFactory) ic.lookup(qConnFactoryName);
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return factory;
}
/**
* @param queueName
* @return Queue
*/
public Queue getQueue(String queueName) throws ServiceLocatorException {
Queue queue = null;
try {
queue =(Queue)ic.lookup(queueName);
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return queue;
}
/**
* @param topicConnFactoryName
* @return TopicConnectionFactory
*/
public TopicConnectionFactory getTopicConnectionFactory(String topicConnFactoryName) throws ServiceLocatorException {
TopicConnectionFactory factory = null;
try {
factory = (TopicConnectionFactory) ic.lookup(topicConnFactoryName);
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return factory;
}
/**
* @param topicName
* @return Topic
*/
public Topic getTopic(String topicName) throws ServiceLocatorException {
Topic topic = null;
try {
topic = (Topic)ic.lookup(topicName);
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return topic;
}
/**
* @param dataSourceName
* @return DataSource
*/
public DataSource getDataSource(String dataSourceName) throws ServiceLocatorException {
DataSource dataSource = null;
try {
dataSource = (DataSource)ic.lookup(dataSourceName);
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return dataSource;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -