Java Code Examples for javax.validation.Configuration

The following are top voted examples for showing how to use javax.validation.Configuration. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: infobip-bean-validation   File: CustomLocalValidatorFactoryBean.java   View source code 5 votes vote down vote up
@Override
protected void postProcessConfiguration(Configuration<?> configuration) {
    super.postProcessConfiguration(configuration);
    HibernateValidatorConfiguration hibernateConfiguration = (HibernateValidatorConfiguration) configuration;

    ConstraintMapping constraintMapping = hibernateConfiguration.createConstraintMapping();
    validators.forEach(validator -> addConstraint(constraintMapping, validator));
    hibernateConfiguration.addMapping(constraintMapping);

    hibernateValidatorConfigurationStrategy.accept(hibernateConfiguration);
}
 
Example 2
Project: syndesis   File: ValidatorContextResolver.java   View source code 5 votes vote down vote up
@Override
public GeneralValidator getContext(final Class<?> type) {
    final ResourceBundleLocator resourceBundleLocator = new PlatformResourceBundleLocator("messages");
    final MessageInterpolator messageInterpolator = new ResourceBundleMessageInterpolator(resourceBundleLocator);
    final Configuration<?> config = Validation.byDefaultProvider().configure()
        .messageInterpolator(messageInterpolator);
    final BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();
    final boolean isExecutableValidationEnabled = bootstrapConfiguration.isExecutableValidationEnabled();
    final Set<ExecutableType> defaultValidatedExecutableTypes = bootstrapConfiguration
        .getDefaultValidatedExecutableTypes();

    return new GeneralValidatorImpl(validatorFactory, isExecutableValidationEnabled,
        defaultValidatedExecutableTypes);
}
 
Example 3
Project: syndesis-rest   File: ValidatorContextResolver.java   View source code 5 votes vote down vote up
@Override
public GeneralValidator getContext(final Class<?> type) {
    final ResourceBundleLocator resourceBundleLocator = new PlatformResourceBundleLocator("messages");
    final MessageInterpolator messageInterpolator = new ResourceBundleMessageInterpolator(resourceBundleLocator);
    final Configuration<?> config = Validation.byDefaultProvider().configure()
        .messageInterpolator(messageInterpolator);
    final BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();
    final boolean isExecutableValidationEnabled = bootstrapConfiguration.isExecutableValidationEnabled();
    final Set<ExecutableType> defaultValidatedExecutableTypes = bootstrapConfiguration
        .getDefaultValidatedExecutableTypes();

    return new GeneralValidatorImpl(validatorFactory, isExecutableValidationEnabled,
        defaultValidatedExecutableTypes);
}
 
Example 4
Project: opencucina   File: BeanMessageInterpolator.java   View source code 5 votes vote down vote up
/**
 * Creates a new BeanMessageInterpolator object. The nested delegator is
 * pulled from the bootstrap of the validation provider
 *
 */
public BeanMessageInterpolator() {
    @SuppressWarnings("rawtypes")
    Configuration configuration = Validation.byDefaultProvider().configure();

    delegate = configuration.getDefaultMessageInterpolator();
}
 
Example 5
Project: packagedrone   File: ValidationBundle.java   View source code 5 votes vote down vote up
private static Validator buildValidator ()
{
    final GenericBootstrap bootstrap = Validation.byDefaultProvider ();
    bootstrap.providerResolver ( tracker );

    final Configuration<?> cfg = bootstrap.configure ();
    final OsgiMessageInterpolator mi = getMessageInterpolator ();
    mi.setFallback ( cfg.getDefaultMessageInterpolator () );
    cfg.messageInterpolator ( mi );

    final ValidatorFactory factory = cfg.buildValidatorFactory ();
    return factory.getValidator ();
}
 
Example 6
Project: sdcct   File: SdcctValidatorFactoryBean.java   View source code 5 votes vote down vote up
@Override
protected void postProcessConfiguration(Configuration<?> config) {
    this.config = config;

    if (this.paramNameProv == null) {
        this.paramNameProv = this.config.getDefaultParameterNameProvider();
    }
}
 
Example 7
Project: package-drone   File: ValidationBundle.java   View source code 5 votes vote down vote up
private static Validator buildValidator ()
{
    final GenericBootstrap bootstrap = Validation.byDefaultProvider ();
    bootstrap.providerResolver ( tracker );

    final Configuration<?> cfg = bootstrap.configure ();
    final OsgiMessageInterpolator mi = getMessageInterpolator ();
    mi.setFallback ( cfg.getDefaultMessageInterpolator () );
    cfg.messageInterpolator ( mi );

    final ValidatorFactory factory = cfg.buildValidatorFactory ();
    return factory.getValidator ();
}
 
