Example usage for javax.naming.directory Attribute isOrdered

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

Introduction

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

Prototype

boolean isOrdered();

Source Link

Document

Determines whether this attribute's values are ordered.

Usage

From source file:de.acosix.alfresco.mtsupport.repo.auth.ldap.EnhancedLDAPUserRegistry.java

protected Collection<Object> mapAttribute(final Attribute attribute) throws NamingException {
    Collection<Object> values;
    if (attribute.isOrdered()) {
        values = new ArrayList<>();
    } else {/*from   www  .j  a  v  a  2s.c o  m*/
        values = new HashSet<>();
    }
    final NamingEnumeration<?> allAttributeValues = attribute.getAll();
    while (allAttributeValues.hasMore()) {
        final Object next = allAttributeValues.next();
        final Object mappedValue = this.mapAttributeValue(attribute.getID(), next);
        values.add(mappedValue);
    }

    LOGGER.debug("Mapped value of {} to {}", attribute, values);

    return values;
}

From source file:de.acosix.alfresco.mtsupport.repo.auth.ldap.EnhancedLDAPUserRegistry.java

protected <T> Collection<T> mapAttribute(final Attribute attribute, final Class<T> expectedValueClass)
        throws NamingException {
    Collection<T> values;/*from   w  w w  .  j av  a2s  . c o m*/
    if (attribute.isOrdered()) {
        values = new ArrayList<>();
    } else {
        values = new HashSet<>();
    }
    final NamingEnumeration<?> allAttributeValues = attribute.getAll();
    while (allAttributeValues.hasMore()) {
        final Object next = allAttributeValues.next();
        final Object mappedValue = this.mapAttributeValue(attribute.getID(), next);
        final T value = DefaultTypeConverter.INSTANCE.convert(expectedValueClass, mappedValue);
        values.add(value);
    }

    LOGGER.debug("Mapped value of {} to {}", attribute, values);

    return values;
}

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 www  . j a va  2s .  com*/
 * @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);
    }
}