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

org.wisdom.validation.hibernate.WrappedExecutableValidator Maven / Gradle / Ivy

There is a newer version: 0.10.0
Show newest version
/*
 * #%L
 * Wisdom-Framework
 * %%
 * Copyright (C) 2013 - 2014 Wisdom Framework
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package org.wisdom.validation.hibernate;

import javax.validation.ConstraintViolation;
import javax.validation.executable.ExecutableValidator;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Set;

/**
 * An Executable Validator delegating to the Hibernate validator, but wrapping methods triggering classloading to set
 * the TCCL.
 */
public class WrappedExecutableValidator implements ExecutableValidator {

    private final ExecutableValidator delegate;

    WrappedExecutableValidator(ExecutableValidator delegate) {
        this.delegate = delegate;
    }

    @Override
    public  Set> validateParameters(T t, Method method, Object[] objects, Class... classes) {
        final ClassLoader original = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
            return delegate.validateParameters(t, method, objects, classes);
        } finally {
            Thread.currentThread().setContextClassLoader(original);
        }
    }

    @Override
    public  Set> validateReturnValue(T t, Method method, Object o, Class... classes) {
        return delegate.validateReturnValue(t, method, o, classes);
    }

    @Override
    public  Set> validateConstructorParameters(Constructor constructor, Object[] objects, Class... classes) {
        return delegate.validateConstructorParameters(constructor, objects, classes);
    }

    @Override
    public  Set> validateConstructorReturnValue(Constructor constructor, T t, Class... classes) {
        return delegate.validateConstructorReturnValue(constructor, t, classes);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy