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

org.hibernate.validator.internal.engine.constraintvalidation.ConstraintViolationCreationContext Maven / Gradle / Ivy

There is a newer version: 8.0.1.Final
Show newest version
/*
 * Hibernate Validator, declare and validate application constraints
 *
 * License: Apache License, Version 2.0
 * See the license.txt file in the root directory or .
 */
package org.hibernate.validator.internal.engine.constraintvalidation;

import static org.hibernate.validator.internal.util.CollectionHelper.toImmutableMap;

import java.util.Collections;
import java.util.Map;

import org.hibernate.validator.internal.engine.path.PathImpl;
import org.hibernate.validator.internal.util.stereotypes.Immutable;

/**
 * Container class for the information needed to create a constraint violation.
 *
 * @author Hardy Ferentschik
 */
public class ConstraintViolationCreationContext {
	private final String message;
	private final PathImpl propertyPath;
	@Immutable
	private final Map messageParameters;
	@Immutable
	private final Map expressionVariables;
	private final Object dynamicPayload;

	public ConstraintViolationCreationContext(String message, PathImpl property) {
		this( message, property, Collections.emptyMap(), Collections.emptyMap(), null );
	}

	public ConstraintViolationCreationContext(String message, PathImpl property, Map messageParameters, Map expressionVariables,
			Object dynamicPayload) {
		this.message = message;
		this.propertyPath = property;
		this.messageParameters = toImmutableMap( messageParameters );
		this.expressionVariables = toImmutableMap( expressionVariables );
		this.dynamicPayload = dynamicPayload;
	}

	public final String getMessage() {
		return message;
	}

	public final PathImpl getPath() {
		return propertyPath;
	}

	public Map getMessageParameters() {
		return messageParameters;
	}

	public Map getExpressionVariables() {
		return expressionVariables;
	}

	public Object getDynamicPayload() {
		return dynamicPayload;
	}

	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder( "ConstraintViolationCreationContext{" );
		sb.append( "message='" ).append( message ).append( '\'' );
		sb.append( ", propertyPath=" ).append( propertyPath );
		sb.append( ", messageParameters=" ).append( messageParameters );
		sb.append( ", expressionVariables=" ).append( expressionVariables );
		sb.append( ", dynamicPayload=" ).append( dynamicPayload );
		sb.append( '}' );
		return sb.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy