FileDocCategorySizeDatePackage
cd.javaAPI DocExample1948Wed Apr 05 11:25:42 BST 2000None

cd

public class cd extends Object implements Command

Fields Summary
Constructors Summary
Methods Summary
public voidexecute(javax.naming.Context ctx, java.util.Vector v)

    if (NamingShell.getCurrentContext() == null)
      throw new CommandException(new Exception(), "No current context");
    else if (v.isEmpty())
      throw new CommandException(new Exception(), "No name specified");

    // get args[0] and throw away the other args
    else {
      String name = (String)v.firstElement();
      try {
        if (name.equals("..")) {
          throw new CommandException(new Exception(), 
            "Contexts don't know about their parents");
        }
        else if (((name.equals("/")) || (name.equals("\\"))) ) {
          NamingShell.setCurrentContext(NamingShell.getInitialContext());
          NamingShell.setCurrentName(NamingShell.getInitialName());
          System.out.println("Returning to initial context");
        }
        else {
          Context c = (Context)NamingShell.getCurrentContext().lookup(name);
          NamingShell.setCurrentContext(c);
          NamingShell.setCurrentName(name);
          System.out.println("Current context now " + name);
        }
      }
      catch (NamingException ne) {
        throw new CommandException(ne, "Couldn't change to context " + name);
      }
      catch (ClassCastException cce) {
        throw new CommandException(cce, name + " not a Context");
      }
    }
  
public voidhelp()

 System.out.println("Usage: cd [name]");