org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor Maven / Gradle / Ivy
/*
* 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.util.annotation;
import java.lang.annotation.Annotation;
import java.util.Map;
import jakarta.validation.ConstraintTarget;
import jakarta.validation.Payload;
import org.hibernate.validator.internal.metadata.core.ConstraintHelper;
/**
* @author Marko Bekhta
*/
public class ConstraintAnnotationDescriptor extends AnnotationDescriptor {
public ConstraintAnnotationDescriptor(A annotation) {
super( annotation );
}
public ConstraintAnnotationDescriptor(AnnotationDescriptor descriptor) {
super( descriptor );
}
public String getMessage() {
return getMandatoryAttribute( ConstraintHelper.MESSAGE, String.class );
}
public Class[] getGroups() {
return getMandatoryAttribute( ConstraintHelper.GROUPS, Class[].class );
}
@SuppressWarnings("unchecked")
public Class[] getPayload() {
return getMandatoryAttribute( ConstraintHelper.PAYLOAD, Class[].class );
}
public ConstraintTarget getValidationAppliesTo() {
return getAttribute( ConstraintHelper.VALIDATION_APPLIES_TO, ConstraintTarget.class );
}
public static class Builder extends AnnotationDescriptor.Builder {
public Builder(Class type) {
super( type );
}
public Builder(Class type, Map attributes) {
super( type, attributes );
}
public Builder(S annotation) {
super( annotation );
}
public Builder setMessage(String message) {
setAttribute( ConstraintHelper.MESSAGE, message );
return this;
}
public Builder setGroups(Class[] groups) {
setAttribute( ConstraintHelper.GROUPS, groups );
return this;
}
public Builder setPayload(Class[] payload) {
setAttribute( ConstraintHelper.PAYLOAD, payload );
return this;
}
public Builder setValidationAppliesTo(ConstraintTarget validationAppliesTo) {
setAttribute( ConstraintHelper.VALIDATION_APPLIES_TO, validationAppliesTo );
return this;
}
@Override
public ConstraintAnnotationDescriptor build() {
return new ConstraintAnnotationDescriptor<>( super.build() );
}
}
}