use of com.unboundid.util.args.Argument in project ldapsdk by pingidentity.
the class LDAPDiff method setArgumentValueFromArgument.
/**
* Updates the specified non-legacy argument with the value from the given
* legacy argument, if it is present.
*
* @param legacyArgument The legacy argument to use to set the value
* of the specified non-legacy argument. It
* must not be {@code null}.
* @param nonLegacyArgumentName The name of the non-legacy argument to
* update with the value of the legacy
* argument. It must not be {@code null} and
* must reference a defined argument that takes
* a value.
*
* @throws ArgumentException If a problem occurs while attempting to set the
* value of the specified non-legacy argument from
* the given legacy argument.
*/
private void setArgumentValueFromArgument(@NotNull final Argument legacyArgument, @NotNull final String nonLegacyArgumentName) throws ArgumentException {
if (legacyArgument.isPresent()) {
try {
final Argument nonLegacyArgument = parser.getNamedArgument(nonLegacyArgumentName);
final Method addValueMethod = Argument.class.getDeclaredMethod("addValue", String.class);
addValueMethod.setAccessible(true);
final Method incrementOccurrencesMethod = Argument.class.getDeclaredMethod("incrementOccurrences");
incrementOccurrencesMethod.setAccessible(true);
for (final String valueString : legacyArgument.getValueStringRepresentations(false)) {
addValueMethod.invoke(nonLegacyArgument, valueString);
incrementOccurrencesMethod.invoke(nonLegacyArgument);
}
} catch (final Exception e) {
Debug.debugException(e);
final String message = ERR_LDAP_DIFF_CANNOT_SET_ARG_FROM_LEGACY.get(legacyArgument.getIdentifierString(), nonLegacyArgumentName, StaticUtils.getExceptionMessage(e));
toolCompletionMessageRef.compareAndSet(null, message);
throw new ArgumentException(message, e);
}
}
}
Aggregations