final void validate(Object object) throws RaveException { Class<?> clazz = object.getClass(); if (supportedClasses.contains(clazz)) { // This will call the object specific generated validate method. validateAs(object, clazz); } else { throw new IllegalArgumentException( clazz.getCanonicalName() + ":" + RaveErrorStrings.CLASS_NOT_SUPPORTED_ERROR); } }
/** * Since various objects may have subclass/interfaces that also require validation this mechanism allows for * targeted validation of different inherited subtypes on the same object. * * @param obj the object to validate * @param clazz the class type to validate it as. * validation. * @throws RaveException thrown if the validation process fails. */ void validateAs(Object obj, Class<?> clazz) throws RaveException { if (!clazz.isInstance(obj)) { throw new IllegalArgumentException("Trying to validate " + obj.getClass().getCanonicalName() + " as " + clazz.getCanonicalName()); } BaseValidator base; synchronized (this) { base = classValidatorMap.get(clazz); if (base == null) { base = getValidatorInstance(clazz); } if (base == null) { throw new UnsupportedObjectException(Collections.singletonList( new RaveError(obj.getClass(), "", RaveErrorStrings.CLASS_NOT_SUPPORTED_ERROR))); } } base.validateAs(obj, clazz); }