KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.regis.remote.client;
2
3 import java.util.Properties JavaDoc;
4
5 import org.sapia.regis.Registry;
6 import org.sapia.regis.RegistryFactory;
7
8 /**
9  * This class implements a factory that looks up a remote registry. The
10  * remote registry is a registry server stub that is made available on the network in
11  * one of two ways (using a <code>RegistryExporter</code>):
12  * <ul>
13  * <li>by binding the registry stub to a specific port.
14  * <li>by binding the registry stub under a given name, in a distributed
15  * Ubik JNDI server.
16  * </ul>
17  * <p>
18  * Then, an instance of this class is used to lookup the registry. The instance
19  * expects properties that specify either the JNDI name of the registry and connection URL
20  * of the JNDI server in which it is published; or the IP address/port to which the registry
21  * is bound.
22  *
23  * @see org.sapia.regis.remote.RegistryExporter
24  *
25  * @author yduchesne
26  *
27  */

28 public class RemoteRegistryFactory implements RegistryFactory{
29   
30   /**
31    * This constant corresponds to the property that specifies the JNDI name under
32    * which to lookup the remote registry.
33    */

34   public static final String JavaDoc JNDI_NAME = "org.sapia.regis.remote.jndi.name";
35   
36   /**
37    * This constant corresponds to the property that specifies the address of
38    * the host on which the remote registry is bound.
39    */

40   public static final String JavaDoc ADDRESS = "org.sapia.regis.remote.address";
41   
42   /**
43    * This constant corresponds to the property that specifies the port to
44    * which the remote registry is bound.
45    */

46   public static final String JavaDoc PORT = "org.sapia.regis.remote.port";
47   
48   public Registry connect(Properties JavaDoc props) throws Exception JavaDoc {
49     String JavaDoc jndiName = props.getProperty(JNDI_NAME);
50     String JavaDoc portStr = props.getProperty(PORT);
51     if(portStr == null){
52       throw new IllegalStateException JavaDoc("Registry server jndi name or port must be specified");
53     }
54     String JavaDoc addr = props.getProperty(ADDRESS);
55     if(addr == null){
56       throw new IllegalStateException JavaDoc("Address must be specified");
57     }
58     
59     if(jndiName != null){
60       RegistryImporter imp = new RegistryImporter();
61       props.setProperty("java.naming.provider.url", "ubik://"+addr+":"+portStr);
62       return imp.lookup(jndiName, props);
63     }
64     else{
65       RegistryImporter imp = new RegistryImporter();
66       return imp.lookup(addr, Integer.parseInt(portStr));
67     }
68   }
69 }
70
Popular Tags