Searches

 


Other Context Methods

Other methods in the interface, in addition to search(), read from the directory:

Because the LDAP "search" operation is the primary way in which data is to be read from the directory, all other methods use the LDAP "search" operation in one way or another. This section describes how each method uses this operation. Examples of how to use each method are available in The Basics trail.

 

 

getAttributes()

getAttributes() retrieves attributes associated with the named entry. This method comes in two forms (ignoring the overloads that accept java.lang.String names instead of Name names): The first form is equivalent to the second form, with null supplied as the retAttrs argument:
getAttributes(name, null);
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_SCOPE and asking that the requested attributes be returned.

 

 

lookup() and lookupLink()

lookup() and lookupLink() return the object bound to the name. If a java.io.Serializable, Reference , or Referenceable object was previously bound to the name, by using either bind() or rebind(), then the result of these methods will be an object constructed by using the attributes used for storing Java objects. See the Representation in the Directory lesson for details. Otherwise, a DirContext object representing the named entry is returned.

These methods are implemented by 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, then those attributes are used to reconstruct the object, as described in the Representation in the Directory lesson. The result is then passed to the object factory mechanism, NamingManager.getObjectInstance(), before being returned to the caller. See the Reading Objects from the Directory lesson for details.

 

 

list() and listBindings()

list() and listBindings() list the named context and return an enumeration of NameClassPair or Binding , respectively. These methods are implemented by using an LDAP "search" operation with the string filter "(objectclass=*)" and a search scope of SearchControls.ONELEVEL_SCOPE. list() 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.

listBindings() resembles list(), except that 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 that lookup() creates an object from the data read from the directory.