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

io.quarkus.hibernate.validator.runtime.locale.LocaleResolversWrapper Maven / Gradle / Ivy

package io.quarkus.hibernate.validator.runtime.locale;

import java.util.Locale;

import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.inject.Singleton;

import org.hibernate.validator.spi.messageinterpolation.LocaleResolver;
import org.hibernate.validator.spi.messageinterpolation.LocaleResolverContext;

/**
 * Wrapper for potentially multiple locale resolvers. The first one that actually returns a non-null Locale will be used.
 */
@Singleton
@Named("locale-resolver-wrapper")
public class LocaleResolversWrapper implements LocaleResolver {

    @Inject
    Instance resolvers;

    @Override
    public Locale resolve(LocaleResolverContext context) {
        for (LocaleResolver resolver : resolvers) {
            if (!resolver.equals(this)) {
                Locale locale = resolver.resolve(context);
                if (locale != null) {
                    return locale;
                }
            }
        }
        return context.getDefaultLocale();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy