FileDocCategorySizeDatePackage
list.javaAPI DocExample2574Thu Dec 15 21:26:14 GMT 2005com.oreilly.jent.jndi

list

public class list extends Object implements Command
list: Command to list the contents of a JNDI context.

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

        
    String name = "";
        
    // An empty string is OK for a list operation as it means
    // list children of the current context.
    if (!(v.isEmpty()))
      name = (String)v.firstElement();
        
    // Check for current context; throw an exception if there isn’t one
    if (NamingShell.getCurrentContext() == null)
      throw new CommandException(new Exception(), 
        "Error: no current context.");

    // Call list() and then loop through the results, printing the names
    // and class names of the children
    try {
      NamingEnumeration ctxEnum = c.list(name);                
      while (ctxEnum.hasMore()) {
        NameClassPair ncPair = (NameClassPair)ctxEnum.next();
        System.out.print(ncPair.getName() + " (type ");
        System.out.println(ncPair.getClassName() + ")");
      }
    }
    catch (NamingException e) {
      throw new CommandException(e, "Couldn't list " + name);
    }
  
public voidhelp()

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