Modifications are applied in the order in which they appear in the list. Either all of the modifications are executed, or none are.
The following code creates a list of modifications. It replaces the "mail" attribute's value with a value of "geisel@wizards.com", adds an additional value to the "telephonenumber" attribute, and removes the "jpegphoto" attribute.
// Specify the changes to make
ModificationItem[] mods = new ModificationItem[3];
// Replace the "mail" attribute with a new value
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute("mail", "geisel@wizards.com"));
// Add an additional value to "telephonenumber"
mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
new BasicAttribute("telephonenumber", "+1 555 555 5555"));
// Remove the "jpegphoto" attribute
mods[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE,
new BasicAttribute("jpegphoto"));
After creating this list of modifications, you can supply it to modifyAttributes() as follows.
// Perform the requested modifications on the named object ctx.modifyAttributes(name, mods);
For example, the following line replaces the attributes (identified in orig) associated with name with those in orig:
ctx.modifyAttributes(name, DirContext.REPLACE_ATTRIBUTE, orig);
Both of these uses of modifyAttributes() are demonstrated in the sample program. This program modifies the attributes by using a modification list and then uses the second form of modifyAttributes() to restore the original attributes.