@Override public PropertyDescriptor getConstraintsForProperty(String name) { if(name == null) { throw new IllegalArgumentException("Property name cannot be null."); } if(!this.backingReflector.getPropertyNames().contains(name)) { return null; } PropertyDescriptor descriptor = DescriptorFactory.INSTANCE.getPropertyDescriptor(this.backingReflector, name); if(!descriptor.hasConstraints() && !descriptor.isCascaded()) { return null; } return descriptor; }
@Override public Set<PropertyDescriptor> getConstrainedProperties() { Set<PropertyDescriptor> propertyDescriptors = new HashSet<PropertyDescriptor>(); //this was added as part of the work-around for the problems found in issue #32. this just gets us passed //one set of exceptions and not passed the entire problem. there was a null pointer exception being thrown //by one of the generated classes at this point because it's backing reflector hadn't been generated. if(this.backingReflector == null || this.backingReflector.getPropertyNames() == null) { return propertyDescriptors; } for(String propertyName : this.backingReflector.getPropertyNames()) { PropertyDescriptor descriptor = DescriptorFactory.INSTANCE.getPropertyDescriptor(this.backingReflector, propertyName); if(descriptor.hasConstraints() || descriptor.isCascaded()) { propertyDescriptors.add(descriptor); } } return propertyDescriptors; }
/** * Build a complete map of object property / list of {@link org.resthub.web.validation.ValidationConstraint} * from a given {@link javax.validation.metadata.BeanDescriptor} <tt>bd</tt> instance and a given {@link java.util.Locale} * <tt>locale</tt> */ private Map<String, List<ValidationConstraint>> getConstraints(BeanDescriptor bd, Locale locale) { Map<String, List<ValidationConstraint>> constraints = new HashMap<String, List<ValidationConstraint>>(); for (PropertyDescriptor pd : bd.getConstrainedProperties()) { // if property has defined constraints directly or delegates validation through cascading option if ((pd.getPropertyName() != null) && (pd.hasConstraints() || pd.isCascaded())) { constraints.put(pd.getPropertyName(), this.getValidationConstraints(pd, locale)); } } return constraints; }
if(groupProperty != null && groupProperty.hasConstraints()) { constraints.addAll(groupProperty.getConstraintDescriptors());