Example usage for javax.naming.directory Attribute equals

List of usage examples for javax.naming.directory Attribute equals

Introduction

In this page you can find the example usage for javax.naming.directory Attribute equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:org.springframework.ldap.core.DirContextAdapter.java

/**
 * Collect all modifications for the changed attribute. If no changes have
 * been made, return immediately. If modifications have been made, and the
 * original size as well as the updated size of the attribute is 1, replace
 * the attribute. If the size of the updated attribute is 0, remove the
 * attribute. Otherwise, the attribute is a multi-value attribute; if it's
 * an ordered one it should be replaced in its entirety to preserve the new
 * ordering, if not all modifications to the original value (removals and
 * additions) will be collected individually.
 * //from  w ww  .  j  a v a2s  .  c  o m
 * @param changedAttr the value of the changed attribute.
 * @param modificationList the list in which to add the modifications.
 * @throws NamingException if thrown by called Attribute methods.
 */
private void collectModifications(Attribute changedAttr, List modificationList) throws NamingException {
    Attribute currentAttribute = originalAttrs.get(changedAttr.getID());

    if (changedAttr.equals(currentAttribute)) {
        // No changes
        return;
    } else if (currentAttribute != null && currentAttribute.size() == 1 && changedAttr.size() == 1) {
        // Replace single-vale attribute.
        modificationList.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, changedAttr));
    } else if (changedAttr.size() == 0 && currentAttribute != null) {
        // Attribute has been removed.
        modificationList.add(new ModificationItem(DirContext.REMOVE_ATTRIBUTE, changedAttr));
    } else if ((currentAttribute == null || currentAttribute.size() == 0) && changedAttr.size() > 0) {
        // Attribute has been added.
        modificationList.add(new ModificationItem(DirContext.ADD_ATTRIBUTE, changedAttr));
    } else if (changedAttr.size() > 0 && changedAttr.isOrdered()) {
        // This is a multivalue attribute and it is ordered - the original
        // value should be replaced with the new values so that the ordering
        // is preserved.
        modificationList.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, changedAttr));
    } else if (changedAttr.size() > 0) {
        // Change of multivalue Attribute. Collect additions and removals
        // individually.
        List myModifications = new LinkedList();
        collectModifications(currentAttribute, changedAttr, myModifications);

        if (myModifications.isEmpty()) {
            // This means that the attributes are not equal, but the
            // actual values are the same - thus the order must have
            // changed. This should result in a REPLACE_ATTRIBUTE operation.
            myModifications.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, changedAttr));
        }

        modificationList.addAll(myModifications);
    }
}