Search in sources :

Example 11 with Argument

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);
        }
    }
}
Also used : IntegerArgument(com.unboundid.util.args.IntegerArgument) ScopeArgument(com.unboundid.util.args.ScopeArgument) Argument(com.unboundid.util.args.Argument) DNArgument(com.unboundid.util.args.DNArgument) BooleanArgument(com.unboundid.util.args.BooleanArgument) FileArgument(com.unboundid.util.args.FileArgument) StringArgument(com.unboundid.util.args.StringArgument) FilterArgument(com.unboundid.util.args.FilterArgument) Method(java.lang.reflect.Method) ArgumentException(com.unboundid.util.args.ArgumentException) ArgumentException(com.unboundid.util.args.ArgumentException) LDAPException(com.unboundid.ldap.sdk.LDAPException) IOException(java.io.IOException)

Aggregations

Argument (com.unboundid.util.args.Argument)11 BooleanArgument (com.unboundid.util.args.BooleanArgument)9 FileArgument (com.unboundid.util.args.FileArgument)9 StringArgument (com.unboundid.util.args.StringArgument)7 IntegerArgument (com.unboundid.util.args.IntegerArgument)6 ArrayList (java.util.ArrayList)6 SubCommand (com.unboundid.util.args.SubCommand)5 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)4 LDAPException (com.unboundid.ldap.sdk.LDAPException)4 ArgumentException (com.unboundid.util.args.ArgumentException)4 DurationArgument (com.unboundid.util.args.DurationArgument)4 TimestampArgument (com.unboundid.util.args.TimestampArgument)4 ArgumentParser (com.unboundid.util.args.ArgumentParser)3 DNArgument (com.unboundid.util.args.DNArgument)3 FilterArgument (com.unboundid.util.args.FilterArgument)3 BooleanValueArgument (com.unboundid.util.args.BooleanValueArgument)2 ControlArgument (com.unboundid.util.args.ControlArgument)2 ScopeArgument (com.unboundid.util.args.ScopeArgument)2 Method (java.lang.reflect.Method)2 List (java.util.List)2