FileDocCategorySizeDatePackage
SubdirTest.javaAPI DocExample2778Wed Apr 05 11:25:42 BST 2000None

SubdirTest

public class SubdirTest extends Object

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

    ORB orb = ORB.init(argv, null);
    org.omg.CORBA.Object ref = null;
    try {
      ref = orb.resolve_initial_references("NameService");
    }
    catch (InvalidName invN) {
      System.out.println("No primary NameService available.");
      System.exit(1);
    }

    try {
      // 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
      NamingContext context1 = rootNC.new_context();
      NameComponent path1[] = { comp1 };
      rootNC.bind_context(path1, context1);
      NamingContext ttDir = rootNC.new_context();
      NameComponent path2_1[] = { comp1, ttComp };
      rootNC.bind_context(path2_1, ttDir);
      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);
      System.out.println("Bound first server");
    
      // 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);
      System.out.println("Bound second server");
    }
    catch (Exception e) {
      e.printStackTrace();
    }