FileDocCategorySizeDatePackage
NamingSubdirs.javaAPI DocExample2764Wed Apr 05 11:25:42 BST 2000None

NamingSubdirs

public class NamingSubdirs 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("Primary naming service unavailable.");
      invN.printStackTrace();
      System.exit(1);
    }
    NamingContext localNC = NamingContextHelper.narrow(ref);
    System.out.println("Got primary Naming Service.");
    NameComponent nodeName = new NameComponent("RemoteContexts", "");
    NameComponent sub1 = new NameComponent("sub1", "foo");
    NameComponent sub2 = new NameComponent("sub1", "bar");
    NameComponent path1[] = {nodeName};
    NameComponent path2[] = {nodeName, sub1};
    NameComponent path2_1[] = {nodeName, sub2};
    NameComponent fullPath[] = {nodeName, sub1,
                                new NameComponent("object", "")};
    NameComponent fullPath2[] = {nodeName, sub2,
                                 new NameComponent("object", "")};
    NameComponent fullPath2v2[] = {nodeName,
                                   new NameComponent("sub1", ""),
                                   new NameComponent("foo", ""),
                                   new NameComponent("object", "")};
    try {
      NamingContext node = localNC.bind_new_context(path1);
      node = localNC.bind_new_context(path2);
      node = localNC.bind_new_context(path2_1);
      ServerImpl server = new ServerImpl();
      localNC.bind(fullPath, server);
      localNC.bind(fullPath2, server);
    }
    catch (Exception e) {
      System.out.println("Failed to bind objects/context to primary.");
      e.printStackTrace();
    }

    // Try getting name context
    try {
      ref = localNC.resolve(fullPath2v2);
      ref = localNC.resolve(path2);
      NamingContext nc = NamingContextHelper.narrow(ref);
      System.out.println("Got context...");
      NameComponent relPath[] = {new NameComponent("object", "")};
      ref = nc.resolve(relPath);
      Server server = ServerHelper.narrow(ref);
      System.out.println("Got server...");
    }
    catch (Exception e2) {
      System.out.println("Couldn't resolve subdir.");
      e2.printStackTrace();
    }