/** * factory method - overwrite in subclasses * * @return ValidationContext parameterized with our listener type */ protected ValidationContext<T> createContext() { return new BeanValidationContext<T>(createResults()); }
/** * Create a new MetaBeanManager instance. */ public MetaBeanManager() { builder = new MetaBeanBuilder(); }
/** * {@inheritDoc} */ @Override public void setBean(Object aBean, MetaBean aMetaBean) { bean = aBean; metaBean = aMetaBean; metaProperty = null; unknownValue(); }
/** * Compute a single related {@link MetaBean}. * * @param prop meta property * @param beanRef bean reference */ protected void computeRelatedMetaBean(MetaProperty prop, String beanRef) { Class<?> beanType = prop.getFeature(REF_BEAN_TYPE); if (beanType == null) { if (prop.getFeature(REF_CASCADE) != null) { // dynamic type resolution: prop.setMetaBean(new DynamicMetaBean(this)); } } else { prop.setMetaBean(findForClass(beanType)); } }
/** * API to add an error to the validation results. * * @param reason - Features from {@link org.apache.bval.model.Features.Property} * or custom reason of validation error * @param context - context information (bean, propertyName, value, ...) */ @Override public <T extends ValidationListener> void addError(String reason, ValidationContext<T> context) { Error error = createError(reason, context.getBean(), context.getPropertyName()); addError(error, context); }
/** * 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); }
/** * {@inheritDoc} */ @Override public void moveDown(MetaProperty prop, AccessStrategy access) { setBean(getPropertyValue(access), prop.getMetaBean()); }
/** * Create a new MetaBeanBuilder instance. */ public MetaBeanBuilder() { this(new MetaBeanFactory[] { new IntrospectorMetaBeanFactory() }); }
/** * API to add an error to the validation results. * * @param error - holding the description of reason and object to describe * the validation error * @param context - null or the context to provide additional information */ @Override public <T extends ValidationListener> void addError(Error error, ValidationContext<T> context) { if (errorsByReason == null) { initialize(); } addToReasonBucket(error); addToOwnerBucket(error); }
/** * Old API to add an error to the validation results when no context is available. * * @param reason - Features from {@link org.apache.bval.model.Features.Property} or custom validation reason * @param bean - (optional) owner bean or null * @param propertyName - (optional) propertyName where valiation error occurred or null */ public void addError(String reason, Object bean, String propertyName) { addError(createError(reason, bean, propertyName), null); }
/** * Create a new MetaBeanBuilder instance. * * @param factories */ public MetaBeanBuilder(MetaBeanFactory[] factories) { setFactories(factories); }
/** * Set the property value, fixed. * @param value */ public void setFixedValue(Object value) { setPropertyValue(value); setFixed(true); }
/** * {@inheritDoc} * different strategies with hints to find MetaBean of associated object can * be implemented here. */ @Override public MetaBean resolveMetaBean(Object bean) { return bean instanceof Class<?> ? finder.findForClass((Class<?>) bean) : finder.findForClass(bean.getClass()); } }
/** * factory method - overwrite in subclasses * * @return ValidationListener of the proper type */ @SuppressWarnings("unchecked") protected T createResults() { return (T) new ValidationResults(); }
/** * {@inheritDoc} */ @Override public void moveUp(Object bean, MetaBean aMetaBean) { setBean(bean, aMetaBean); // reset context state }
/** * Create a new BeanValidator instance. Convenience constructor. Use the * global instance of MetaBeanManagerFactory.getFinder(). */ public BeanValidator() { this(MetaBeanManagerFactory.getFinder()); }
/** * Create a {@link MetaProperty} from the specified {@link PropertyDescriptor}. * * @param pd * @return MetaProperty */ @Deprecated protected MetaProperty buildMetaProperty(PropertyDescriptor pd) { return buildMetaProperty(pd, null); }
/** * {@inheritDoc} */ @Override public void setMetaProperty(MetaProperty metaProperty) { this.metaProperty = metaProperty; unknownValue(); }
/** * {@inheritDoc} */ @Override public void setBean(Object bean) { this.bean = bean; unknownValue(); }