Example 8
Project: ironjacamar   File: BeanValidationImpl.java   View source code 5 votes vote down vote up
/**
 * Create a validator factory
 * @return The factory
 */
static ValidatorFactory createValidatorFactory()
{
   Configuration configuration = Validation.byDefaultProvider().configure();
   Configuration<?> conf = configuration.traversableResolver(new IronJacamarTraversableResolver());

   return conf.buildValidatorFactory();
}
 
Example 9
Project: jaxrs-beanvalidation-javaee7   File: ValidationConfigurationContextResolver.java   View source code 5 votes vote down vote up
/**
 * Get a context of type {@code GeneralValidator} that is applicable to the supplied type.
 *
 * @param type the class of object for which a context is desired
 * @return a context for the supplied type or {@code null} if a context for the supplied type is not available from
 *         this provider.
 */
@Override
public GeneralValidator getContext(Class<?> type) {
    Configuration<?> config = Validation.byDefaultProvider().configure();
    BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();

    config.messageInterpolator(new LocaleSpecificMessageInterpolator(Validation.byDefaultProvider().configure()
            .getDefaultMessageInterpolator()));
    config.parameterNameProvider(new CustomParameterNameProvider());

    return new GeneralValidatorImpl(config.buildValidatorFactory(),
            bootstrapConfiguration.isExecutableValidationEnabled(),
            bootstrapConfiguration.getDefaultValidatedExecutableTypes());
}
 
Example 10
Project: tomee   File: ValidatorBuilder.java   View source code 5 votes vote down vote up
public static ValidatorFactory buildFactory(final ValidationInfo config, final ClassLoader classLoader) {
    ValidatorFactory factory = null;
    final Thread thread = Thread.currentThread();
    final ClassLoader oldContextLoader = thread.getContextClassLoader();
    try {
        thread.setContextClassLoader(classLoader);
        if (config == null) {
            factory = Validation.buildDefaultValidatorFactory();
        } else {
            final Configuration<?> configuration = getConfig(config);
            try {
                factory = configuration.buildValidatorFactory();
            } catch (final ValidationException ve) {
                thread.setContextClassLoader(ValidatorBuilder.class.getClassLoader());
                factory = Validation.buildDefaultValidatorFactory();
                thread.setContextClassLoader(classLoader);

                logger.warning("Unable create validator factory with config " + config
                    + " (" + ve.getMessage() + ")."
                    + " Default factory will be used.");
            }
        }
    } finally {
        thread.setContextClassLoader(oldContextLoader);
    }
    return factory;
}
 
Example 11
Project: sejda   File: DefaultValidationContext.java   View source code 5 votes vote down vote up
private DefaultValidationContext() {
    Configuration<?> validationConfig = Validation.byDefaultProvider().configure();
    if (new DefaultSejdaContext().isIgnoreXmlConfiguration()) {
        validationConfig.ignoreXmlConfiguration();
    }
    ValidatorFactory factory = validationConfig.buildValidatorFactory();
    validator = factory.getValidator();
}
 
Example 12
Project: morphia   File: ValidationExtension.java   View source code 5 votes vote down vote up
/**
 * Creates a ValidationExtension
 *
 * @param m the Morphia instance to use
 */
public ValidationExtension(final Morphia m) {
    final Configuration<?> configuration = Validation.byDefaultProvider().configure();
    validationFactory = configuration.buildValidatorFactory();

    m.getMapper().addInterceptor(this);
}
 
Example 13
Project: beanvalidation   File: SameTest.java   View source code 4 votes vote down vote up
@Before
public void setUp() {
	Configuration config = Validation.byDefaultProvider().configure();
	ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
	validator = factory.getValidator();
}
 
