Class DirContextAdapter

java.lang.Object
org.springframework.ldap.core.DirContextAdapter
All Implemented Interfaces:
Context, DirContext, AttributeModificationsAware, DirContextOperations, LdapDataEntry

public class DirContextAdapter extends Object implements DirContextOperations
Adapter that implements the interesting methods of the DirContext interface. In particular it contains utility methods for getting and setting attributes. Using the DefaultDirObjectFactory in your ContextSource (which is the default) you will receive instances of this class from searches and lookups. This can be particularly useful when updating data, since this class implements AttributeModificationsAware, providing a getModificationItems() method. When in update mode, an object of this class keeps track of the changes made to its attributes, making them available as an array of ModificationItem objects, suitable as input to LdapTemplate.modifyAttributes(DirContextOperations).

This class is aware of the specifics of Name instances with regards to equality when working with attribute values. This comes in very handy when working with e.g. security groups and modifications of them. If Name instances are supplied to one of the Attribute manipulation methods (e.g. addAttributeValue(String, Object), removeAttributeValue(String, Object), setAttributeValue(String, Object), or setAttributeValues(String, Object[])), the produced modifications will be calculated using Name equality. This means that if an the member has a value of "cn=John Doe,ou=People", and we call addAttributeValue("member", LdapUtils.newLdapName("CN=John Doe,OU=People"), this will not be considered a modification since the two DN strings represent the same distinguished name (case and spacing between attributes is disregarded).

Note that this is not a complete implementation of DirContext. Several methods are not relevant for the intended usage of this class, so they throw UnsupportOperationException.

See Also: