KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > examples > jndi > JndiBrowsingEg


1 package org.sapia.ubik.rmi.examples.jndi;
2
3 import org.sapia.ubik.rmi.Consts;
4 import org.sapia.ubik.rmi.examples.Foo;
5 import org.sapia.ubik.rmi.examples.ReliableFoo;
6 import org.sapia.ubik.rmi.naming.remote.RemoteInitialContextFactory;
7
8 import java.util.Properties JavaDoc;
9
10 import javax.naming.Binding JavaDoc;
11 import javax.naming.Context JavaDoc;
12 import javax.naming.InitialContext JavaDoc;
13 import javax.naming.NamingEnumeration JavaDoc;
14
15
16 /**
17  * <dl>
18  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
19  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
20  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
21  * </dl>
22  * @author Yanick Duchesne
23  */

24 public class JndiBrowsingEg {
25   /** Creates a new instance of JndiBrowsingEg */
26   public JndiBrowsingEg() {
27   }
28
29   /**
30    * @param args the command line arguments
31    */

32   public static void main(String JavaDoc[] args) {
33     try {
34       Properties JavaDoc props = new Properties JavaDoc();
35
36       // ENABLES MARSHALLING
37
System.setProperty(Consts.MARSHALLING, "true");
38
39       props.setProperty(InitialContext.PROVIDER_URL, "ubik://localhost:1099");
40       props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,
41         RemoteInitialContextFactory.class.getName());
42
43       InitialContext JavaDoc ctx = new InitialContext JavaDoc(props);
44       ReliableFoo foo = new ReliableFoo();
45
46       System.out.println("Creating subcontext...");
47
48       ctx.createSubcontext("/path1");
49
50       Context JavaDoc child = ctx.createSubcontext("/path1/path2");
51
52       System.out.println("Binding Foo to subcontext...");
53
54       child.bind("foo", foo);
55       child.bind("foo", foo);
56
57       System.out.println("Looking up...");
58
59       Foo server = (Foo) ctx.lookup("/path1/path2/foo");
60
61       System.out.println("Looked up; now listing bindings...");
62
63       NamingEnumeration JavaDoc en = ctx.listBindings("/path1");
64       Binding JavaDoc b;
65
66       while (en.hasMore()) {
67         b = (Binding JavaDoc) en.next();
68         System.out.println("Got child context from enumeration: " +
69           b.getName());
70         child = (Context JavaDoc) b.getObject();
71         child.lookup("foo");
72         System.out.println("Looked up Foo from child context");
73       }
74     } catch (Exception JavaDoc e) {
75       e.printStackTrace();
76     }
77   }
78 }
79
Popular Tags