<commit_before>package org.springframework.binding.validation.support;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;
import org.springframework.binding.form.ValidatingFormModel;
import org.springframework.binding.validation.ValidationMessage;
import org.springframework.binding.validation.ValidationResults;
import org.springframework.richclient.core.Severity;
import org.springframework.richclient.util.Assert;
import org.springframework.rules.RulesSource;

/**
 * Validator that combines Hibernate validation with rules defined by a
 * RulesSource. First the rules will be checked, then validation will occurs
 * through a ClassValidator.<br/>
 *
 * Usage in a {@link ValidatingFormModel}: <br>
 *
 * {@example formModel.setValidator( new HibernateRulesValidator(formModel, rulesSource, SomeClass.class)); }
 *
 * @author <NAME>
 * @author <NAME>
 *
 */
@SuppressWarnings("unchecked")
public class HibernateRulesValidator extends RulesValidator {

	private final ClassValidator hibernateValidator;

	private ValidatingFormModel formModel;

	private DefaultValidationResults results = new DefaultValidationResults();

	private Map<String, DefaultValidationResults> propertyResults;

	private Set<String> ignoredHibernateProperties;

	/**
	 * Creates a new HibernateRulesValidator
	 *
	 * @param formModel The {@link ValidatingFormModel} on which validation
	 * needs to occur
	 * @param rulesSource The {@link RulesSource} that contains the rules. If
	 * <code>null</code>, no rules will be enfored.
	 * @param clazz The class of the object this validator needs to check
	 */
	public HibernateRulesValidator(ValidatingFormModel formModel, RulesSource rulesSource, Class clazz) {
		super(formModel, rulesSource);
		this.formModel = formModel;
		hibernateValidator = new ClassValidator(clazz, new HibernateRulesMessageInterpolator());
		propertyResults = new HashMap<String, DefaultValidationResults>();
		ignoredHibernateProperties = new HashSet<String>();
	}

	/**
	 * Creates a new HibernateRulesValidator without specific Rules
	 *
	 * @param formModel The {@link ValidatingFormModel} on which validation
	 * needs to occur
	 * @param rulesSource The {@link RulesSource} that contains the rules. If
	 * <code>null</code>, no rules will be enfored.
	 * @param clazz The class of the object this validator needs to check
	 */
	public HibernateRulesValidator(ValidatingFormModel formModel, Class clazz) {
		super(formModel, null);
		this.formModel = formModel;
		hibernateValidator = new ClassValidator(clazz, new HibernateRulesMessageInterpolator());
		propertyResults = new HashMap<String, DefaultValidationResults>();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ValidationResults validate(Object object, String propertyName) {
		if (propertyName != null) {
			DefaultValidationResults result = propertyResults.get(propertyName);
			if (result == null) {
				result = new DefaultValidationResults();
				propertyResults.put(propertyName, result);
			}
			else {
				result.clearMessages();
			}
			result.addAllMessages(super.validate(object, propertyName));
		}
		final InvalidValue[] validationMessages = doHibernateValidate(object, propertyName);
		if (validationMessages != null) {
			for (final InvalidValue validationMessage : validationMessages) {
				ValidationMessage message = new DefaultValidationMessage(validationMessage.getPropertyName(),
						Severity.ERROR, resolveObjectName(validationMessage.getPropertyName()) + " "
								+ validationMessage.getMessage());
				propertyResults.get(validationMessage.getPropertyName()).addMessage(message);
			}
		}
		return combineResults(propertyResults);
	}
<commit_msg>Fixed constructor calling.<commit_after>package org.springframework.binding.validation.support;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;
import org.springframework.binding.form.ValidatingFormModel;
import org.springframework.binding.validation.ValidationMessage;
import org.springframework.binding.validation.ValidationResults;
import org.springframework.richclient.core.Severity;
import org.springframework.richclient.util.Assert;
import org.springframework.rules.RulesSource;

/**
 * Validator that combines Hibernate validation with rules defined by a
 * RulesSource. First the rules will be checked, then validation will occurs
 * through a ClassValidator.<br/>
 *
 * Usage in a {@link ValidatingFormModel}: <br>
 *
 * {@example formModel.setValidator( new HibernateRulesValidator(formModel, rulesSource, SomeClass.class)); }
 *
 * @author <NAME>
 * @author <NAME>
 *
 */
@SuppressWarnings("unchecked")
public class HibernateRulesValidator extends RulesValidator {

	private final ClassValidator hibernateValidator;

	private ValidatingFormModel formModel;

	private DefaultValidationResults results = new DefaultValidationResults();

	private Map<String, DefaultValidationResults> propertyResults;

	private Set<String> ignoredHibernateProperties;

	/**
	 * Creates a new HibernateRulesValidator
	 *
	 * @param formModel The {@link ValidatingFormModel} on which validation
	 * needs to occur
	 * @param rulesSource The {@link RulesSource} that contains the rules. If
	 * <code>null</code>, no rules will be enfored.
	 * @param clazz The class of the object this validator needs to check
	 */
	public HibernateRulesValidator(ValidatingFormModel formModel, RulesSource rulesSource, Class clazz) {
		super(formModel, rulesSource);
		this.formModel = formModel;
		hibernateValidator = new ClassValidator(clazz, new HibernateRulesMessageInterpolator());
		propertyResults = new HashMap<String, DefaultValidationResults>();
		ignoredHibernateProperties = new HashSet<String>();
	}

	/**
	 * Creates a new HibernateRulesValidator without specific Rules
	 *
	 * @param formModel The {@link ValidatingFormModel} on which validation
	 * needs to occur
	 * @param rulesSource The {@link RulesSource} that contains the rules. If
	 * <code>null</code>, no rules will be enfored.
	 * @param clazz The class of the object this validator needs to check
	 */
	public HibernateRulesValidator(ValidatingFormModel formModel, Class clazz) {
	    this(formModel, null, clazz);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ValidationResults validate(Object object, String propertyName) {
		if (propertyName != null) {
			DefaultValidationResults result = propertyResults.get(propertyName);
			if (result == null) {
				result = new DefaultValidationResults();
				propertyResults.put(propertyName, result);
			}
			else {
				result.clearMessages();
			}
			result.addAllMessages(super.validate(object, propertyName));
		}
		final InvalidValue[] validationMessages = doHibernateValidate(object, propertyName);
		if (validationMessages != null) {
			for (final InvalidValue validationMessage : validationMessages) {
				ValidationMessage message = new DefaultValidationMessage(validationMessage.getPropertyName(),
						Severity.ERROR, resolveObjectName(validationMessage.getPropertyName()) + " "
								+ validationMessage.getMessage());
				propertyResults.get(validationMessage.getPropertyName()).addMessage(message);
			}
		}
		return combineResults(propertyResults);
	}

{'fraction_non_alphanumeric': 0.09186317698885722, 'fraction_numerical': 0.0, 'mean_word_length': 5.524936601859679, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7065495', 'n_tokens_mistral': 2161, 'n_tokens_neox': 1968, 'n_words': 552}