
/*
 * Copyright (C) 2012 Archie L. Cobbs. All rights reserved.
 *
 * $Id$
 */

package org.dellroad.stuff.pobj;

import java.util.Set;

import javax.validation.ConstraintViolation;

/**
 * Runtime exception thrown during {@link PersistentObject} operations.
 */
@SuppressWarnings("serial")
public class PersistentObjectValidationException extends PersistentObjectException {

    private final Set<ConstraintViolation<?>> violations;

    /**
     * Constructor.
     *
     * @param violations set of violations
     * @throws IllegalArgumentException if {@code violations} is null
     */
    public PersistentObjectValidationException(Set<ConstraintViolation<?>> violations) {
        super("object failed to validate: " + violations);
        if (violations == null)
            throw new IllegalArgumentException("null violations");
        this.violations = violations;
    }

    /**
     * Get the set of constraint violations.
     */
    public Set<ConstraintViolation<?>> getViolations() {
        return this.violations;
    }
}


@@ -678,166 +678,8 @@
 ) %7B%0A
-        super(%22object failed to validate: %22 + violations);%0A        if (violations == null)%0A            throw new IllegalArgumentException(%22null violations%22);%0A
     
@@ -874,12 +874,654 @@
 s;%0A    %7D
+%0A%0A    private static String generateMessage(Set%3CConstraintViolation%3C?%3E%3E violations) %7B%0A        if (violations == null)%0A            throw new IllegalArgumentException(%22null violations%22);%0A        StringBuilder buf = new StringBuilder(%22object failed to validate with %22 + violations.size() + %22 violation(s): %22);%0A        boolean first = true;%0A        for (ConstraintViolation%3C?%3E violation : violations) %7B%0A            if (first)%0A                first = false;%0A            else%0A                buf.append(%22; %22);%0A            buf.append(%22%5B%22 + violation.getPropertyPath() + %22%5D: %22 + violation.getMessage());%0A        %7D%0A        return buf.toString();%0A    %7D
 %0A%7D%0A%0A

Improve exception message from previous commit.