![]() ![]() ![]() ![]() |
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);The same notes that apply to the list bindings example also apply to this example.#java -Djava.security.manager -Djava.security.policy=.policy 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:[129.111.111.111:46547](remote),objID:[75de816d:d98468df8c:-8000, 0]]]] cn=RefHello: HelloImpl_Stub: HelloImpl_Stub[RemoteStub [ref: [endpoint:[129.111.111.111:46550](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@ac6b5dd2Reading 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 |