protected void computeRelationships(MetaBean beanInfo, Map<String, MetaBean> cached) { for (MetaProperty prop : beanInfo.getProperties()) { String beanRef = (String) prop.getFeature(REF_BEAN_ID); if (beanRef != null) { prop.setMetaBean(cached.get(beanRef)); } } }
/** * Compute all known relationships for <code>beanInfo</code>. must be called * AFTER cache.cache() to avoid endless loop * * @param beanInfo * - the bean for which to compute relationships */ protected void computeRelationships(MetaBean beanInfo) { for (final MetaProperty prop : beanInfo.getProperties()) { final String beanRef = prop.getFeature(REF_BEAN_ID); computeRelatedMetaBean(prop, beanRef); } }
private boolean hasAnyConstraints() { if (hasConstraints()) return true; for (MetaProperty mprop : metaBean.getProperties()) { if (getConstraintDescriptors(mprop.getValidations()).size() > 0) return true; } return false; }
/** * {@inheritDoc} * * @return the property descriptors having at least a constraint defined */ public Set<PropertyDescriptor> getConstrainedProperties() { Set<PropertyDescriptor> validatedProperties = new HashSet<PropertyDescriptor>(); for (MetaProperty prop : metaBean.getProperties()) { if (prop.getValidations().length > 0 || (prop.getMetaBean() != null || prop.getFeature(Features.Property.REF_CASCADE) != null)) { validatedProperties.add(getPropertyDescriptor(prop)); } } return Collections.unmodifiableSet(validatedProperties); }
/** * Returns true if the bean involves validation: * <ul> * <li>a constraint is hosted on the bean itself</li> * <li>a constraint is hosted on one of the bean properties, OR</li> * <li>a bean property is marked for cascade (<code>@Valid</code>)</li> * </ul> * * @return true if the bean involves validation */ public boolean isBeanConstrained() { if (hasAnyConstraints()) return true; for (MetaProperty mprop : metaBean.getProperties()) { if (mprop.getMetaBean() != null || mprop.getFeature(Features.Property.REF_CASCADE) != null) return true; } return false; }
/** * {@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); } } }
/** * 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); } }
for (MetaProperty prop : context.getMetaBean().getProperties()) { validateCascadedBean(context, prop);