FileDocCategorySizeDatePackage
cd.javaAPI DocExample2874Thu Dec 15 21:13:34 GMT 2005com.oreilly.jent.jndi

cd

public class cd extends Object implements Command
cd: Command to re-position the NamingShell to a new context within the JNDI name space.

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]");