<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">The naming in the bootstrap API was lacking some consistency and was a bit obscure at time<div><br></div><div>I went back tot he drawing board and came with something that is I think more natural and thus easier to use:</div><div> - to build <font class="Apple-style-span" face="'Courier New'">ValidatorFactory</font></div><div> - to build<font class="Apple-style-span" face="'Courier New'"> Validator</font></div><div><br></div><div>Each set of proposal change is followed by the old and new syntax. Feedback welcome.</div><div><br></div><div><b>To Build a ValidatorFactory</b></div><div><br></div><div>Here are the proposed changes</div><div><font class="Apple-style-span" face="'Courier New'">ValidatorFactoryBuilder</font> => <font class="Apple-style-span" face="'Courier New'">Configuration</font> (should it be <font class="Apple-style-span" face="'Courier New'">ValidatorFactoryConfiguration</font>)</div><div><font class="Apple-style-span" face="'Courier New'">Validation.builderType(Class<T>)</font> to <font class="Apple-style-span" face="'Courier New'">Validation.byProvider(Class<T>)</font></div><div><font class="Apple-style-span" face="'Courier New'">Validation.defineBootstrapState()<span class="Apple-style-span" style="font-family: Helvetica; "> to</span> Validation.byDefaultProvider()</font></div><div><font class="Apple-style-span" face="'Courier New'">GenericBuilderFactory.getBuilder()<span class="Apple-style-span" style="font-family: Helvetica; "> to</span> GenericConfigurationFactory.configure()</font></div><div><div><font class="Apple-style-span" face="'Courier New'">SpecializedBuilderFactory.getBuilder()<span class="Apple-style-span" style="font-family: Helvetica; "> to</span> SpecializedConfigurationFactory.configure()</font></div></div><div><font class="Apple-style-span" face="'Courier New'">ValidatorFactoryBuilder.build() <span class="Apple-style-span" style="font-family: Helvetica; ">to</span> Configuration.getValidatorFactory() <span class="Apple-style-span" style="font-family: Helvetica; "> (should it be<span class="Apple-style-span" style="font-family: 'Courier New'; "> buildValidatorFactory()<span class="Apple-style-span" style="font-family: Helvetica; ">?)</span></span></span></font></div><div><font class="Apple-style-span" face="'Courier New'">ValidatorFactoryBuilder.configure() <span class="Apple-style-span" style="font-family: Helvetica; ">to</span> Configuration.customConfiguration()</font></div><div><br></div><div><br></div><div>Also I am considering:</div><div> - removing <font class="Apple-style-span" face="'Courier New'">Validation.getBuilder()</font> (which would have been Validation.configure() )</div><div> - adding <font class="Apple-style-span" face="'Courier New'">Validation.getDefaultValidatorFactory()</font> (which correspond to the default bootstrap strategy used by JPA and JSF unless overridden)</div><div><br></div><div>Here are various bootstraps with the old naming followed by the new naming. You will see that we gain in consistency and expressivity:</div><div> - byProvider(Class<?>) vs byDefaultProvider()</div><div> - the object type retrieved and its purpose is more obvious (configure(), getValidatorFactory())</div><div> - the builder is a configuration object retrieving state to build ValidatorFactory</div><div><br></div><div>//simple bootstrap</div><div><font class="Apple-style-span" face="'Courier New'">ValidatorFactoryBuilder<?> builder = Validation.getBuilder();</font></div><div>=> no equivalent but replaced by</div><div><font class="Apple-style-span" face="'Courier New'">Configuration<?> configuration = Validation.byDefaultProvider().configure();</font></div><div><br></div><div><font class="Apple-style-span" face="'Courier New'">Validation.getBuilder().build();</font></div><div>=></div><div><font class="Apple-style-span" face="'Courier New'">ValidatorFactory factory = Validation.getDefaultValidatorFactory();</font></div><div><br></div><div>//use generic provider with specific resolver strategy</div><div><font class="Apple-style-span" face="'Courier New'">ValidatorFactoryBuilder<?> factoryBuilder = </font></div><div><div><font class="Apple-style-span" face="'Courier New'"> Validation.defineBootstrapState()</font></div><div><font class="Apple-style-span" face="'Courier New'"> .providerResolver(...) //optional step</font></div><div><font class="Apple-style-span" face="'Courier New'"> .getBuilder();</font></div><div>=></div><div><font class="Apple-style-span" face="'Courier New'">Configuration<?> configuration = </font></div><div><font class="Apple-style-span" face="'Courier New'"> Validation.byDefaultProvider()</font></div><div><div><font class="Apple-style-span" face="'Courier New'"> .providerResolver(...) //optional step</font></div><div><font class="Apple-style-span" face="'Courier New'"> .configure();</font></div><div><br></div><div>//use a specific provider with specific resolver strategy</div><div><div><font class="Apple-style-span" face="'Courier New'">ValidatorFactoryBuilder<?> factoryBuilder = </font></div><div><div><font class="Apple-style-span" face="'Courier New'"> Validation.builderType(ACMEValidatorFactoryBuilder.class)</font></div><div><font class="Apple-style-span" face="'Courier New'"> .providerResolver(...) //optional step</font></div><div><font class="Apple-style-span" face="'Courier New'"> .getBuilder();</font></div><div>=></div><div><font class="Apple-style-span" face="'Courier New'">Configuration<?> configuration = </font></div><div><font class="Apple-style-span" face="'Courier New'"> Validation.byProvider(ACMEValidatorConfiguration.class)</font></div><div><div><font class="Apple-style-span" face="'Courier New'"> .providerResolver(...) //optional step</font></div><div><font class="Apple-style-span" face="'Courier New'"> .configure();</font></div><div><br></div><div>I am also wondering if we should rename the methods on the <font class="Apple-style-span" face="'Courier New'">Configuration</font> object (former <font class="Apple-style-span" face="'Courier New'">ValidatorFactoryBuilder</font>):</div><div><div> - <font class="Apple-style-span" face="'Courier New'">messageResolver</font> => <font class="Apple-style-span" face="'Courier New'">useMessageResolver</font></div><div> - <font class="Apple-style-span" face="'Courier New'">providerResolver</font> => <font class="Apple-style-span" face="'Courier New'">useProviderResolver</font></div><div> - <font class="Apple-style-span" face="'Courier New'">traversableResolver</font> => <font class="Apple-style-span" face="'Courier New'">useTraversableResolver</font></div><div> - <font class="Apple-style-span" face="'Courier New'">customConfiguration</font> => <font class="Apple-style-span" face="'Courier New'">useCustomConfiguration</font></div><div> - <font class="Apple-style-span" face="'Courier New'">constraintFactory</font> => <font class="Apple-style-span" face="'Courier New'">useConstraintFactory</font></div></div><div><br></div><div>This makes them a bit more "fluent" but also more verbose.</div><div><br></div><div><span class="Apple-style-span" style="font-weight: bold; ">To Build a Validator</span></div><div><b><br></b></div><div><div>rename <font class="Apple-style-span" face="'Courier New'">ValidatorFactory.defineValidatorState()</font> to <font class="Apple-style-span" face="'Courier New'">ValidatorFactory.usingContext()</font></div><div>rename <font class="Apple-style-span" face="'Courier New'">ValidatorBuilder</font> to <font class="Apple-style-span" face="'Courier New'">ValidatorContext</font></div><div><br></div><div>Here are various bootstraps with the old naming followed by the new naming. We gain consistency with the VF creation as well</div><div><br></div><div><div>//simple validator creation</div><div><font class="Apple-style-span" face="'Courier New'">Validator validator = validatorFactory.getValidator();</font></div><div>=></div><div><font class="Apple-style-span" face="'Courier New'">Validator validator = validatorFactory.getValidator(); </font> //unchanged</div><div><br></div><div>//with overriding context</div><div><font class="Apple-style-span" face="'Courier New'">Validator validator = </font></div><div><font class="Apple-style-span" face="'Courier New'"> validatorFactory.defineValidatorState()</font></div><div><font class="Apple-style-span" face="'Courier New'"> .traversableResolver(...)</font></div><div><font class="Apple-style-span" face="'Courier New'"> .messageResolver(...)</font></div><div><font class="Apple-style-span" face="'Courier New'"> .getValidator();</font></div><div>=></div><div><div><font class="Apple-style-span" face="'Courier New'">Validator validator = </font></div><div><font class="Apple-style-span" face="'Courier New'"> validatorFactory.usingContext()</font></div><div><font class="Apple-style-span" face="'Courier New'"> .traversableResolver(...)</font></div><div><font class="Apple-style-span" face="'Courier New'"> .messageResolver(...)</font></div><div><font class="Apple-style-span" face="'Courier New'"> .getValidator();</font></div><div><br></div><div>What do you think?</div><div><br></div><div>There are three layers of changes:</div><div> - having a consistent naming between VF and V creations and using more meaningful name for the build method (ie getValidator / getValidatorFactory</div><div> - having a consistent path and naming wether you use the default provider or a specific one</div><div> - rename the builder classes with meaningful definitions</div></div></div></div></div></div></div></div></div><br><div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><br></div></div></div></div></div></body></html>