import javax.naming.*;
import javax.naming.directory.*;

import java.util.Hashtable;

/**
 * Demonstrates how to retrieve selected attributes of a named object.
 *
 * usage: java Getattrs
 */
class Getattrs {
    public static void main(String[] args) {

	// Set up environment for creating initial context
	Hashtable env = new Hashtable(11);
	env.put(Context.INITIAL_CONTEXT_FACTORY, 
	    "com.sun.jndi.ldap.LdapCtxFactory");
	env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");

	try {
	    // Create initial context
	    DirContext ctx = new InitialDirContext(env);

	    // Specify the ids of the attributes to return
	    String[] attrIDs = {"sn", "telephonenumber", "golfhandicap", "mail"};

	    // Get the attributes requested
	    Attributes answer = 
		ctx.getAttributes("cn=Ted Geisel, ou=People", attrIDs);

	    // Print the answer
	    GetattrsAll.printAttrs(answer);
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}
