KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > regis > gui > RegistryFactory


1 package org.sapia.regis.gui;
2
3 import java.io.File JavaDoc;
4 import java.util.Properties JavaDoc;
5
6 import org.sapia.regis.Registry;
7 import org.sapia.regis.RegistryContext;
8 import org.sapia.regis.local.LocalRegistry;
9 import org.sapia.regis.local.LocalRegistryFactory;
10 import org.sapia.regis.remote.client.RemoteRegistryFactory;
11
12 public class RegistryFactory {
13
14   public static Registry newEmbeddedInstance() throws Exception JavaDoc{
15     Properties JavaDoc props = new Properties JavaDoc();
16     props.setProperty(RegistryContext.FACTORY_CLASS, LocalRegistryFactory.class.getName());
17
18     RegistryContext ctx = new RegistryContext(props);
19     return ctx.connect();
20   }
21   
22   public static Registry newDebugInstance() throws Exception JavaDoc{
23     LocalRegistry local = (LocalRegistry)newEmbeddedInstance();
24     //local.load(new File("etc/configCreateExample.xml"));
25
return local;
26   }
27   
28   public static Registry newRemoteInstance(String JavaDoc host, int port, String JavaDoc jndiName) throws Exception JavaDoc{
29     Properties JavaDoc props = new Properties JavaDoc();
30     props.setProperty(RegistryContext.FACTORY_CLASS, RemoteRegistryFactory.class.getName());
31     props.setProperty(RemoteRegistryFactory.ADDRESS, host);
32     props.setProperty(RemoteRegistryFactory.PORT, ""+port);
33     if(jndiName != null && jndiName.trim().length() > 0){
34       props.setProperty(RemoteRegistryFactory.JNDI_NAME, ""+jndiName);
35     }
36     RegistryContext ctx = new RegistryContext(props);
37     return ctx.connect();
38   }
39 }
40
Popular Tags