@Override public Configuration<?> createGenericConfiguration(BootstrapState state) { return new ConfigurationImpl( state ); }
@Override public final MessageInterpolator getMessageInterpolator() { if ( messageInterpolator == null ) { // apply explicitly given MI, otherwise use default one MessageInterpolator interpolator = validationBootstrapParameters.getMessageInterpolator(); if ( interpolator != null ) { messageInterpolator = interpolator; } else { messageInterpolator = getDefaultMessageInterpolatorConfiguredWithClassLoader(); } } return messageInterpolator; }
private static ClassLoader getExternalClassLoader(ConfigurationState configurationState) { return ( configurationState instanceof ConfigurationImpl ) ? ( (ConfigurationImpl) configurationState ).getExternalClassLoader() : null; }
@Override public final ValidatorFactory buildValidatorFactory() { loadValueExtractorsFromServiceLoader(); parseValidationXml(); if ( isSpecificProvider() ) { factory = validationBootstrapParameters.getProvider().buildValidatorFactory( this );
/** * Tries to check whether a validation.xml file exists and parses it */ private void parseValidationXml() { if ( ignoreXmlConfiguration ) { log.ignoringXmlConfiguration(); if ( validationBootstrapParameters.getTraversableResolver() == null ) { validationBootstrapParameters.setTraversableResolver( defaultTraversableResolver ); } if ( validationBootstrapParameters.getConstraintValidatorFactory() == null ) { validationBootstrapParameters.setConstraintValidatorFactory( defaultConstraintValidatorFactory ); } if ( validationBootstrapParameters.getParameterNameProvider() == null ) { validationBootstrapParameters.setParameterNameProvider( defaultParameterNameProvider ); } } else { ValidationBootstrapParameters xmlParameters = new ValidationBootstrapParameters( getBootstrapConfiguration(), externalClassLoader ); applyXmlSettings( xmlParameters ); } }
final ClassLoader originalContextClassLoader = run( GetClassLoader.fromContext() ); run( SetContextClassLoader.action( externalClassLoader ) ); return new ResourceBundleMessageInterpolator( userResourceBundleLocator, run( SetContextClassLoader.action( originalContextClassLoader ) ); return getDefaultMessageInterpolator();
tmpFailFast = hibernateSpecificConfig.getFailFast(); hibernateSpecificConfig.getMethodValidationConfiguration() .isAllowOverridingMethodAlterParameterConstraint(); tmpAllowMultipleCascadedValidationOnReturnValues = hibernateSpecificConfig.getMethodValidationConfiguration() .isAllowMultipleCascadedValidationOnReturnValues(); tmpAllowParallelMethodsDefineParameterConstraints = hibernateSpecificConfig.getMethodValidationConfiguration() .isAllowParallelMethodsDefineParameterConstraints(); tmpValidatedValueHandlers.addAll( hibernateSpecificConfig.getValidatedValueHandlers() );
@Override public final ValidatorFactory buildValidatorFactory() { parseValidationXml(); ValidatorFactory factory = null; try { if ( isSpecificProvider() ) { factory = validationBootstrapParameters.getProvider().buildValidatorFactory( this );
private static Set<DefaultConstraintMapping> getConstraintMappings(ConfigurationState configurationState, ClassLoader externalClassLoader) { Set<DefaultConstraintMapping> constraintMappings = newHashSet(); if ( configurationState instanceof ConfigurationImpl ) { ConfigurationImpl hibernateConfiguration = (ConfigurationImpl) configurationState; // programmatic config /* We add these first so that constraint mapping created through DefaultConstraintMappingBuilder will take * these programmatically defined mappings into account when checking for constraint definition uniqueness */ constraintMappings.addAll( hibernateConfiguration.getProgrammaticMappings() ); // service loader based config ConstraintMappingContributor serviceLoaderBasedContributor = hibernateConfiguration.getServiceLoaderBasedConstraintMappingContributor(); DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder( constraintMappings ); serviceLoaderBasedContributor.createConstraintMappings( builder ); } // XML-defined constraint mapping contributors List<ConstraintMappingContributor> contributors = getPropertyConfiguredConstraintMappingContributors( configurationState.getProperties(), externalClassLoader ); for ( ConstraintMappingContributor contributor : contributors ) { DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder( constraintMappings ); contributor.createConstraintMappings( builder ); } return constraintMappings; }
private static boolean getAllowParallelMethodsDefineParameterConstraints(ConfigurationImpl hibernateSpecificConfig, Map<String, String> properties) { return checkPropertiesForBoolean( properties, HibernateValidatorConfiguration.ALLOW_PARALLEL_METHODS_DEFINE_PARAMETER_CONSTRAINTS, hibernateSpecificConfig != null ? hibernateSpecificConfig.getMethodValidationConfiguration().isAllowParallelMethodsDefineParameterConstraints() : false ); }
private static boolean getFailFast(ConfigurationImpl configuration, Map<String, String> properties) { // check whether fail fast is programmatically enabled boolean tmpFailFast = configuration != null ? configuration.getFailFast() : false; String propertyStringValue = properties.get( HibernateValidatorConfiguration.FAIL_FAST ); if ( propertyStringValue != null ) { boolean configurationValue = Boolean.valueOf( propertyStringValue ); // throw an exception if the programmatic value is true and it overrides a false configured value if ( tmpFailFast && !configurationValue ) { throw LOG.getInconsistentFailFastConfigurationException(); } tmpFailFast = configurationValue; } return tmpFailFast; }
private static Set<DefaultConstraintMapping> getConstraintMappings(TypeResolutionHelper typeResolutionHelper, ConfigurationState configurationState, ClassLoader externalClassLoader) { Set<DefaultConstraintMapping> constraintMappings = newHashSet(); if ( configurationState instanceof ConfigurationImpl ) { ConfigurationImpl hibernateConfiguration = (ConfigurationImpl) configurationState; // programmatic config /* We add these first so that constraint mapping created through DefaultConstraintMappingBuilder will take * these programmatically defined mappings into account when checking for constraint definition uniqueness */ constraintMappings.addAll( hibernateConfiguration.getProgrammaticMappings() ); // service loader based config ConstraintMappingContributor serviceLoaderBasedContributor = new ServiceLoaderBasedConstraintMappingContributor( typeResolutionHelper, externalClassLoader != null ? externalClassLoader : run( GetClassLoader.fromContext() ) ); DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder( constraintMappings ); serviceLoaderBasedContributor.createConstraintMappings( builder ); } // XML-defined constraint mapping contributors List<ConstraintMappingContributor> contributors = getPropertyConfiguredConstraintMappingContributors( configurationState.getProperties(), externalClassLoader ); for ( ConstraintMappingContributor contributor : contributors ) { DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder( constraintMappings ); contributor.createConstraintMappings( builder ); } return constraintMappings; }
/** * Tries to check whether a validation.xml file exists and parses it */ private void parseValidationXml() { if ( ignoreXmlConfiguration ) { LOG.ignoringXmlConfiguration(); if ( validationBootstrapParameters.getTraversableResolver() == null ) { validationBootstrapParameters.setTraversableResolver( defaultTraversableResolver ); } if ( validationBootstrapParameters.getConstraintValidatorFactory() == null ) { validationBootstrapParameters.setConstraintValidatorFactory( defaultConstraintValidatorFactory ); } if ( validationBootstrapParameters.getParameterNameProvider() == null ) { validationBootstrapParameters.setParameterNameProvider( defaultParameterNameProvider ); } if ( validationBootstrapParameters.getClockProvider() == null ) { validationBootstrapParameters.setClockProvider( defaultClockProvider ); } } else { ValidationBootstrapParameters xmlParameters = new ValidationBootstrapParameters( getBootstrapConfiguration(), externalClassLoader ); applyXmlSettings( xmlParameters ); } }
final ClassLoader originalContextClassLoader = run( GetClassLoader.fromContext() ); run( SetContextClassLoader.action( externalClassLoader ) ); return new ResourceBundleMessageInterpolator( userResourceBundleLocator, run( SetContextClassLoader.action( originalContextClassLoader ) ); return getDefaultMessageInterpolator();
private static boolean getAllowMultipleCascadedValidationOnReturnValues(ConfigurationImpl hibernateSpecificConfig, Map<String, String> properties) { return checkPropertiesForBoolean( properties, HibernateValidatorConfiguration.ALLOW_MULTIPLE_CASCADED_VALIDATION_ON_RESULT, hibernateSpecificConfig != null ? hibernateSpecificConfig.getMethodValidationConfiguration().isAllowMultipleCascadedValidationOnReturnValues() : false ); }
@Override public Configuration<?> createGenericConfiguration(BootstrapState state) { return new ConfigurationImpl( state ); }
private static boolean getAllowOverridingMethodAlterParameterConstraint(ConfigurationImpl hibernateSpecificConfig, Map<String, String> properties) { return checkPropertiesForBoolean( properties, HibernateValidatorConfiguration.ALLOW_PARAMETER_CONSTRAINT_OVERRIDE, hibernateSpecificConfig != null ? hibernateSpecificConfig.getMethodValidationConfiguration().isAllowOverridingMethodAlterParameterConstraint() : false ); }
@Override public final MessageInterpolator getMessageInterpolator() { if ( messageInterpolator == null ) { // apply explicitly given MI, otherwise use default one MessageInterpolator interpolator = validationBootstrapParameters.getMessageInterpolator(); if ( interpolator != null ) { messageInterpolator = interpolator; } else { messageInterpolator = getDefaultMessageInterpolatorConfiguredWithClassLoader(); } } return messageInterpolator; }
private static ClassLoader getExternalClassLoader(ConfigurationState configurationState) { return ( configurationState instanceof ConfigurationImpl ) ? ( (ConfigurationImpl) configurationState ).getExternalClassLoader() : null; }
@Override public HibernateValidatorConfiguration createSpecializedConfiguration(BootstrapState state) { return HibernateValidatorConfiguration.class.cast( new ConfigurationImpl( this ) ); }