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 ; 9 10 import javax.naming.Binding ; 11 import javax.naming.Context ; 12 import javax.naming.InitialContext ; 13 import javax.naming.NamingEnumeration ; 14 15 16 24 public class JndiBrowsingEg { 25 26 public JndiBrowsingEg() { 27 } 28 29 32 public static void main(String [] args) { 33 try { 34 Properties props = new Properties (); 35 36 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 ctx = new InitialContext (props); 44 ReliableFoo foo = new ReliableFoo(); 45 46 System.out.println("Creating subcontext..."); 47 48 ctx.createSubcontext("/path1"); 49 50 Context 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 en = ctx.listBindings("/path1"); 64 Binding b; 65 66 while (en.hasMore()) { 67 b = (Binding ) en.next(); 68 System.out.println("Got child context from enumeration: " + 69 b.getName()); 70 child = (Context ) b.getObject(); 71 child.lookup("foo"); 72 System.out.println("Looked up Foo from child context"); 73 } 74 } catch (Exception e) { 75 e.printStackTrace(); 76 } 77 } 78 } 79 | Popular Tags |