All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cz.jalasoft.util.configuration.ConverterIntegrityValidator Maven / Gradle / Ivy

The newest version!
package cz.jalasoft.util.configuration;

import cz.jalasoft.util.configuration.exception.InvalidPropertyMethod;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @author Honza Lastovicka ([email protected])
 * @since 2016-07-31.
 */
final class ConverterIntegrityValidator {

    private final ConverterRegistry converterRegistry;

    public ConverterIntegrityValidator(ConverterRegistry converterRegistry) {
        this.converterRegistry = converterRegistry;
    }

    void validate(Class type) {
        Method[] methods = type.getDeclaredMethods();
        Arrays.stream(methods).forEach(this::assertReturnValueHasConverter);
    }

    private void assertReturnValueHasConverter(Method method) {
        Class returnType = method.getReturnType();

        if (!converterRegistry.hasConverter(returnType)) {
            throw new InvalidPropertyMethod(method, "Method returns a value of type '" + returnType + "' for which no converter is registered.");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy