Search in sources :

Example 1 with LDAPModification

use of org.opends.server.protocols.ldap.LDAPModification in project OpenAM by OpenRock.

the class SMSEmbeddedLdapObject method copyModItemsToLDAPModList.

// Method to covert JNDI ModificationItems to LDAPModificationSet
private static List copyModItemsToLDAPModList(ModificationItem[] mods) throws SMSException {
    if ((mods == null) || (mods.length == 0)) {
        return null;
    }
    List<LDAPModification> modList = new ArrayList<>(mods.length);
    try {
        for (ModificationItem mod : mods) {
            Attribute dAttr = mod.getAttribute();
            String attrName = dAttr.getID();
            List<String> values = new ArrayList<>();
            for (NamingEnumeration ne = dAttr.getAll(); ne.hasMore(); ) {
                values.add((String) ne.next());
            }
            ModificationType modType = null;
            switch(mod.getModificationOp()) {
                case DirContext.ADD_ATTRIBUTE:
                    modType = ModificationType.ADD;
                    break;
                case DirContext.REPLACE_ATTRIBUTE:
                    modType = ModificationType.REPLACE;
                    break;
                case DirContext.REMOVE_ATTRIBUTE:
                    modType = ModificationType.DELETE;
                    break;
            }
            if (modType != null) {
                modList.add(new LDAPModification(modType, new LDAPAttribute(attrName, values)));
            }
        }
    } catch (NamingException nne) {
        throw (new SMSException(nne, "sms-cannot-copy-fromModItemToModSet"));
    }
    return (modList);
}
Also used : ModificationItem(javax.naming.directory.ModificationItem) LDAPAttribute(org.opends.server.protocols.ldap.LDAPAttribute) Attribute(javax.naming.directory.Attribute) LDAPAttribute(org.opends.server.protocols.ldap.LDAPAttribute) ModificationType(org.forgerock.opendj.ldap.ModificationType) SMSException(com.sun.identity.sm.SMSException) LDAPModification(org.opends.server.protocols.ldap.LDAPModification) ArrayList(java.util.ArrayList) NamingEnumeration(javax.naming.NamingEnumeration) NamingException(javax.naming.NamingException)

Aggregations

SMSException (com.sun.identity.sm.SMSException)1 ArrayList (java.util.ArrayList)1 NamingEnumeration (javax.naming.NamingEnumeration)1 NamingException (javax.naming.NamingException)1 Attribute (javax.naming.directory.Attribute)1 ModificationItem (javax.naming.directory.ModificationItem)1 ModificationType (org.forgerock.opendj.ldap.ModificationType)1 LDAPAttribute (org.opends.server.protocols.ldap.LDAPAttribute)1 LDAPModification (org.opends.server.protocols.ldap.LDAPModification)1