Previous | Next | Trail Map | Tips for LDAP Users | 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 (in the Basics trail) 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(in the API reference documentation) 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(in the API reference documentation) 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 (in the API reference documentation), or Referenceable (in the API reference documentation) object was previously bound to the name, by using either bind()(in the API reference documentation) or rebind()(in the API reference documentation), 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 (in the Java Objects and the Directory trail) 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(in the API reference documentation), 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 (in the Java Objects and the Directory trail) lesson. The result is then passed to the object factory mechanism, NamingManager.getObjectInstance()(in the API reference documentation), before being returned to the caller. See the Reading Objects from the Directory (in the Java Objects and the Directory trail) lesson for details.

list() and listBindings()

list() and listBindings() list the named context and return an enumeration of NameClassPair (in the API reference documentation) or Binding (in the API reference documentation), respectively. These methods are implemented by using an LDAP "search" operation with the string filter "(objectclass=*)" and a search scope of SearchControls.ONELEVEL_SCOPE(in the API reference documentation). list() asks for the "objectClass" and "javaClassName" attributes so that the class name of each entry can be determined ( NameClassPair.getClassName() (in the API reference documentation)). If the "javaClassName" attribute does not exist, the class name is "javax.naming.directory.DirContext". The name of each entry ( NameClassPair.getName() (in the API reference documentation)) 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() (in the API reference documentation)) similar to the way that lookup() creates an object from the data read from the directory.


Previous | Next | Trail Map | Tips for LDAP Users | Searches