1 6 7 8 9 package com.sun.j2ee.blueprints.docoriented.client; 10 11 12 13 import javax.naming.*; 14 15 import java.rmi.Remote ; 16 17 import javax.xml.rpc.*; 18 19 20 21 28 29 public class ServiceLocator { 30 31 32 33 private transient InitialContext ic; 34 35 36 37 public ServiceLocator() throws ServiceLocatorException { 38 39 try { 40 41 setInitialContext(); 42 43 } catch (Exception e) { 44 45 throw new ServiceLocatorException(e); 46 47 } 48 49 } 50 51 52 53 private void setInitialContext() throws javax.naming.NamingException { 54 55 ic = new InitialContext(); 56 57 } 58 59 60 61 70 71 public Service getService(String jndiName) throws ServiceLocatorException { 72 73 try { 74 75 if (ic == null) setInitialContext(); 76 77 return (Service) ic.lookup(jndiName); 78 79 } catch (Exception e) { 80 81 throw new ServiceLocatorException("ServiceLocator can not lookup jndiName=" + jndiName, e); 82 83 } 84 85 } 86 87 88 89 98 99 public Remote getServicePort(String jndiName, Class className) throws ServiceLocatorException { 100 101 try { 102 103 if (ic == null) setInitialContext(); 104 105 Service service = (Service) ic.lookup(jndiName); 106 107 return service.getPort(className); 108 109 } catch (Exception e) { 110 111 throw new ServiceLocatorException("ServiceLocator can not lookup jndiName=" + jndiName + " and className=" + className, e); 112 113 } 114 115 } 116 117 } 118 119 | Popular Tags |