Previous | Next | Trail Map | Java Objects and the Directory | Reading Objects from the Directory

Lists

The List (in the Basics trail) lesson showed you how to list a context using the Context.list()(in the API reference documentation) and Context.listBindings()(in the API reference documentation) methods.

List

When you use Context.list(), you get back an enumeration of NameClassPair(in the API reference documentation). You can invoke getClassName()(in the API reference documentation) on each NameClassPair to obtain the class name of the object in that binding.

For example, if we list the context that we used to bind the various objects in the Storing Objects (in the Java Objects and the Directory trail) lesson, we get the following output:

# java List
ou=Groups: javax.naming.directory.DirContext
ou=People: javax.naming.directory.DirContext
cn=Button: java.awt.Button
cn=favorite: Fruit
cn=favDrink: javax.naming.directory.DirContext
For each binding, the Java class name was determined based on information stored in the directory, without necessarily creating an instance of the object in the binding.

List Bindings

When you use Context.listBindings(), you get back an enumeration of Binding(in the API reference documentation). You can invoke getObject()(in the API reference documentation) on each Binding to obtain the object in that binding. The result of getObject() is the same as the result obtained by looking up the object using Context.lookup()(in the API reference documentation).

For example, if we list the bindings in the context that we used to bind the various objects in the Storing Objects (in the Java Objects and the Directory trail) lesson, we get the following output:

# java ListBindings
ou=Groups: com.sun.jndi.ldap.LdapCtx: com.sun.jndi.ldap.LdapCtx@1dacd730
ou=People: com.sun.jndi.ldap.LdapCtx: com.sun.jndi.ldap.LdapCtx@1dacd8ae
cn=Button: java.awt.Button: java.awt.Button[button0,0,0,0x0,invalid,label=Push me]
cn=favorite: Fruit: orange
cn=favDrink: Drink: water
Notice that the "cn=favDrink" entry now has a more precise class name ("Drink"), because instantiating the object (by the corresponding object factory) provided more class information.


Previous | Next | Trail Map | Java Objects and the Directory | Reading Objects from the Directory