<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Feedback please. I am sick of talking to myself<div><br><div><div>On Jan 21, 2009, at 23:37, Emmanuel Bernard wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>I looked at the OVAL schema and as usual there are good stuffs here, I also added some missing elements<div> - I forgot the flag to be able to ignore existing annotations</div><div> - I forgot the @Valid equivalent</div><div> - OVal has the ability to describe OVal specific constraints in a typesafe way but not custom user constraints (as far as I can see). </div><div><br></div><div>Let me know what you think, especially on the constraints declarations options.</div><div><br></div><div><b>Ignore Annotation flag</b></div><div>Should the ignore-annotation flag be a <bean/> level attribute only or should a user be able to define it at the field/method/class level?</div><div>If set to true, annotations placed on the bean, field or getter will not be considered. If set to false, they will.</div><div><br></div><div><b>@Valid</b></div><div><valid/></div><div>will indicate that a field or a getter is to be cascaded</div><div><br></div><div><b>Constraints declarations</b></div><div>In the current schema proposal, here is how constraints are declared</div><div><br></div><div> <constraint annotation="com.acme.validate.SafeCustomer"><br> <attribute name="category"><br> <array-element>com.acme.validate.SecurityLevel.SECURED_COUNTRY</array-element><br> <array-element>com.acme.validate.SecurityLevel.SECURED_ADDRESS</array-element><br> <array-element>com.acme.validate.SecurityLevel.SECURED_FINANCIALS</array-element><br> </attribute><br> <attribute name="failPerCategory">false</attribute><br> </constraint></div><div> <constraint annotation="javax.validation.constraint.NotNull"></div><div> <message>blah</message></div><div> </constraint></div><div><br></div><div>We could enhance this in two ways:</div><div> - provide type-safe support for built-in validations:</div><div><not-null/>, </div><div><min></div><div> <value>3</value></div><div> <message>blah</message></div><div></min></div><div>etc</div><div> - allow custom constraints support in a type-safe way: </div><div><br></div><div>The second point would work as followed</div><div> - a constraint annotation would be associated with a given XML type eg. <Min/></div><div> - propose an abstract constraintType XML type that any constraint declared in XML would inherit (Min would extend ConstraintType)</div><div> - thanks to that message and groups would be inherited</div><div> - Min would have an attribute "annotation" fixed to the f.q.c.n of the corresponding annotation (I haven't find a way to hide it from the user but still have it present at parsing time)</div><div> - subelements of a constraint XML element would represent attributes of the annotation (with the same name)</div><div><br></div><div><div><div><?xml version="1.0" encoding="UTF-8"?></div><div><validation-mappings</div><div> xmlns="<a href="http://jboss.com/java/validation-mapping">http://jboss.com/java/validation-mapping</a>"</div><div> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"</div><div> xmlns:appval="<a href="http://acme.com/appval">http://acme.com/appval</a>"</div><div> xsi:schemaLocation="<a href="http://jboss.com/java/validation-mapping">http://jboss.com/java/validation-mapping</a> validation-mapping.xsd"></div><div> <default-package>com.acme.dvdstore.model</default-package></div><div> <bean class="Customer" i<b>gnore-annotations="true"</b>></div><div> <class></div><div> <constraint annotation="com.acme.validate.SafeCustomer"></div><div> <attribute name="category"></div><div> <array-element>com.acme.validate.SecurityLevel.SECURED_COUNTRY</array-element></div><div> <array-element>com.acme.validate.SecurityLevel.SECURED_ADDRESS</array-element></div><div> <array-element>com.acme.validate.SecurityLevel.SECURED_FINANCIALS</array-element></div><div> </attribute></div><div> <attribute name="failPerCategory">false</attribute></div><div> </constraint></div><div> </class></div><div> <fields></div><div> <field name="firstname"></div><div><b> <valid/></b></div><div><b> <appval:min annotation="javax.validation.constraint.Min"></b></div><div><b> <message>blah</message></b></div><div><b> <value>4</value></b></div><div><b> </appval:min></b></div><div> <constraint annotation="javax.validation.Min"></div><div> <message>{error.tooSmall}</message></div><div> <groups></div><div> <group>javax.validation.groups.Default</group></div><div> </groups></div><div> <attribute name="value">45</attribute></div><div> </constraint></div><div> </field></div><div> </fields></div><div> <getters></div><div> <getter name="firstname"></div><div> <ignore-annotations/></div><div> <stop-inheritance/></div><div> <constraint annotation="javax.validation.Min"></div><div> <message>{error.tooSmall}</message></div><div> <groups></div><div> <group>javax.validation.groups.Default</group></div><div> </groups></div><div> <attribute name="value">45</attribute></div><div> </constraint></div><div> </getter></div><div> </getters></div><div> </bean></div><div></validation-mappings></div></div><div><br></div><div><br></div><div>where app:val is described in the XSD as </div><div><div><?xml version="1.0" encoding="UTF-8"?></div><div><xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>" version="1.0"</div><div> xmlns:bv="<a href="http://jboss.com/java/validation-mapping">http://jboss.com/java/validation-mapping</a>"></div><div> <xs:element name="min" type="minType"/></div><div><br></div><div> <xs:complexType name="minType"></div><div> <xs:complexContent></div><div> <xs:extension base="bv:AbstractConstraintType"></div><div> <xs:sequence></div><div> <xs:element name="value" type="xs:int" minOccurs="1"/></div><div> </xs:sequence></div><div> <xs:attribute name="annotation" use="required" fixed="javax.validation.constraint.Min"/></div><div> </xs:extension></div><div> </xs:complexContent></div><div> </xs:complexType></div><div></xs:schema></div></div></div></div><br><div><div>On Jan 19, 2009, at 19:35, Emmanuel Bernard wrote:</div><br><blockquote type="cite"><div>Here is my very first attempt to describe the constraint mapping XML schema.<br>I did not look at other product approach to avoid being tainted. If you have examples of alternative approach, I would appreciate a link.<br><br>A couple of comments:<br>- I would have preferred a Web Beans style XML approach but this kind of approach is getting some heavy resistance from some members of the expert committee. So I fell back to a more classic approach.<br>- constraints themselves cannot be defined: you have to write an actual annotation. I wonder if we should provide such model. At minimal we might want to provide a way to override the constraint validator for a given constraint.<br>- I used JPA 2 mapping schema as inspiration<br>- I stayed very close to the Java structure<br><br>Better names, enhancements, alternative proposals are welcome.<br><br>Emmanuel<br><br><?xml version="1.0" encoding="UTF-8"?><br><validation-mappings><br> <package>com.acme.dvdstore.model</package><br> <bean class="Customer"><br> <class><br> <constraint annotation="com.acme.validate.SafeCustomer"><br> <attribute name="category"><br> <array-element>com.acme.validate.SecurityLevel.SECURED_COUNTRY</array-element><br> <array-element>com.acme.validate.SecurityLevel.SECURED_ADDRESS</array-element><br> <array-element>com.acme.validate.SecurityLevel.SECURED_FINANCIALS</array-element><br> </attribute><br> <attribute name="failPerCategory">false</attribute><br> </constraint><br> </class><br> <fields><br> <field name="firstname"><br> <ignore-annotations/><br> <stop-inheritance/><br> <constraint annotation="javax.validation.Min"><br> <message>{error.tooSmall}</message><br> <groups><br> <group>javax.validation.groups.Default</group><br> </groups><br> <attribute name="value">45</attribute><br> </constraint><br> </field><br> </fields><br> <getters><br> <getter name="firstname"><br> <ignore-annotations/><br> <stop-inheritance/><br> <constraint annotation="javax.validation.Min"><br> <message>{error.tooSmall}</message><br> <groups><br> <group>javax.validation.groups.Default</group><br> </groups><br> <attribute name="value">45</attribute><br> </constraint><br> </getter><br> </getters><br> </bean><br></validation-mappings><br>_______________________________________________<br>hibernate-dev mailing list<br><a href="mailto:hibernate-dev@lists.jboss.org">hibernate-dev@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/hibernate-dev">https://lists.jboss.org/mailman/listinfo/hibernate-dev</a><br></div></blockquote></div><br></div>_______________________________________________<br>hibernate-dev mailing list<br><a href="mailto:hibernate-dev@lists.jboss.org">hibernate-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/hibernate-dev<br></blockquote></div><br></div></body></html>