1 package org.sapia.soto.ubik; 2 3 import org.sapia.soto.ConfigurationException; 4 import org.sapia.soto.Service; 5 6 import org.sapia.ubik.rmi.naming.remote.RemoteInitialContextFactory; 7 8 import java.util.Properties ; 9 10 import javax.naming.Context ; 11 import javax.naming.InitialContext ; 12 import javax.naming.NameNotFoundException ; 13 import javax.naming.NamingException ; 14 15 16 26 public class NamingService implements Service { 27 private String _domain; 28 private String _host; 29 private int _port; 30 private InitialContext _ctx; 31 32 35 public void setJndiHost(String host) { 36 _host = host; 37 } 38 39 42 public void setJndiPort(int port) { 43 _port = port; 44 } 45 46 49 public void setDomain(String domain) { 50 _domain = domain; 51 } 52 53 60 public synchronized void bind(String name, Object o) 61 throws NamingException { 62 _ctx.bind(name, o); 63 } 64 65 70 public Object lookup(String name) 71 throws NamingException , NameNotFoundException { 72 return _ctx.lookup(name); 73 } 74 75 78 public void dispose() { 79 try { 80 _ctx.close(); 81 } catch (NamingException e) { 82 } 84 } 85 86 89 public void init() throws Exception { 90 if (_port == 0) { 91 throw new ConfigurationException( 92 "'jndiPort' not set for Ubik naming service"); 93 } 94 95 if (_host == null) { 96 throw new ConfigurationException( 97 "'jndiHost' not set for Ubik naming service"); 98 } 99 100 if (_domain == null) { 101 throw new ConfigurationException( 102 "'domain' not set for Ubik naming service"); 103 } 104 105 Properties props = new Properties (); 106 props.setProperty(Context.INITIAL_CONTEXT_FACTORY, 107 RemoteInitialContextFactory.class.getName()); 108 props.setProperty(RemoteInitialContextFactory.UBIK_DOMAIN_NAME, _domain); 109 props.setProperty(Context.PROVIDER_URL, "ubik://" + _host + ":" + _port); 110 _ctx = new InitialContext (props); 111 } 112 113 116 public void start() throws Exception { 117 } 118 } 119 | Popular Tags |