Example 14
Project: lams   File: LocalValidatorFactoryBean.java   View source code 4 votes vote down vote up
@Override
public void afterPropertiesSet() {
	@SuppressWarnings({"rawtypes", "unchecked"})
	Configuration<?> configuration = (this.providerClass != null ?
			Validation.byProvider(this.providerClass).configure() :
			Validation.byDefaultProvider().configure());

	MessageInterpolator targetInterpolator = this.messageInterpolator;
	if (targetInterpolator == null) {
		targetInterpolator = configuration.getDefaultMessageInterpolator();
	}
	configuration.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator));

	if (this.traversableResolver != null) {
		configuration.traversableResolver(this.traversableResolver);
	}

	ConstraintValidatorFactory targetConstraintValidatorFactory = this.constraintValidatorFactory;
	if (targetConstraintValidatorFactory == null && this.applicationContext != null) {
		targetConstraintValidatorFactory =
				new SpringConstraintValidatorFactory(this.applicationContext.getAutowireCapableBeanFactory());
	}
	if (targetConstraintValidatorFactory != null) {
		configuration.constraintValidatorFactory(targetConstraintValidatorFactory);
	}

	if (this.parameterNameDiscoverer != null) {
		configureParameterNameProviderIfPossible(configuration);
	}

	if (this.mappingLocations != null) {
		for (Resource location : this.mappingLocations) {
			try {
				configuration.addMapping(location.getInputStream());
			}
			catch (IOException ex) {
				throw new IllegalStateException("Cannot read mapping resource: " + location);
			}
		}
	}

	for (Map.Entry<String, String> entry : this.validationPropertyMap.entrySet()) {
		configuration.addProperty(entry.getKey(), entry.getValue());
	}

	// Allow for custom post-processing before we actually build the ValidatorFactory.
	postProcessConfiguration(configuration);

	this.validatorFactory = configuration.buildValidatorFactory();
	setTargetValidator(this.validatorFactory.getValidator());
}
 
Example 15
Project: my-spring-cache-redis   File: LocalValidatorFactoryBean.java   View source code 4 votes vote down vote up
@Override
public void afterPropertiesSet() {
	@SuppressWarnings({"rawtypes", "unchecked"})
	Configuration<?> configuration = (this.providerClass != null ?
			Validation.byProvider(this.providerClass).configure() :
			Validation.byDefaultProvider().configure());

	MessageInterpolator targetInterpolator = this.messageInterpolator;
	if (targetInterpolator == null) {
		targetInterpolator = configuration.getDefaultMessageInterpolator();
	}
	configuration.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator));

	if (this.traversableResolver != null) {
		configuration.traversableResolver(this.traversableResolver);
	}

	ConstraintValidatorFactory targetConstraintValidatorFactory = this.constraintValidatorFactory;
	if (targetConstraintValidatorFactory == null && this.applicationContext != null) {
		targetConstraintValidatorFactory =
				new SpringConstraintValidatorFactory(this.applicationContext.getAutowireCapableBeanFactory());
	}
	if (targetConstraintValidatorFactory != null) {
		configuration.constraintValidatorFactory(targetConstraintValidatorFactory);
	}

	if (this.parameterNameDiscoverer != null) {
		configureParameterNameProviderIfPossible(configuration);
	}

	if (this.mappingLocations != null) {
		for (Resource location : this.mappingLocations) {
			try {
				configuration.addMapping(location.getInputStream());
			}
			catch (IOException ex) {
				throw new IllegalStateException("Cannot read mapping resource: " + location);
			}
		}
	}

	for (Map.Entry<String, String> entry : this.validationPropertyMap.entrySet()) {
		configuration.addProperty(entry.getKey(), entry.getValue());
	}

	// Allow for custom post-processing before we actually build the ValidatorFactory.
	postProcessConfiguration(configuration);

	this.validatorFactory = configuration.buildValidatorFactory();
	setTargetValidator(this.validatorFactory.getValidator());
}
 
Example 16
Project: Camel   File: ValidatorFactories.java   View source code 4 votes vote down vote up
public static ValidatorFactory buildValidatorFactory(boolean osgi,
                                                     ValidationProviderResolver validationProviderResolver,
                                                     MessageInterpolator messageInterpolator,
                                                     TraversableResolver traversableResolver,
                                                     ConstraintValidatorFactory constraintValidatorFactory) {

    ValidationProviderResolver resolvedValidationProviderResolver =
            resolveValidationProviderResolver(osgi, validationProviderResolver);

    GenericBootstrap bootstrap = Validation.byDefaultProvider();
    if (resolvedValidationProviderResolver != null) {
        bootstrap.providerResolver(resolvedValidationProviderResolver);
    }
    Configuration<?> configuration = bootstrap.configure();

    if (messageInterpolator != null) {
        configuration.messageInterpolator(messageInterpolator);
    }

    if (traversableResolver != null) {
        configuration.traversableResolver(traversableResolver);
    }

    if (constraintValidatorFactory != null) {
        configuration.constraintValidatorFactory(constraintValidatorFactory);
    }

    return configuration.buildValidatorFactory();
}
 
