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


The Directory Operations (in the Basics trail) lesson showed how to use the various the API reference documentation) methods. When you perform a search using a SearchControls(in the API reference documentation) parameter, you can control what gets returned in each SearchResult(in the API reference documentation). Specifically, if you invoke SearchControls.setReturningObjFlag()(in the API reference documentation) with true and pass that to search(), then each entry in the SearchResult will contain the corresponding Java object.

The following example searches the context used to bind the various objects in the Storing Objects in the Directory (in the Java Objects and the Directory trail) lesson and prints each result's object (class name and object reference).

SearchControls ctls = new SearchControls();

// Specify the search filter to match any object
String filter = "(objectclass=*)";

// Search for objects by using the filter
NamingEnumeration answer ="", filter, ctls);
The output of this example is as follows.
# java Search
ou=Groups: com.sun.jndi.ldap.LdapCtx: com.sun.jndi.ldap.LdapCtx@723fdc9a
ou=People: com.sun.jndi.ldap.LdapCtx: com.sun.jndi.ldap.LdapCtx@642fdc9a
cn=Fruits: com.sun.jndi.ldap.LdapCtx: com.sun.jndi.ldap.LdapCtx@63afdc9a
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=CorbaHello: com.sun.CORBA.idl.CORBAObjectImpl: com.sun.CORBA.idl.CORBAObjectImpl:com.sun.CORBA.idl.GenericCORBAClientSC@8a9e173a
cn=RemoteHello: HelloImpl_Stub: HelloImpl_Stub[RemoteStub [ref: [endpoint:[](remote),objID:[75de816d:d98468df8c:-8000, 0]]]]
cn=RefHello: HelloImpl_Stub: HelloImpl_Stub[RemoteStub [ref: [endpoint:[](remote),objID:[272f25a1:d9846946ca:-8000, 0]]]]
cn=Custom: com.sun.jndi.ldap.LdapCtx: com.sun.jndi.ldap.LdapCtx@db7a1739
cn=John Smith: Person: My name is Smith, John Smith.
cn=RmiiiopHello: com.sun.CORBA.idl.CORBAObjectImpl: com.sun.CORBA.idl.CORBAObjectImpl:com.sun.CORBA.idl.GenericCORBAClientSC@ac6b5dd2
The same notes that apply to the list bindings example also apply to this example.

Reading Objects from the Directory: End of Lesson

What's next? Now you can:

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