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);
}