FileDocCategorySizeDatePackage
NamingTest.javaAPI DocExample2551Wed Apr 05 11:25:42 BST 2000None

NamingTest

public class NamingTest extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)

    ORB myORB = ORB.init(argv, null);
    try {
      org.omg.CORBA.Object ref = myORB.resolve_initial_references("NameService");
      // Get the root context, as before
      NamingContext rootNC = NamingContextHelper.narrow(ref);
      // Create the components to the sub-context name
      NameComponent comp1 = new NameComponent("servers", "");
      NameComponent ttComp = new NameComponent("ThisOrThat", "");
      NameComponent otherComp= new NameComponent("misc", "");
      // Create each sub-context within the root context, and bind them
      // to their appropriate names
      // Create a new context, bind it to the name "servers", off of the root 
      NamingContext context1 = rootNC.new_context();
      NameComponent path1[] = { comp1 };
      rootNC.bind_context(path1, context1);
      // Create another context, bind it to the name "servers, ThisOrThat" 
      NamingContext ttDir = rootNC.new_context();
      NameComponent path2_1[] = { comp1, ttComp };
      rootNC.bind_context(path2_1, ttDir);
      // Create another context, bind it to the name "servers, misc" 
      NamingContext otherDir = rootNC.new_context();
      NameComponent path2_2[] = { comp1, otherComp };
      rootNC.bind_context(path2_2, otherDir);
      // Now we can bind servers to a name within any of the new sub-contexts
      org.omg.CORBA.Object ttRef = new ThisOrThatServerImpl();
      org.omg.CORBA.Object otherRef = new ThisOrThatServerImpl();
      // Bind the ThisOrThatServer to the appropriate branch under "servers"
      NameComponent tt1Comp = new NameComponent("server1", "");
      NameComponent ttPath[] = { comp1, ttComp, tt1Comp };
      rootNC.bind(ttPath, ttRef);
      // Bind the other server to the "misc" branch of the "servers" dir.
      NameComponent yetAnotherComp = new NameComponent("SomeOtherServer", "");
      NameComponent otherPath[] = { comp1, otherComp, yetAnotherComp };
      rootNC.bind(otherPath, otherRef);
    }
    catch (Exception e) {
      e.printStackTrace();
    }