Class ViolationCollector
- java.lang.Object
-
- io.dropwizard.validation.selfvalidating.ViolationCollector
-
public class ViolationCollector extends Object
This class is a simple wrapper around the ConstraintValidatorContext of hibernate validation. It collects all the violations of the SelfValidation methods of an object.
-
-
Constructor Summary
Constructors Constructor Description ViolationCollector(jakarta.validation.ConstraintValidatorContext constraintValidatorContext)Constructs a newViolationCollectorwith the givenConstraintValidatorContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddViolation(String message)Adds a new violation to this collector.voidaddViolation(String propertyName, Integer index, String message)Adds a new violation to this collector.voidaddViolation(String propertyName, Integer index, String message, Map<String,Object> messageParameters)Adds a new violation to this collector.voidaddViolation(String propertyName, String message)Adds a new violation to this collector.voidaddViolation(String propertyName, String key, String message)Adds a new violation to this collector.voidaddViolation(String propertyName, String key, String message, Map<String,Object> messageParameters)Adds a new violation to this collector.voidaddViolation(String propertyName, String message, Map<String,Object> messageParameters)Adds a new violation to this collector.voidaddViolation(String message, Map<String,Object> messageParameters)Adds a new violation to this collector.jakarta.validation.ConstraintValidatorContextgetContext()This method returns the wrapped context for raw access to the validation framework.booleanhasViolationOccurred()Returns, if a violation has previously occurred.voidsetViolationOccurred(boolean violationOccurred)Manually sets if a violation occurred.
-
-
-
Constructor Detail
-
ViolationCollector
public ViolationCollector(jakarta.validation.ConstraintValidatorContext constraintValidatorContext)
Constructs a newViolationCollectorwith the givenConstraintValidatorContext.- Parameters:
constraintValidatorContext- the wrappedConstraintValidatorContext
-
-
Method Detail
-
addViolation
public void addViolation(String message)
Adds a new violation to this collector. This also setsviolationOccurredtotrue.
Prefer the method with explicit message parameters if you want to interpolate the message.- Parameters:
message- the message of the violation- See Also:
addViolation(String, Map)
-
addViolation
public void addViolation(String message, Map<String,Object> messageParameters)
Adds a new violation to this collector. This also setsviolationOccurredtotrue.- Parameters:
message- the message of the violationmessageParameters- a map of message parameters which can be interpolated in the violation message- Since:
- 2.0.3
-
addViolation
public void addViolation(String propertyName, String message)
Adds a new violation to this collector. This also setsviolationOccurredtotrue.
Prefer the method with explicit message parameters if you want to interpolate the message.- Parameters:
propertyName- the name of the propertymessage- the message of the violation- Since:
- 2.0.2
- See Also:
addViolation(String, String, Map)
-
addViolation
public void addViolation(String propertyName, String message, Map<String,Object> messageParameters)
Adds a new violation to this collector. This also setsviolationOccurredtotrue.- Parameters:
propertyName- the name of the propertymessage- the message of the violationmessageParameters- a map of message parameters which can be interpolated in the violation message- Since:
- 2.0.3
-
addViolation
public void addViolation(String propertyName, Integer index, String message)
Adds a new violation to this collector. This also setsviolationOccurredtotrue. Prefer the method with explicit message parameters if you want to interpolate the message.- Parameters:
propertyName- the name of the property with the violationindex- the index of the element with the violationmessage- the message of the violation (any EL expression will be escaped and not parsed)- Since:
- 2.0.2
- See Also:
addViolation(String, Integer, String, Map)
-
addViolation
public void addViolation(String propertyName, Integer index, String message, Map<String,Object> messageParameters)
Adds a new violation to this collector. This also setsviolationOccurredtotrue.- Parameters:
propertyName- the name of the property with the violationindex- the index of the element with the violationmessage- the message of the violationmessageParameters- a map of message parameters which can be interpolated in the violation message- Since:
- 2.0.3
-
addViolation
public void addViolation(String propertyName, String key, String message)
Adds a new violation to this collector. This also setsviolationOccurredtotrue.- Parameters:
propertyName- the name of the property with the violationkey- the key of the element with the violationmessage- the message of the violation- Since:
- 2.0.2
-
addViolation
public void addViolation(String propertyName, String key, String message, Map<String,Object> messageParameters)
Adds a new violation to this collector. This also setsviolationOccurredtotrue.- Parameters:
propertyName- the name of the property with the violationkey- the key of the element with the violationmessage- the message of the violationmessageParameters- a map of message parameters which can be interpolated in the violation message- Since:
- 2.0.3
-
getContext
public jakarta.validation.ConstraintValidatorContext getContext()
This method returns the wrapped context for raw access to the validation framework. If you use the context to add violations make sure to callsetViolationOccurred(true).- Returns:
- the wrapped Hibernate ConstraintValidatorContext
-
hasViolationOccurred
public boolean hasViolationOccurred()
Returns, if a violation has previously occurred.- Returns:
- if any violation was collected
-
setViolationOccurred
public void setViolationOccurred(boolean violationOccurred)
Manually sets if a violation occurred. This is automatically set ifaddViolationis called.- Parameters:
violationOccurred- if any violation was collected
-
-