// get right expression - if it is not a literal we
// can't handle that so throw an exception
rightExpr = setClause.getValue();
if (!(rightExpr instanceof Literal)) {
final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.valueNotLiteralError",nameLeftElement); //$NON-NLS-1$
throw new TranslatorException(msg);
}
valueRightExpr = ((Literal)rightExpr).getValue();
// add in the modification as a replacement - meaning
// any existing value(s) for this attribute will
// be replaced by the new value. If the attribute
// didn't exist, it will automatically be created
// TODO - since null is a valid attribute
// value, we don't do any special handling of it right
// now. But maybe null should mean to delete an
// attribute?
updateMods[i] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(nameLeftElement, valueRightExpr));
}
// just try to update an LDAP entry using the DN and
// attributes specified in the UPDATE operation. If it isn't
// legal, we'll get a NamingException back, whose explanation
// we'll return in a ConnectorException
try {
ldapCtx.modifyAttributes(distinguishedName, updateMods);
} catch (NamingException ne) {
final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.updateFailed",distinguishedName,ne.getExplanation()); //$NON-NLS-1$
throw new TranslatorException(msg);
// don't remember why I added this generic catch of Exception,
// but it does no harm...
} catch (Exception e) {
final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.updateFailedUnexpected",distinguishedName); //$NON-NLS-1$
throw new TranslatorException(e, msg);
}
}