![]() ![]() ![]() ![]() |
Reading Objects from the Directory |
The Searchlesson showed you how to use the various DirContext.search()
methods. When you perform a search using a SearchControls
parameter, you can control what gets returned in each SearchResult
. Specifically, if you invoke the SearchControls.setReturningObjFlag()
method with true, and pass that to search(), each entry in the SearchResult will contain the corresponding Java object. This example searches the context that we used to bind the various objects in the Storing Objects
lesson, and prints each result's object (class name and object reference):
The output of this example is as follows:SearchControls ctls = new SearchControls(); ctls.setReturningObjFlag(true); // Specify the search filter to match any object String filter = "(objectclass=*)"; // Search for objects using filter NamingEnumeration answer = ctx.search("", filter, ctls);#java Search ou=Groups: com.sun.jndi.ldap.LdapCtx: com.sun.jndi.ldap.LdapCtx@1dacd78d ou=People: com.sun.jndi.ldap.LdapCtx: com.sun.jndi.ldap.LdapCtx@1dacd91b cn=Button: java.awt.Button: java.awt.Button[button0,0,0,0x0,invalid,label=Push me] cn=favorite: Fruit: orange cn=favDrink: Drink: waterReading Objects from the Directory: End of Lesson
![]()
![]()
What's next? Now you can:
- Continue on in this trail to learn how object factories interact with the reading of object representations from the directory.
- Go to the Representation in the Directory
lesson to read about the physical representation of Java objects in the directory.
![]() ![]() ![]() ![]() |
Reading Objects from the Directory |