Created
May 26, 2017 17:04
-
-
Save naturalwarren/97c108eb3b99e84ebfe96cd60b968746 to your computer and use it in GitHub Desktop.
RAVE's generated validator code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class RaveValidatorFactory_Generated_Validator extends BaseValidator { | |
RaveValidatorFactory_Generated_Validator() { | |
addSupportedClass(MyModel.class); | |
registerSelf(); | |
} | |
@Override | |
protected void validateAs(@NonNull Object object, @NonNull Class<?> clazz, @NonNull ExclusionStrategy exclusionStrategy) throws InvalidModelException { | |
if (!clazz.isInstance(object)) { | |
throw new IllegalArgumentException(object.getClass().getCanonicalName() + "is not of type" + clazz.getCanonicalName()); | |
} | |
if (clazz.equals(MyModel.class)) { | |
validateAs((MyModel) object, exclusionStrategy); | |
return; | |
} | |
throw new IllegalArgumentException(object.getClass().getCanonicalName() + " is not supported by validator " + this.getClass().getCanonicalName()); | |
} | |
private void validateAs(MyModel object, ExclusionStrategy exclusionStrategy) throws InvalidModelException { | |
BaseValidator.ValidationContext context = getValidationContext(MyModel.class); | |
List<RaveError> raveErrors = null; | |
if (!setContextAndCheckshouldIgnoreMethod(MyModel.class, "getSomeString", exclusionStrategy, context)) { | |
raveErrors = mergeErrors(raveErrors, checkNullable(object.getSomeString(), false, context)); | |
} | |
if (!setContextAndCheckshouldIgnoreMethod(MyModel.class, "customValidationLogic", exclusionStrategy, context)) { | |
raveErrors = mergeErrors(raveErrors, mustBeTrue(object.customValidationLogic(), context)); | |
} | |
if (raveErrors != null && !raveErrors.isEmpty()) { | |
throw new InvalidModelException(raveErrors); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment