play.data.validation.ValidCheck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of framework Show documentation
Show all versions of framework Show documentation
RePlay is a fork of the Play1 framework, created by Codeborne.
package play.data.validation;
import net.sf.oval.ConstraintViolation;
import net.sf.oval.Validator;
import net.sf.oval.configuration.annotation.AbstractAnnotationCheck;
import net.sf.oval.context.FieldContext;
import net.sf.oval.context.MethodParameterContext;
import net.sf.oval.context.OValContext;
import play.exceptions.UnexpectedException;
import play.utils.Java;
import java.util.Collection;
import java.util.List;
import static java.util.Collections.emptyList;
import static play.data.validation.Error.toValidationError;
public class ValidCheck extends AbstractAnnotationCheck {
static final String mes = "validation.object";
String key;
@Override
public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator) {
String superKey = ValidationPlugin.keys.get().get(validatedObject);
if (value == null) {
return true;
}
try {
if (context != null) {
if (context instanceof MethodParameterContext) {
MethodParameterContext ctx = (MethodParameterContext) context;
String[] paramNames = Java.parameterNames(ctx.getMethod());
key = paramNames[ctx.getParameterIndex()];
}
if (context instanceof FieldContext) {
FieldContext ctx = (FieldContext) context;
key = ctx.getField().getName();
}
}
} catch (Exception e) {
throw new UnexpectedException(e);
}
if (superKey != null) {
key = superKey + "." + key;
}
if(value instanceof Collection) {
Collection