boolean executeValidationMethod()

in src/main/java/org/apache/commons/validator/ValidatorAction.java [153:216]


    boolean executeValidationMethod(final Field field,
            // TODO What is this the correct value type?
            // both ValidatorAction and Validator are added as parameters
            final Map<String, Object> params, final ValidatorResults results, final int pos) throws ValidatorException {

        params.put(Validator.VALIDATOR_ACTION_PARAM, this);

        try {
            if (validationMethod == null) {
                synchronized (this) {
                    final ClassLoader loader = getClassLoader(params);
                    loadValidationClass(loader);
                    loadParameterClasses(loader);
                    loadValidationMethod();
                }
            }

            final Object[] paramValues = getParameterValues(params);

            if (field.isIndexed()) {
                handleIndexedField(field, pos, paramValues);
            }

            Object result = null;
            try {
                result = validationMethod.invoke(getValidationClassInstance(), paramValues);

            } catch (IllegalArgumentException | IllegalAccessException e) {
                throw new ValidatorException(e.getMessage());
            } catch (final InvocationTargetException e) {

                if (e.getTargetException() instanceof Exception) {
                    throw (Exception) e.getTargetException();

                }
                if (e.getTargetException() instanceof Error) {
                    throw (Error) e.getTargetException();
                }
            }

            final boolean valid = isValid(result);
            if (!valid || valid && !onlyReturnErrors(params)) {
                results.add(field, name, valid, result);
            }

            if (!valid) {
                return false;
            }

            // TODO This catch block remains for backward compatibility. Remove
            // this for Validator 2.0 when exception scheme changes.
        } catch (final Exception e) {
            if (e instanceof ValidatorException) {
                throw (ValidatorException) e;
            }

            getLog().error("Unhandled exception thrown during validation: " + e.getMessage(), e);

            results.add(field, name, false);
            return false;
        }

        return true;
    }