/** * factory method - overwrite in subclasses * * @return ValidationContext parameterized with our listener type */ protected ValidationContext<T> createContext() { return new BeanValidationContext<T>(createResults()); }
/** * Convenience API. validate a root object with all related objects with its * default metaBean definition. * * @param bean * @return results - validation results found */ public T validate(Object bean) { MetaBean metaBean = getMetaBeanFinder().findForClass(bean.getClass()); return validate(bean, metaBean); }
if (anno instanceof Validate) { if (context == null) { context = createContext(); if (determineMetaBean((Validate) anno, parameters[i], context)) { ValidationHelper.validateContext(context, new BeanValidatorCallback(context), treatMapsLikeBeans);
/** * Convenience API. validate a root object with all related objects * according to the metaBean. * * @param bean * - a single bean or a collection of beans (that share the same * metaBean!) * @param metaBean * @return results - validation results found */ public T validate(Object bean, MetaBean metaBean) { ValidationContext<T> context = createContext(); context.setBean(bean, metaBean); ValidationHelper.validateContext(context, new BeanValidatorCallback(context), treatMapsLikeBeans); return context.getListener(); }
beanClass = parameter.getClass(); context.setBean(parameter, getMetaBeanFinder().findForClass(beanClass)); } else { context.setBean(parameter, getMetaBeanFinder().findForId(validate.value()));
/** * {@inheritDoc} internal validate a bean (=not a collection of beans) and * its related beans */ protected <VL extends ValidationListener> void validateBeanNet(ValidationContext<VL> context) { if (context.collectValidated()) { ValidationHelper.validateBean(context); for (MetaProperty prop : context.getMetaBean().getProperties()) { validateRelatedBean(context, prop); } } }
/** * Convenience API. validate a single property. * * @param bean * - the root object * @param metaProperty * - metadata for the property * @return validation results */ public T validateProperty(Object bean, MetaProperty metaProperty) { ValidationContext<T> context = createContext(); context.setBean(bean); context.setMetaProperty(metaProperty); ValidationHelper.validateProperty(context); return context.getListener(); }