com.github.ldeitos.exception.ViolationException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of extendedValidation-core Show documentation
Show all versions of extendedValidation-core Show documentation
Extension for BeanValidation API Core. Content interfaces, qualifiers and constraints definitions.
This version is Java 17 and JakartaEE 10 compatible.
The newest version!
package com.github.ldeitos.exception;
import java.util.HashSet;
import java.util.Set;
import com.github.ldeitos.validation.Message;
import com.github.ldeitos.validation.Validator;
/**
* Exception to throw when a object under validation has violations.
*
* @author Leandro Deitos
*
* @see Validator#validateAndThrow(Object, Class...)
*
* @since 0.9.2
*/
public class ViolationException extends RuntimeException {
private static final long serialVersionUID = 1L;
private Set messages = new HashSet();
public ViolationException(String msg) {
super(msg);
}
public ViolationException(String msg, Set messages) {
this(msg);
this.messages.addAll(messages);
}
public ViolationException(String msg, Throwable t) {
super(msg, t);
}
public ViolationException(String msg, Throwable t, Set messages) {
this(msg, t);
this.messages.addAll(messages);
}
public static void throwNew(String msg) throws ViolationException {
throw new ViolationException(msg);
}
public static void throwNew(String msg, Set messages) throws ViolationException {
throw new ViolationException(msg, messages);
}
public static void throwNew(String msg, Throwable t) throws ViolationException {
throw new ViolationException(msg, t);
}
public static void throwNew(String msg, Throwable t, Set messages) throws ViolationException {
throw new ViolationException(msg, t, messages);
}
/**
* @return Violation messages.
*/
public Set getMessages() {
return messages;
}
}