servicelocator.java

来自「一个java写的加密算法」· Java 代码 · 共 80 行

JAVA
80
字号
/* * Copyright 2004-2005 Sun Microsystems, Inc.  All rights reserved. * Use is subject to license terms. */package samples.jms.soaptojms;import java.net.URL;import javax.ejb.EJBHome;import javax.ejb.EJBLocalHome;import javax.jms.QueueConnectionFactory;import javax.jms.Queue;import javax.jms.TopicConnectionFactory;import javax.jms.Topic;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.rmi.PortableRemoteObject;import javax.sql.DataSource;import samples.jms.soaptojms.ServiceLocatorException;/** *  This class is an implementation of the Service Locator pattern. It is *  used to looukup resources such as JMS Destinations, etc. */public class ServiceLocator {    private InitialContext ic;        public ServiceLocator() throws ServiceLocatorException  {      try {        ic = new InitialContext();             } catch (NamingException ne) {            throw new ServiceLocatorException(ne);      } catch (Exception e) {            throw new ServiceLocatorException(e);      }     }       /**     * This method helps in obtaining the topic factory     * @return the factory for the factory to get topic connections from     */    public  TopicConnectionFactory getTopicConnectionFactory(String topicConnFactoryName) throws ServiceLocatorException {      TopicConnectionFactory factory = null;      try {        factory = (TopicConnectionFactory) ic.lookup(topicConnFactoryName);              } catch (NamingException ne) {          ne.printStackTrace();          throw new ServiceLocatorException(ne);      } catch (Exception e) {          e.printStackTrace();          throw new ServiceLocatorException(e);      }      return factory;    }           /**     * This method obtains the topc itself for a caller     * @return the Topic Destination to send messages to     */    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;    }}

⌨️ 快捷键说明

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