1 37 38 package com.sun.j2ee.blueprints.servicelocator.ejb; 39 40 import java.net.*; 41 import javax.ejb.*; 42 import javax.jms.*; 43 import javax.naming.*; 44 import javax.rmi.*; 45 import javax.sql.*; 46 47 import com.sun.j2ee.blueprints.servicelocator.ServiceLocatorException; 48 49 53 public class ServiceLocator { 54 55 private transient InitialContext ic; 56 57 public ServiceLocator() throws ServiceLocatorException { 58 try { 59 ic = new InitialContext(); 60 } catch (Exception e) { 61 throw new ServiceLocatorException(e); 62 } 63 } 64 65 71 public EJBLocalHome getLocalHome(String jndiHomeName) throws ServiceLocatorException { 72 try { 73 return (EJBLocalHome) ic.lookup(jndiHomeName); 74 } catch (Exception e) { 75 throw new ServiceLocatorException(e); 76 } 77 } 78 79 85 public EJBHome getRemoteHome(String jndiHomeName, Class className) throws ServiceLocatorException { 86 try { 87 Object objref = ic.lookup(jndiHomeName); 88 return (EJBHome) PortableRemoteObject.narrow(objref, className); 89 } catch (Exception e) { 90 throw new ServiceLocatorException(e); 91 } 92 } 93 94 97 public ConnectionFactory getJMSConnectionFactory(String jmsConnFactoryName) 98 throws ServiceLocatorException { 99 try { 100 return (ConnectionFactory) ic.lookup(jmsConnFactoryName); 101 } catch (Exception e) { 102 throw new ServiceLocatorException(e); 103 } 104 } 105 106 109 public Destination getJMSDestination(String destName) throws ServiceLocatorException { 110 try { 111 return (Destination)ic.lookup(destName); 112 } catch (Exception e) { 113 throw new ServiceLocatorException(e); 114 } 115 } 116 117 121 public DataSource getDataSource(String dataSourceName) throws ServiceLocatorException { 122 try { 123 return (DataSource)ic.lookup(dataSourceName); 124 } catch (Exception e) { 125 throw new ServiceLocatorException(e); 126 } 127 } 128 129 133 public URL getUrl(String envName) throws ServiceLocatorException { 134 try { 135 return (URL)ic.lookup(envName); 136 } catch (Exception e) { 137 throw new ServiceLocatorException(e); 138 } 139 } 140 141 145 public boolean getBoolean(String envName) throws ServiceLocatorException { 146 try { 147 return ((Boolean )ic.lookup(envName)).booleanValue(); 148 } catch (Exception e) { 149 throw new ServiceLocatorException(e); 150 } 151 } 152 153 157 public String getString(String envName) throws ServiceLocatorException { 158 try { 159 return (String )ic.lookup(envName); 160 } catch (Exception e) { 161 throw new ServiceLocatorException(e); 162 } 163 } 164 } 165 | Popular Tags |