Example 17
Project: lastaflute   File: ActionValidator.java   View source code 4 votes vote down vote up
protected ValidatorFactory buildValidatorFactory(VaConfigSetupper hibernateConfigSetupper) {
    final Configuration<?> configuration = createConfiguration();
    setupFrameworkConfiguration(configuration);
    setupYourConfiguration(configuration, hibernateConfigSetupper);
    return configuration.buildValidatorFactory();
}
 
Example 18
Project: lastaflute   File: ActionValidator.java   View source code 4 votes vote down vote up
protected void setupFrameworkConfiguration(Configuration<?> configuration) {
    configuration.messageInterpolator(newResourceBundleMessageInterpolator());
}
 
Example 19
Project: lastaflute   File: ActionValidator.java   View source code 4 votes vote down vote up
protected void setupYourConfiguration(Configuration<?> configuration, VaConfigSetupper hibernateConfigSetupper) {
    hibernateConfigSetupper.setup(configuration);
}
 
Example 20
Project: lastaflute   File: ActionValidator.java   View source code 4 votes vote down vote up
protected Configuration<?> createConfiguration() {
    return newGenericBootstrap().configure();
}
 
Example 21
Project: sdcct   File: SdcctValidatorFactoryBean.java   View source code 4 votes vote down vote up
public Configuration<?> getConfiguration() {
    return this.config;
}
 
Example 22
Project: ValidateFX   File: ValidatorFX.java   View source code 4 votes vote down vote up
public ValidatorFX(U controller) {
    this.controller = controller;
    Configuration<?> validationConf = Validation.byDefaultProvider().configure();
    validator = validationConf.buildValidatorFactory().getValidator();
}
 
Example 23
Project: dolphin-platform   File: SizePropertyValidatorTest.java   View source code 4 votes vote down vote up
@BeforeClass
public void setup() {
    Configuration<?> validationConf = Validation.byDefaultProvider().configure();
    validator = validationConf.buildValidatorFactory().getValidator();
}
 
Example 24
Project: gwt-bean-validators   File: GwtValidationProvider.java   View source code 4 votes vote down vote up
@Override
public Configuration<?> createGenericConfiguration(final BootstrapState state) {
  return new GwtConfiguration(this, state);
}
 
Example 25
Project: class-guard   File: LocalValidatorFactoryBean.java   View source code 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void afterPropertiesSet() {
	@SuppressWarnings("rawtypes")
	Configuration configuration = (this.providerClass != null ?
			Validation.byProvider(this.providerClass).configure() :
			Validation.byDefaultProvider().configure());

	MessageInterpolator targetInterpolator = this.messageInterpolator;
	if (targetInterpolator == null) {
		targetInterpolator = configuration.getDefaultMessageInterpolator();
	}
	configuration.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator));

	if (this.traversableResolver != null) {
		configuration.traversableResolver(this.traversableResolver);
	}

	ConstraintValidatorFactory targetConstraintValidatorFactory = this.constraintValidatorFactory;
	if (targetConstraintValidatorFactory == null && this.applicationContext != null) {
		targetConstraintValidatorFactory =
				new SpringConstraintValidatorFactory(this.applicationContext.getAutowireCapableBeanFactory());
	}
	if (targetConstraintValidatorFactory != null) {
		configuration.constraintValidatorFactory(targetConstraintValidatorFactory);
	}

	if (this.mappingLocations != null) {
		for (Resource location : this.mappingLocations) {
			try {
				configuration.addMapping(location.getInputStream());
			}
			catch (IOException ex) {
				throw new IllegalStateException("Cannot read mapping resource: " + location);
			}
		}
	}

	for (Map.Entry<String, String> entry : this.validationPropertyMap.entrySet()) {
		configuration.addProperty(entry.getKey(), entry.getValue());
	}

	// Allow for custom post-processing before we actually build the ValidatorFactory.
	postProcessConfiguration(configuration);

	this.validatorFactory = configuration.buildValidatorFactory();
	setTargetValidator(this.validatorFactory.getValidator());
}
 
Example 26
Project: cloudbreak   File: ImageCatalogBaseTest.java   View source code 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    Configuration<?> cfg = Validation.byDefaultProvider().configure();
    cfg.messageInterpolator(new ParameterMessageInterpolator());
    validator = cfg.buildValidatorFactory().getValidator();
}
 
