FileDocCategorySizeDatePackage
listattrs.javaAPI DocExample2890Thu Dec 15 21:26:30 GMT 2005com.oreilly.jent.jndi

listattrs

public class listattrs extends Object implements Command
listattrs: Command to list the attributes of a given directory 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 listattrs operation
    // as it means list attributes of the current context
    if (!(v.isEmpty()))
      name = (String)v.firstElement();
        
    if (NamingShell.getCurrentContext() == null)
      throw new CommandException(new Exception(), "No current context");       

    try {
      // Get the Attributes and then get enumeration of Attribute objects
      Attributes attrs = ((DirContext)c).getAttributes(name);
      NamingEnumeration allAttr = attrs.getAll();
      while (allAttr.hasMore()) {
        Attribute attr = (Attribute)allAttr.next();
        System.out.println("Attribute: " + attr.getID());
                
        // Note that this can return human-unreadable garbage
        NamingEnumeration values = attr.getAll();
        while (values.hasMore())
          System.out.println("Value: " + values.next());
      }
    }
    catch (NamingException e) {
      throw new CommandException(e, "Couldn't list attributes of " + name);
    }
    catch (ClassCastException cce) {
      throw new CommandException(cce, "Not a directory context");
    }
  
public voidhelp()

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