| Reading Objects from the Directory

## Lists

> The Naming Operations lesson showed you how to list a context using the `Context.list()` and `Context.listBindings()` methods. This section describes how these methods are affected by object factories.

> #### List

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

> For example, if you list the context that you used to bind the various objects in the Storing Objects in the Directory lesson, then you get the following output.

> >     # java List
> >     ou=Groups: javax.naming.directory.DirContext
> >     ou=People: javax.naming.directory.DirContext
> >     cn=Button: java.awt.Button
> >     cn=Flower: Flower
> >     cn=favorite: Fruit
> >     cn=favDrink: javax.naming.directory.DirContext
> >     cn=RefHello: Hello
> >     cn=CorbaHello: javax.naming.directory.DirContext
> >     cn=RmiiiopHello: javax.naming.directory.DirContext
> >     cn=RemoteHello: HelloImpl

> For each binding, the Java class name was determined based on information stored in the directory, without an instance of the object in the binding necessarily having to be created. No object factory was involved.

> #### List Bindings

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

> For example, if you list the bindings in the context that you used to bind the various objects in the Storing Objects in the Directory lesson, then you get the following output.

> >     # java -Djava.security.manager -Djava.security.policy=.policy 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=Flower: Flower: pink rose
> >     cn=favorite: Fruit: orange
> >     cn=favDrink: Drink: water
> >     cn=RemoteHello: HelloImpl_Stub: HelloImpl_Stub[RemoteStub [ref: [endpoint:[129.111.111.111:44999](remote),objID:[-68dff7b3:d975735a08:-8000, 0]]]]
> >     cn=RefHello: HelloImpl_Stub: HelloImpl_Stub[RemoteStub [ref: [endpoint:[129.111.111.111:45006](remote),objID:[2bf4308e:d975745b44:-8000, 0]]]]
> >     cn=CorbaHello: com.sun.CORBA.idl.CORBAObjectImpl: com.sun.CORBA.idl.CORBAObjectImpl:com.sun.CORBA.idl.GenericCORBAClientSC@84675dd2
> >     cn=RmiiiopHello: com.sun.CORBA.idl.CORBAObjectImpl: com.sun.CORBA.idl.CORBAObjectImpl:com.sun.CORBA.idl.GenericCORBAClientSC@ac6b5dd2

> Notice that the `"cn=favDrink"` entry and a few others now have a more precise class name (`"Drink"`, `"HelloImpl_Stub"`). This is because instantiating the object (by the corresponding object factory) provided more class information. Notice also that the remote object `HelloImpl` was returned as a stub to the real object.

> Note 1: You must run this example by using the Java 2 Platform, v1.2, or higher release because some of the object factories require that platform.

> Note 2: The `-Djava.security.manager` option specifies that the default security manager be used, and the `-Djava.security.policy=.policy` option specifies that the `.policy` file be used for the security policy. These two options are needed when you are listing/looking up the `java.rmi.Remote` objects. In the policy file, you need to grant permission to connect to and accept connections from the Web server and the machine on which the remote objects are running.

| Reading Objects from the Directory