/** * 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(); }
/** * 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 handleIndexOrKey(String token) { moveDownIfNecessary(); AccessStrategy access; if (IndexedAccess.getJavaElementType(type) != null) { try { Integer index = token == null ? null : Integer.valueOf(token); access = new IndexedAccess(type, index); validationContext.setCurrentIndex(index); } catch (NumberFormatException e) { throw new UnknownPropertyException(String.format("Cannot parse %s as an array/iterable index", token), e); } } else if (KeyedAccess.getJavaElementType(type) != null) { access = new KeyedAccess(type, token); validationContext.setCurrentKey(token); } else { throw new UnknownPropertyException(String.format("Cannot determine index/key type for %s", type)); } Object value = validationContext.getBean(); Object child = value == null ? null : access.get(value); setType(child == null ? access.getJavaType() : child.getClass()); validationContext.setBean(child, validationContext.getMetaBean().resolveMetaBean(child == null ? rawType : child)); }