1 package org.jacorb.naming; 2 3 import org.omg.CosNaming.*; 4 5 public class TestClient 6 { 7 public static void list( NamingContextExt n, String indent) 8 { 9 10 try 11 { 12 BindingListHolder blsoh = 13 new BindingListHolder(new Binding[0]); 14 BindingIteratorHolder bioh = 15 new BindingIteratorHolder(); 16 17 n.list( 0, blsoh, bioh ); 18 19 BindingHolder bh = new BindingHolder(); 20 21 if( bioh.value == null ) 22 return; 23 24 while( bioh.value.next_one( bh )) 25 { 26 Name name = new Name( bh.value.binding_name); 27 System.out.print( indent + name ); 28 if( bh.value.binding_type.value() == BindingType._ncontext ) 29 { 30 String _indent = indent + "\t"; 31 System.out.println("/"); 32 list(NamingContextExtHelper.narrow(n.resolve(name.components())), _indent); 33 } 34 else 35 System.out.println(); 36 } 37 38 } 39 catch (Exception e) 40 { 41 e.printStackTrace(); 42 } 43 } 44 45 46 public static void main(String args[]) 47 { 48 try 49 { 50 org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null); 51 52 NamingContextExt rootContext = 53 NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService")); 54 55 56 57 NameComponent[] nameComp = new NameComponent[1]; 58 nameComp[0] = new NameComponent("first","context"); 59 NamingContextExt firstsubContext = 60 NamingContextExtHelper.narrow(rootContext.bind_new_context( nameComp )); 61 62 nameComp = new NameComponent[1]; 63 nameComp[0] = new NameComponent("second","context"); 64 NamingContextExt secondsubContext = 65 NamingContextExtHelper.narrow(rootContext.bind_new_context( nameComp )); 66 67 nameComp = new NameComponent[1]; 68 nameComp[0] = new NameComponent("subsub","context"); 69 NamingContextExt subsubContext = 70 NamingContextExtHelper.narrow(secondsubContext.bind_new_context( nameComp )); 71 72 73 list( rootContext ,""); 74 75 if( args.length > 0 ) 76 System.out.println(rootContext.to_url( args[0], rootContext.to_string( nameComp ))); 77 78 System.out.println("Wait for the NS to go down, then press <enter> to continue"); 79 80 int n = 0; 81 82 while( '\n' != System.in.read()); 83 84 list( secondsubContext, ""); 85 86 System.out.println("done. "); 87 System.exit(0); 88 } 89 catch (Exception e) 90 { 91 e.printStackTrace(); 92 System.exit(1); 93 } 94 } 95 } 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | Popular Tags |