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(javax.validation.ConstraintValidatorContext constraintValidatorContext)
ViolationCollector(javax.validation.ConstraintValidatorContext constraintValidatorContext, boolean escapeExpressions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addViolation(String message)
Adds a new violation to this collector.void
addViolation(String propertyName, Integer index, String message)
Adds a new violation to this collector.void
addViolation(String propertyName, Integer index, String message, Map<String,Object> messageParameters)
Adds a new violation to this collector.void
addViolation(String propertyName, String message)
Adds a new violation to this collector.void
addViolation(String propertyName, String key, String message)
Adds a new violation to this collector.void
addViolation(String propertyName, String key, String message, Map<String,Object> messageParameters)
Adds a new violation to this collector.void
addViolation(String propertyName, String message, Map<String,Object> messageParameters)
Adds a new violation to this collector.void
addViolation(String message, Map<String,Object> messageParameters)
Adds a new violation to this collector.javax.validation.ConstraintValidatorContext
getContext()
This method returns the wrapped context for raw access to the validation framework.boolean
hasViolationOccurred()
void
setViolationOccurred(boolean violationOccurred)
Manually sets if a violation occurred.
-
-
-
Method Detail
-
addViolation
public void addViolation(String message)
Adds a new violation to this collector. This also setsviolationOccurred
totrue
.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 setsviolationOccurred
totrue
.- 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 setsviolationOccurred
totrue
.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:
- 1.3.19
- 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 setsviolationOccurred
totrue
.- 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:
- 1.3.21
-
addViolation
public void addViolation(String propertyName, Integer index, String message)
Adds a new violation to this collector. This also setsviolationOccurred
totrue
. 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:
- 1.3.19
- 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 setsviolationOccurred
totrue
.- 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:
- 1.3.21
-
addViolation
public void addViolation(String propertyName, String key, String message)
Adds a new violation to this collector. This also setsviolationOccurred
totrue
.- Parameters:
propertyName
- the name of the property with the violationkey
- the key of the element with the violationmessage
- the message of the violation- Since:
- 1.3.19
-
addViolation
public void addViolation(String propertyName, String key, String message, Map<String,Object> messageParameters)
Adds a new violation to this collector. This also setsviolationOccurred
totrue
.- 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:
- 1.3.21
-
getContext
public javax.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 any violation was collected
-
setViolationOccurred
public void setViolationOccurred(boolean violationOccurred)
Manually sets if a violation occurred. This is automatically set ifaddViolation
is called.- Parameters:
violationOccurred
- if any violation was collected
-
-