[ 
https://issues.apache.org/jira/browse/SLING-4138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14200182#comment-14200182
 ] 

Konrad Windszus commented on SLING-4138:
----------------------------------------

What about this interface which covers the aspects b) and c) from SLING-4027:

{code}
/**
     * Validates the {@code data} and/or the {@code valueMap} according to the 
internal constraints of this validator.
     * 
     * The validator can enforce the type of the given data just by setting the 
appropriate parameter type which can be any non-primitive class. 
     * Depending on whether this type is an array or not the {@code validate} 
is called differently:
     * <table> 
     *  <tr>
     *    <th>T is array type</th>
     *    <th>Valuemap contains array value</th>
     *    <th>{@code validate} is called...</th>
     *  </tr>
     *  <tr>
     *    <td>yes</td>
     *    <td>yes</td>
     *    <td>once per property with {@code data} containing the array</td>
     *  </tr>
     *  <tr>
     *    <td>yes</td>
     *    <td>no</td>
     *    <td>once per property with {@code data} containing a single element 
array</td>
     *  </tr>
     *  <tr>
     *    <td>no</td>
     *    <td>yes</td>
     *    <td>once per element in the property array with {@code data} 
containing one array element</td>
     *  </tr>
     *  <tr>
     *    <td>no</td>
     *    <td>no</td>
     *    <td>once per property with {@code data} containing the value of the 
property</td>
     *  </tr>
     * </table>
     *
     * @param data the data to validate (primary property), never {@code null}.
     * @param valueMap all properties (only used for validations considering 
multiple properties), never {@code null}.
     * @param arguments the parametrization of the validator. Might be {@code 
null} in case no arguments were given.
     * @return validation error message if validation was not successfull, 
{@code null} otherwise. In case an empty string is returned a generic 
validation error message is used.
     * @throws 
org.apache.sling.validation.api.exceptions.SlingValidationException if some 
expected arguments are missing from the arguments map
     */
    String validate(T data, ValueMap valueMap, Map<String, String> arguments) 
throws SlingValidationException;
{code}

> Allow validator to support arbitrary types
> ------------------------------------------
>
>                 Key: SLING-4138
>                 URL: https://issues.apache.org/jira/browse/SLING-4138
>             Project: Sling
>          Issue Type: Improvement
>          Components: Validation
>            Reporter: Konrad Windszus
>
> Currently the {{Validator.validate}} method only act on String values. 
> Since type conversion is already built into the ValueMap, it would be good to 
> leverage that and to allow Validator to act on arbitrary types there!
> Also the type conversion from ValueMap should be leveraged to do the type 
> check in {{ValidationServiceImpl.validatePropertyValue}} rather than 
> implementing a new thing in {{Type.isValid()}}.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to