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

com.github.jmkgreen.morphia.validation.VerboseJSR303ConstraintViolationException Maven / Gradle / Ivy

The newest version!
/**
 *
 */
package com.github.jmkgreen.morphia.validation;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;

import com.github.jmkgreen.morphia.utils.Assert;

/**
 * @author [email protected]
 */
public class VerboseJSR303ConstraintViolationException
        extends ConstraintViolationException {
    /**
     *
     * @param vio
     */
    public VerboseJSR303ConstraintViolationException(
            final Set> vio) {
        super(createVerboseMessage(vio), vio);
        Assert.parameterNotNull(vio, "vio");
    }

    /**
     *
     * @param vio
     * @return
     */
    private static String createVerboseMessage(
            final Set> vio) {
        final StringBuffer sb = new StringBuffer(128);
        sb.append("The following constraints have been violated:\n");
        for (final ConstraintViolation c : vio) {
            sb.append(c.getRootBeanClass().getSimpleName());
            sb.append(".");
            sb.append(c.getPropertyPath());
            sb.append(": ");
            sb.append(c.getMessage());
            sb.append(" ('");
            sb.append(c.getInvalidValue());
            sb.append("')\n");
        }
        return sb.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy