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);
}
Aggregations