package it.mice.voila.runtime.validator;

import javax.validation.ConstraintValidatorFactory;
import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
import javax.validation.Validator;

import org.hibernate.validator.engine.ValidatorContextImpl;
import org.hibernate.validator.metadata.BeanMetaDataCache;
import org.hibernate.validator.metadata.ConstraintHelper;

public class RuntimeValidatorContextImpl extends ValidatorContextImpl {
	private final MessageInterpolator factoryMessageInterpolator;
	private final TraversableResolver factoryTraversableResolver;
	private final ConstraintValidatorFactory factoryConstraintValidatorFactory;
	private final ConstraintHelper constraintHelper;
	private final BeanMetaDataCache beanMetaDataCache;

	public RuntimeValidatorContextImpl(
			ConstraintValidatorFactory constraintValidatorFactory,
			MessageInterpolator factoryMessageInterpolator,
			TraversableResolver factoryTraversableResolver,
			ConstraintHelper constraintHelper,
			BeanMetaDataCache beanMetaDataCache) {
		super(constraintValidatorFactory, factoryMessageInterpolator,
				factoryTraversableResolver, constraintHelper, beanMetaDataCache);

		this.factoryConstraintValidatorFactory = constraintValidatorFactory;
		this.factoryMessageInterpolator = factoryMessageInterpolator;
		this.factoryTraversableResolver = factoryTraversableResolver;
		this.constraintHelper = constraintHelper;
		this.beanMetaDataCache = beanMetaDataCache;
	}

	public Validator getValidator() {
		return new RuntimeValidatorImpl(
				factoryConstraintValidatorFactory,
				factoryMessageInterpolator,
				factoryTraversableResolver,
				constraintHelper,
				beanMetaDataCache
		);
	}

}
