import javax.naming.*;
import java.util.Hashtable;

/**
 * Demonstrates how to list the bindings in a context.
 *
 * usage: java ListBindings
 */
class ListBindings {
    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");

	// So that object factory can be found
	env.put(Context.OBJECT_FACTORIES, "DrinkFactory");

	try {
	    // Create the initial context
	    Context ctx = new InitialContext(env);

	    // Get listing of context
	    NamingEnumeration bindings = ctx.listBindings("");

	    // Go through each item in list
	    while (bindings.hasMore()) {
		Binding bd = (Binding)bindings.next();
		System.out.println(bd.getName() + ": " + 
		    bd.getClassName() + ": " + bd.getObject());
	    }
	} catch (NamingException e) {
	    System.out.println("List Bindings failed: " + e);
	}
    }
}
