KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > regis > remote > client > RegistryImporter


1 package org.sapia.regis.remote.client;
2
3 import java.util.Properties JavaDoc;
4
5 import javax.naming.InitialContext JavaDoc;
6
7 import org.sapia.regis.Registry;
8 import org.sapia.regis.remote.RegistryExporter;
9 import org.sapia.ubik.rmi.naming.remote.RemoteInitialContextFactory;
10 import org.sapia.ubik.rmi.server.Hub;
11
12 /**
13  * An instance of this class is used to lookup a remote registry that has been
14  * exported by a <code>RegistryExporter</code>.
15  *
16  * @see org.sapia.regis.remote.RegistryExporter
17  *
18  * @author yduchesne
19  *
20  */

21 public class RegistryImporter {
22   
23   /**
24    * This method looks up a remote registry that listens on the given address:port.
25    *
26    * @param address the remote address to which the remote registry has been bound.
27    * @param port the port to which the remote registry has been bound.
28    * @return the <code>Registry</code> that could be found on the given port.
29    * @throws Exception if no registry could be found, or if a problem occurred while
30    * looking up.
31    */

32   public Registry lookup(String JavaDoc String, int port) throws Exception JavaDoc{
33     return (Registry)Hub.connect(String, port);
34   }
35   
36   /**
37    * This method takes Ubik properties to lookup a remote registry. For more info
38    * concerning the actual properties to use, see the <code>RegistryExporter</code>
39    * class.
40    *
41    * @param jndiName the name of the remote registry to lookup
42    * @param props the <code>Properties</code> containing the lookup information
43    * @return the <code>Registry</code> that has been found
44    * @throws Exception if no registry could be found, or if a problem occurred while
45    * looking up.
46    *
47    * @see RegistryExporter#bind(String, int, Properties)
48    */

49   public Registry lookup(String JavaDoc jndiName, Properties JavaDoc props) throws Exception JavaDoc{
50     props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
51     InitialContext JavaDoc ctx = new InitialContext JavaDoc(props);
52     try{
53       return new RemoteRegistryProxy((Registry)ctx.lookup(jndiName));
54     }finally{
55       ctx.close();
56     }
57   }
58
59 }
60
Popular Tags