/** * Validate a single bean only, no related beans will be validated. */ public static <VL extends ValidationListener> void validateBean(ValidationContext<VL> context) { // execute all property level validations for (MetaProperty prop : context.getMetaBean().getProperties()) { context.setMetaProperty(prop); validateProperty(context); } // execute all bean level validations context.setMetaProperty(null); for (Validation validation : context.getMetaBean().getValidations()) { validation.validate(context); } }
/** * 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(); }
/** * {@inheritDoc} */ public void handleProperty(String token) { moveDownIfNecessary(); MetaBean metaBean = validationContext.getMetaBean(); if (metaBean instanceof DynamicMetaBean) { metaBean = metaBean.resolveMetaBean(ObjectUtils.defaultIfNull(validationContext.getBean(), rawType)); validationContext.setMetaBean(metaBean); } MetaProperty mp = metaBean.getProperty(token); if (mp == null) { // TODO this could indicate a property hosted on a superclass; should we shunt the context traversal down a path based on that type? PropertyAccess access = new PropertyAccess(rawType, token); if (access.isKnown()) { // add heretofore unknown, but valid, property on the fly: mp = Jsr303MetaBeanFactory.addMetaProperty(metaBean, access); } else { throw new UnknownPropertyException("unknown property '" + token + "' in " + metaBean.getId()); } } validationContext.setMetaProperty(mp); setType(mp.getType()); }