Example 27
Project: hibernate-demos   File: AbstractValidationTest.java   View source code 4 votes vote down vote up
@Before
public void setUp() {
	final Configuration<HibernateValidatorConfiguration> configuration = Validation.byProvider( HibernateValidator.class ).configure();
	validator = configuration.buildValidatorFactory().getValidator();
}
 
Example 28
Project: hibernate-demos   File: AbstractValidationTest.java   View source code 4 votes vote down vote up
@Before
public void setUp() {
	final Configuration<HibernateValidatorConfiguration> configuration = Validation.byProvider( HibernateValidator.class ).configure();
	validator = configuration.buildValidatorFactory().getValidator();
}
 
Example 29
Project: tomee   File: ValidatorBuilder.java   View source code 4 votes vote down vote up
public OpenEjbConfig(final BootstrapConfiguration bootstrapConfig, final Configuration<T> target) {
    bootstrap = bootstrapConfig;
    delegate = target;
}
 
Example 30
Project: sejda   File: TestUtils.java   View source code 4 votes vote down vote up
private ValidatorHolder() {
    Configuration<?> validationConfig = Validation.byDefaultProvider().configure();
    validationConfig.ignoreXmlConfiguration();
    ValidatorFactory factory = validationConfig.buildValidatorFactory();
    validator = factory.getValidator();
}
 
Example 31
Project: gwt-bean-validators   File: Validation.java   View source code 3 votes vote down vote up
/**
 * Unsupported. Always throws an {@link UnsupportedOperationException}.
 *
 * @param providerType
 *
 * @throws UnsupportedOperationException not supported
 */
public static <T extends Configuration<T>, U extends ValidationProvider<T>> //
    ProviderSpecificBootstrap<T> //
    byProvider(final Class<U> providerType) {
  throw new UnsupportedOperationException(
      "GWT Validation does not support custom validator " + "providers");
}
 
Example 32
Project: lams   File: LocalValidatorFactoryBean.java   View source code 2 votes vote down vote up
/**
 * Post-process the given Bean Validation configuration,
 * adding to or overriding any of its settings.
 * <p>Invoked right before building the {@link ValidatorFactory}.
 * @param configuration the Configuration object, pre-populated with
 * settings driven by LocalValidatorFactoryBean's properties
 */
protected void postProcessConfiguration(Configuration<?> configuration) {
}
 
Example 33
Project: spring4-understanding   File: LocalValidatorFactoryBean.java   View source code 2 votes vote down vote up
/**
 * Post-process the given Bean Validation configuration,
 * adding to or overriding any of its settings.
 * <p>Invoked right before building the {@link ValidatorFactory}.
 * @param configuration the Configuration object, pre-populated with
 * settings driven by LocalValidatorFactoryBean's properties
 */
protected void postProcessConfiguration(Configuration<?> configuration) {
}
 
Example 34
Project: my-spring-cache-redis   File: LocalValidatorFactoryBean.java   View source code 2 votes vote down vote up
/**
 * Post-process the given Bean Validation configuration,
 * adding to or overriding any of its settings.
 * <p>Invoked right before building the {@link ValidatorFactory}.
 * @param configuration the Configuration object, pre-populated with
 * settings driven by LocalValidatorFactoryBean's properties
 */
protected void postProcessConfiguration(Configuration<?> configuration) {
}
 
Example 35
Project: spring   File: LocalValidatorFactoryBean.java   View source code 2 votes vote down vote up
/**
 * Post-process the given Bean Validation configuration,
 * adding to or overriding any of its settings.
 * <p>Invoked right before building the {@link ValidatorFactory}.
 * @param configuration the Configuration object, pre-populated with
 * settings driven by LocalValidatorFactoryBean's properties
 */
protected void postProcessConfiguration(Configuration<?> configuration) {
}
 
Example 36
Project: lastaflute   File: VaConfigSetupper.java   View source code 2 votes vote down vote up
/**
 * @param conf The configuration of hibernate validator. (NotNull)
 */
void setup(Configuration<?> conf);
 
Example 37
Project: class-guard   File: LocalValidatorFactoryBean.java   View source code 2 votes vote down vote up
/**
 * Post-process the given Bean Validation configuration,
 * adding to or overriding any of its settings.
 * <p>Invoked right before building the {@link ValidatorFactory}.
 * @param configuration the Configuration object, pre-populated with
 * settings driven by LocalValidatorFactoryBean's properties
 */
protected void postProcessConfiguration(Configuration configuration) {
}