![]() ![]() ![]() ![]() |
Searches |
In addition to the search methods, there are other methods in the DirContextinterface that read from the directory. These are:
Since the LDAP "search" operation is the primary way in which data is to be read from the directory, these other methods all use the LDAP "search" operation in one way or another. This section describes how each of these operations use the LDAP search operation. Examples of how to use each of these methods are available in the Basics
trail.
getAttributes()
This method retrieves attributes associated with the named entry. There are two forms of this method (ignoring the overloads that accept java.lang.String names instead of Namenames): The first form is equivalent to the second form with null supplied as the retAttrs argument:
The retAttrs argument contains the list of attributes to retrieve. If retAttrs contains an attribute with the special name "*", or if retAttrs is null, then all attributes of the named entry are retrieved. This method is equivalent to performing an LDAP "search" operation using the string filter "(objectclass=*)" and a search scope of SearchControls.OBJECT_SCOPEgetAttributes(name, null);, and asking that the requested attributes be returned.
lookup() and lookupLink()
These methods return the object bound to the name. If a java.io.Serializable, java.rmi.Remote, Reference, or Referenceable
object was previously bound to the name, using either bind()
or rebind()
, then the result of these methods will be an object constructed using the attributes used for storing Java objects. See the Representation
lesson for details.
Otherwise, a DirContext object representing the named entry is returned.
These methods are implemented using an LDAP "search" operation with the string filter "(objectclass=*)" and a search scope of SearchControls.OBJECT_SCOPE
, and asking for all of the entry's attributes. If the entry contains Java object-related attributes, they are used to reconstruct the object, as described in the Representation
lesson. The result is then passed to the object factory mechanism, NamingManager.getObjectInstance()
, before being returned to the caller. See Reading Objects from the Directory
lesson for details.
list() and listBindings()
list() and listBindings() list the named context and return an enumeration of NameClassPairor Binding
, respectively. These methods are implemented using an LDAP "search" operation with the string filter "(objectclass=*)" and a search scope of SearchControls.ONELEVEL_SCOPE
. The list() method asks for the "objectClass" and "javaClassName" attributes so that the class name of each entry can be determined ( NameClassPair.getClassName()
). If the "javaClassName" attribute does not exist, the class name is "javax.naming.directory.DirContext". The name of each entry ( NameClassPair.getName()
) either is relative to the named context or is an LDAP URL. The latter is used if a referral or alias has been followed.
The listBindings() method is similar to the list() method, except it asks for all of the entry's attributes. It will attempt to create for each item in the enumeration an object (to be returned by Binding.getObject()
) similar to the way lookup() creates an object from the data read from the directory.
![]() ![]() ![]() ![]() |
Searches |