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 you list the context that you used to bind the various objects in the Storing Objects in the Directory (in the Java Objects and the Directory trail) lesson, 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 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 you list the bindings in the context that you used to bind the various objects in the Storing Objects (in the Java Objects and the Directory trail) lesson, 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"), because instantiating the object (by the corresponding object factory) provided more class information. Notice also that the remote object HelloImpl is returned as a stub to the real object.

Note 1: You must run this example using the Java 2 Platform, v 1.2, or higher releases 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 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.


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