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

org.hibernate.validator.cfg.ConstraintDef 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.cfg;

import java.lang.annotation.Annotation;

import javax.validation.Payload;

import org.hibernate.validator.internal.metadata.core.ConstraintHelper;

/**
 * Base class for all constraint definition types. Each sub type represents a
 * single constraint annotation type and allows to add this constraint to a bean
 * class in a programmatic type-safe way with help of the
 * {@link ConstraintMapping} API.
 *
 * @param  The type of a concrete sub type. Following to the
 * "self referencing generic type" pattern each sub type has to be
 * parametrized with itself.
 * @param  The constraint annotation type represented by a concrete sub type.
 *
 * @author Hardy Ferentschik
 * @author Gunnar Morling
 */
public abstract class ConstraintDef, A extends Annotation> extends AnnotationDef {

	protected ConstraintDef(Class constraintType) {
		super( constraintType );
	}

	protected ConstraintDef(ConstraintDef original) {
		super( original );
	}

	@SuppressWarnings("unchecked")
	private C getThis() {
		return (C) this;
	}

	public C message(String message) {
		addParameter( ConstraintHelper.MESSAGE, message );
		return getThis();
	}

	public C groups(Class... groups) {
		addParameter( ConstraintHelper.GROUPS, groups );
		return getThis();
	}

	@SuppressWarnings("unchecked")
	public C payload(Class... payload) {
		addParameter( ConstraintHelper.PAYLOAD, payload );
		return getThis();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy