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

package org.dellroad.stuff.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Implemented by classes that can validate themselves.
 *
 * @see SelfValidates
 */
public class SelfValidatingValidator implements ConstraintValidator<SelfValidates, SelfValidating> {

    @Override
    public void initialize(SelfValidates annotation) {
    }

    @Override
    public boolean isValid(SelfValidating value, ConstraintValidatorContext context) {
        try {
            value.checkValid(context);
            return true;
        } catch (SelfValidationException e) {
            String message = e.getMessage();
            if (message != null) {
                context.disableDefaultConstraintViolation();
                context.buildConstraintViolationWithTemplate(message).addConstraintViolation();
            }
            return false;
        }
    }
}


@@ -231,50 +231,72 @@
 ment
-ed by classes that can validate themselves
+s the validation logic for the @%7B@link SelfValidates%7D annotation
 .%0A *

Correct javadoc description.