/** * Validate a single property only. Performs all validations * for this property. */ public static <VL extends ValidationListener> void validateProperty(ValidationContext<VL> context) { for (Validation validation : context.getMetaProperty().getValidations()) { validation.validate(context); } } }
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); }
/** * Return the property level constraints for a given propertyName or {@code null} if * either the property does not exist or has no constraint. The returned * object (and associated objects including ConstraintDescriptors) are * immutable. * * @param propertyName * property evaluated */ public PropertyDescriptor getConstraintsForProperty(String propertyName) { if (propertyName == null || propertyName.trim().length() == 0) { throw new IllegalArgumentException("propertyName cannot be null or empty"); } MetaProperty prop = metaBean.getProperty(propertyName); if (prop == null) return null; // If no constraints and not cascaded, return null if (prop.getValidations().length == 0 && prop.getFeature(Features.Property.REF_CASCADE) == null) { return null; } return getPropertyDescriptor(prop); }
/** * Create a new PropertyDescriptorImpl instance. * * @param property */ PropertyDescriptorImpl(MetaProperty property) { super(property.getParentMetaBean(), property.getTypeClass(), property.getValidations()); setCascaded(property.getMetaBean() != null || property.getFeature(Features.Property.REF_CASCADE) != null); setPropertyPath(property.getName()); }