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

jodd.vtor.constraint.AssertValidConstraint Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.vtor.constraint;

import jodd.vtor.ValidationConstraint;
import jodd.vtor.ValidationConstraintContext;
import jodd.vtor.ValidationContext;

/**
 * Special annotation that validates inner context of provided value. 
 */
public class AssertValidConstraint implements ValidationConstraint {

	protected final ValidationContext targetValidationContext;

	public AssertValidConstraint(ValidationContext targetValidationContext) {
		this.targetValidationContext = targetValidationContext;
	}

	// ---------------------------------------------------------------- config

	public void configure(AssertValid annotation) {
	}

	// ---------------------------------------------------------------- valid

	/**
	 * Invokes validation on inner context. Always returns true since
	 * inner context violations will be appended to provided validator.
	 */
	public boolean isValid(ValidationConstraintContext vcc, Object value) {
		if (value == null) {
			return true;
		}
		vcc.validateWithin(targetValidationContext, value);
		return true;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy