<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I moved<br>hasConstraints() to the ElementDescritpor<br>which means that BeanDescriptor, PropertyDescritpor do inherit from it. Make sense.<br><br>I also added a isBeanConstrained() to BeanDescriptor to know if a given class will be impacted by validation (namely if any of it's field, method or class / superclass / interfaces is annotated with a constraint or with @Valid). It is a flag to take care of or ignore a given class.<br><br>I also renamed BeanDescriptor.getPropertiesWithConstraints to BeanDescriptor.getConstrainedProperties.<br><br>I am not too happy with the namings though, especially isBeanConstrained(), so any improvement proposal is welcome.<div><br></div><div><span class="Apple-style-span" style="font-family: -webkit-sans-serif; font-size: 14px; "><div class="section" lang="en" style="font-family: sans-serif; font-size: 14px; "><div class="titlepage" style="font-family: sans-serif; font-size: 14px; "><div style="font-family: sans-serif; font-size: 14px; "><div style="font-family: sans-serif; font-size: 14px; "><h2 class="title" style="clear: both; font-family: sans-serif; color: rgb(0, 51, 153); font-size: 140%; margin-top: 10px; padding-top: 5px; font-weight: bold; ">5.2. ElementDescriptor</h2></div></div><div style="font-family: sans-serif; font-size: 14px; "></div></div><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); "><tt class="classname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">ElementDescriptor</tt> is the root interface describing elements hosting constraints. It is used to describe the list of constraints for a given element (whether it be a field, a method or a class).</p><pre class="programlisting" style="font-size: 100%; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); background-color: rgb(244, 244, 244); font-family: monospace; width: auto; ">/**
* Describes a validated element (class, field or property).
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
public interface ElementDescriptor {
        /**
         * return true if at least one constraint declaration is present on the element.
         */
        boolean hasConstraints();
        /**
         * @return Statically defined returned type.
         *
         * @todo should it be Type or even completly removed
         */
        Class<?> getType();
        /**
         * @return All the constraint descriptors for this element.
         */
        List<ConstraintDescriptor> getConstraintDescriptors();
}</pre><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); "><tt class="methodname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">getType</tt> returns either the object type for a class, or the returned type for a property (TODO problem of generics resolution).</p><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); "><tt class="classname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">getConstraintDescriptors</tt> returns the <tt class="classname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">ConstraintDescriptor</tt>s (see <a href="file:///Users/manu/projects/specs/303/specbook/build/en/html/constraintmetadata.html#constraintmetadata-constraintdescriptor" title="5.5. ConstraintDescriptor" style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 204); ">Section 5.5, “ConstraintDescriptor”</a>), each <tt class="classname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">ConstraintDescriptor</tt>describing one of the constraints declared on the given element.</p><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); "><tt class="methodname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">hasConstraints</tt> returns true if the element (class, field or property) holds at lease one constraint declaration.</p></div><div class="section" lang="en" style="font-family: sans-serif; font-size: 14px; "><div class="titlepage" style="font-family: sans-serif; font-size: 14px; "><div style="font-family: sans-serif; font-size: 14px; "><div style="font-family: sans-serif; font-size: 14px; "><h2 class="title" style="clear: both; font-family: sans-serif; color: rgb(0, 51, 153); font-size: 140%; margin-top: 10px; padding-top: 5px; font-weight: bold; "><a name="d0e3836" style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 204); "></a>5.3. BeanDescriptor</h2></div></div><div style="font-family: sans-serif; font-size: 14px; "></div></div><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); ">The <tt class="classname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">BeanDescriptor</tt> interface describes a constrained Java Bean. This interface is returned by <tt class="methodname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">Validator.getConstraintsForClass(Class<?>)</tt>.</p><pre class="programlisting" style="font-size: 100%; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); background-color: rgb(244, 244, 244); font-family: monospace; width: auto; ">/**
* Describe a constrained Java Bean and the constraints associated to it.
*
* @author Emmanuel Bernard
*/
public interface BeanDescriptor extends ElementDescriptor {
        /**
         * Returns true if the bean involves validation:
         * - a constraint is hosted on the bean itself
         * - a constraint is hosted on one of the bean properties
         * - or a bean property is marked for cascade (@Valid)
         *
         * @return true if the bean nvolves validation
         *
         */
        boolean isBeanConstrained();
        /**
         * Return the property level constraints for a given propertyName
         * or 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 evaludated
         */
        PropertyDescriptor getConstraintsForProperty(String propertyName);
        /**
         * return the property names having at least a constraint defined or marked
         * as cascaded (@Valid)
         */
        Set<String> getConstrainedProperties();
}</pre><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); "><tt class="methodname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">isBeanConstrained</tt> returns true if the given class (and superclasses and interfaces) host at least one validation declaration (either constraint or<tt class="classname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">@Valid</tt> annotation). If the method returns false, the Bean Validation engine can safely ignore the bean as it will not be impacted by validation.</p><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); "><tt class="methodname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">getConstraintsForProperty</tt> returns a <tt class="classname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">PropertyDescriptor</tt> object describing the property level constraints (See <a href="file:///Users/manu/projects/specs/303/specbook/build/en/html/constraintdeclarationvalidationprocess.html#constraintdeclarationvalidationprocess-requirements-property" title="3.1.2. Field and property validation" style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 204); ">Section 3.1.2, “Field and property validation”</a>). The property is uniquely identified by its name as per the JavaBeans convention: field level and getter level constraints of the given name are all returned.</p><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); "><tt class="methodname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">getConstrainedProperties</tt> returns the names of the bean properties having at least one constraint or being cascaded (<tt class="classname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">@Valid</tt> annotation).</p></div><div class="section" lang="en" style="font-family: sans-serif; font-size: 14px; "><div class="titlepage" style="font-family: sans-serif; font-size: 14px; "><div style="font-family: sans-serif; font-size: 14px; "><div style="font-family: sans-serif; font-size: 14px; "><h2 class="title" style="clear: both; font-family: sans-serif; color: rgb(0, 51, 153); font-size: 140%; margin-top: 10px; padding-top: 5px; font-weight: bold; "><a name="d0e3872" style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 204); "></a>5.4. PropertyDescriptor</h2></div></div><div style="font-family: sans-serif; font-size: 14px; "></div></div><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); ">The <tt class="classname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">PropertyDescriptor</tt> interface describes a constrained property of a Java Bean. This interface is returned by<tt class="methodname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">BeanDescriptor.getConstraintsForProperty(String)</tt>. Constraints declared on the attribute and the getter of the same name according to the Java Bean rules are returned by this descriptor.</p><pre class="programlisting" style="font-size: 100%; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); background-color: rgb(244, 244, 244); font-family: monospace; width: auto; ">/**
* Describes a Java Bean property hosting validation constraints.
*
* Constraints placed on the attribute and the getter for a given property
* are all referenced by this object.
*
* @author Emmanuel Bernard
*/
public interface PropertyDescriptor extends ElementDescriptor {
/**
* Is the property marked by the <code>@Valid</code> annotation.
* @return true if the annotation is present
*/
boolean isCascaded();
/**
* Name of the property acording to the Java Bean specification.
* @return property name
*/
String getPropertyName();
}</pre><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); ">The <tt class="methodname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">isCascaded</tt> method returns <tt class="literal" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">true</tt> if the property is marked with <tt class="classname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">@Valid</tt>.</p><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); "><tt class="methodname" style="font-size: 100%; color: rgb(17, 17, 17); font-family: monospace; ">getPropertyName</tt> returns the property name as described in <a href="file:///Users/manu/projects/specs/303/specbook/build/en/html/validationapi.html#validationapi-constraintviolation" title="4.2. ConstraintViolation" style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 204); ">Section 4.2, “ConstraintViolation”</a>.</p></div></span></div></body></html>