<p>Hi,</p><p>Am 27.08.2012 15:37 schrieb "Emmanuel Bernard" <<a href="mailto:emmanuel@hibernate.org" target="_blank">emmanuel@hibernate.org</a>>:<br>
><br>
><br>
> On 27 août 2012, at 10:51, Gunnar Morling wrote:<br>
>><br>
>> For the “getter“ approach, getMethodValidator() would be defined on ValidatorFactory, right? At least that was the original idea.<br>
><br>
><br>
> Ah. I was thinking `getMethodValidator()` was hosted to `Validator`. The negative I could see are:<br>
><br>
> 1. `ValidatorContext` needs to be updated too</p><p>> 2. we would require to allow injection of `MethodValidator` in injectable environments</p><p>
> 3. we will need to duplicate `getConstraintsForClass` and `unwrap` in `MethodValidator`</p>
<p>Hmmm, you're right about 1. and 2. No biggie though IMO.</p><p>I'm not sure about getConstraintsForClass(). Would it really be duplicated? I think the following options would be possible:</p><p>* Validator#getConstraintsForClass() could return a descriptor describing all (bean and method) constraints. No getConstraintsForClass() on MethodValidator.</p>
<p>* Validator#getConstraintsForClass() returns a descriptor of the bean constraints, MethodValidator#getConstraintsForClass() returns a descriptor representing the method level constraints.</p>
<p>Which one did you have in mind?</p><p>Regarding unwrap(), I'm tempted to say we should have it anyways on MethodValidator, or did you mean to unwrap via an implementation-specific Validator interface? Also in the fluent approach, I think I'd slightly prefer</p>
<p></p><p>MyMethodValidator mv = myValidator.getMethodValidator().unwrap(MyMethodValidator.class);</p><div>over</div><p></p><p>MyMethodValidator mv = myValidator.unwrap(MyValidator.class).getMethodValidator();</p>
<p>The main reason being, that it is more obvious and one doesn't need a specific Validator interface if one only wants to expose a specific MethodValidator interface. It doesn't make a huge difference, though.</p>
<p>
> Independently, they don't weight much (except point 3) but as a whole I wonder if that's the right approach.<br>
> What would be the negative points of putting it on `Validator`? It requires one extra method call. Any other?</p><p>I'd just find it more natural to retrieve a (method) validator from a validator factory instead from another validator. That way it's more regular IMO.</p>
<p>
><br>
> Emmanuel<br>
></p><p>--Gunnar</p><p>><br>
> _______________________________________________<br>
> beanvalidation-dev mailing list<br>
> <a href="mailto:beanvalidation-dev@lists.jboss.org" target="_blank">beanvalidation-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
></p>