Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * JBoss, Home of Professional Open Source
  * Copyright 2013, Red Hat Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site:
A javax.validation.ValidationProviderResolver to be used within WildFly. If several BV providers are available, HibernateValidator will be the first element of the returned provider list.

The providers are loaded via the current thread's context class loader; If no providers are found, the loader of this class will be tried as fallback.

Note: This class is a copy of

Hardy Ferentschik
Gunnar Morling
public class WildFlyProviderResolver implements ValidationProviderResolver {

Returns a list with all javax.validation.spi.ValidationProvider validation providers.

a list with all javax.validation.spi.ValidationProvider validation providers
        // first try the TCCL
        List<ValidationProvider<?>> providers = loadProviders(WildFlySecurityManager.getCurrentContextClassLoaderPrivileged());
        if (providers != null && !providers.isEmpty()) {
            return providers;
        // otherwise use the loader of this class
        else {
            return loadProviders(WildFlySecurityManager.getClassLoaderPrivileged(WildFlyProviderResolver.class));

Retrieves the providers from the given loader, using the service loader mechanism.

classLoader the class loader to use
a list with providers retrieved via the given loader. May be empty but never null
    private List<ValidationProvider<?>> loadProviders(ClassLoader classLoader) {
        Iterator<ValidationProviderproviderIterator = ServiceLoader.load(ValidationProvider.classclassLoader).iterator();
        LinkedList<ValidationProvider<?>> providers = new LinkedList<ValidationProvider<?>>();
        while (providerIterator.hasNext()) {
            try {
                ValidationProvider<?> provider =;
                // put Hibernate Validator to the beginning of the list
                if (provider.getClass().getName().equals(HibernateValidator.class.getName())) {
                } else {
            } catch (ServiceConfigurationError e) {
                // ignore, because it can happen when multiple
                // providers are present and some of them are not class loader
                // compatible with our API.
        return providers;
New to GrepCode? Check out our FAQ X