<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Please review. Also we need to implement the // group validation in HV to avoid to many passes.<br><div><br><div>Begin forwarded message:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>From: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Emmanuel Bernard <<a href="mailto:emmanuel.bernard@JBOSS.COM">emmanuel.bernard@JBOSS.COM</a>></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>Date:<span class="Apple-converted-space"> </span></b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica"> May 26, 2009 16:43:53<span class="Apple-converted-space"> </span>CEDT</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>To: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica"><a href="mailto:JSR-303-EG@JCP.ORG">JSR-303-EG@JCP.ORG</a></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>Subject: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica"><b>Support for constraints by groups</b></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>Reply-To: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Java Community Process JSR #303 Expert List <<a href="mailto:JSR-303-EG@JCP.ORG">JSR-303-EG@JCP.ORG</a>></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div> </div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div>following a subject dear to Gerhard's heart :)<br><div>I could think of two approaches, let's beat them to death and if possible find a better alternative :)</div><div><br></div><div><br></div><div><b># background</b></div><div>When validating a specific group(s), Bean Validation expends the group into a sequence of groups to be validated (because a group can be a group sequence really). Depending on how clever the implementation is, it could sequencialize all group execution or try to validate several non sequenced group in parallel.</div><div><br></div><div>The concept of discovering which group is validated based on the requested groups is complex enough so an API at the metadata level is required.</div><div><br></div><div>examples</div><div>public interface Minimal {}</div><div><br></div><div>@GroupSequence(Minimal.class, Default.class)</div><div>public interface Complete {}</div><div><br></div><div><br></div><div><b>#1 define the API at the ElementDescriptor level</b></div><div><br></div><div>BeanDescriptor bd = validator.getConstraintsForClass(Address.class);</div><div>PropertyDescriptor pd = bd.getConstraintsForProperty("street1");</div><div>List<Set<ConstraintDescriptor>> sequencedConstraints = pd.getConstraintDescriptorsForGroups(Complete.class);</div><div>//all ConstraintDescriptor in a given set can be validated in the same pass</div><div>//two sets of constraints must be validated sequencially. If one constraint fails, the following sets must be ignored</div><div><br></div><div>for (Set<ConstraintDescriptor> subConstraints : sequencedConstraints) {</div><div> if ( validate(subConstraints) == true ) break;</div><div>}</div><div><br></div><div>The API added is </div><div>ElementDescriptor#getConstraintDescriptorsForGroups(Class<?>... groups)</div><div><br></div><div>Optionally we can add</div><div>ElementDescriptor#hasConstraints(Class<?>... groups)</div><div><br></div><div><div>Pro: The metadata is never "contextual" hence has less risk of error.</div><div>Con: Needs to pass the groups at several levels</div></div><div><br></div><div><b>#2 define the API at the validator level (more aligned with Gerhard's proposal but supporting sequences)</b></div><div><br></div><div>List<BeanDescriptor> sequencedDescriptors = validator.getConstraintsForClassAndGroups(Address.class, Complete.class);</div><div>for (BeanDescriptor bd : sequencedDescriptor) {</div><div> PropertyDescriptor pd = bd. getConstraintsForProperty("street1");</div><div> Set<ConstraintDescriptor> subConstraints = pd.getConstraintDescriptors();</div><div> if ( validate(subConstraints) == true ) break;</div><div>}</div><div><br></div><div><div>Pro: The metadata is "contextual" hence people can become confused</div><div>Con: once contextualized, the API looks the same as the non contextual one</div></div><div><br></div><div>Questions:</div><div> - should we use List to represent a sequence r should we have a dedicated object implementing Iterable</div><div> - we need to ensure that a given group always return the same sequencing regardless of the element (bean or property). This is necessary to ensure that one can validate all bean and property level constraints (and potentially the associated object) before going to the next sequence. How can we formalize that?</div><div><br></div><div>WDYT of all that?</div></div></div></blockquote></div><br></body></html>