Java 类javax.validation.ConstraintValidatorFactory 实例源码

项目:nest-old    文件:ValidatorFactoryImpl513.java   
/**
 * create validator
 * 
 * @param constraintValidatorFactory
 * @param messageInterpolator
 * @param traversableResolver
 * @param parameterNameProvider
 * @param failFast
 * @param validatedValueHandlers
 * @return
 */
protected Validator createValidator(ConstraintValidatorFactory constraintValidatorFactory,
        MessageInterpolator messageInterpolator, TraversableResolver traversableResolver,
        ParameterNameProvider parameterNameProvider, boolean failFast,
        List<ValidatedValueUnwrapper<?>> validatedValueHandlers) {
    BeanMetaDataManager513 beanMetaDataManager;
    if (!beanMetaDataManagerMap.containsKey(parameterNameProvider)) {
        beanMetaDataManager = new BeanMetaDataManager513(constraintHelper, executableHelper, parameterNameProvider,
                buildDataProviders(parameterNameProvider));
        beanMetaDataManagerMap.put(parameterNameProvider, beanMetaDataManager);
    } else {
        beanMetaDataManager = beanMetaDataManagerMap.get(parameterNameProvider);
    }

    return new ValidatorImpl(constraintValidatorFactory, messageInterpolator, traversableResolver,
            beanMetaDataManager, parameterNameProvider, typeResolutionHelper, validatedValueHandlers,
            constraintValidatorManager, failFast);
}
项目:Camel    文件:ValidatorFactories.java   
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();
}
项目:nexus-public    文件:ValidationModule.java   
@Provides
@Singleton
ValidatorFactory validatorFactory(ConstraintValidatorFactory constraintValidatorFactory) {
  ClassLoader tccl = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(HibernateValidator.class.getClassLoader());

    ValidatorFactory factory = Validation.byDefaultProvider().configure()
        .constraintValidatorFactory(constraintValidatorFactory)
        .parameterNameProvider(new AopAwareParanamerParameterNameProvider())
        .traversableResolver(new AlwaysTraversableResolver())
        .buildValidatorFactory();

    // FIXME: Install custom MessageInterpolator that can properly find/merge ValidationMessages.properties for bundles

    // exercise interpolator to preload elements (avoids issues later when TCCL might be different)
    factory.getValidator().validate(new Object()
    {
      // minimal token message
      @NotNull(message = "${0}")
      String empty;
    });

    return factory;
  }
  finally {
    Thread.currentThread().setContextClassLoader(tccl);
  }
}
项目:gwt-bean-validators    文件:GwtValidatorContext.java   
@Override
public ValidatorContext constraintValidatorFactory(
    final ConstraintValidatorFactory constraintValidatorfactory) {
  if (constraintValidatorfactory == null) {
    this.constraintValidatorfactoryEntry = this.factoryConstraintValidatorfactory;
  } else {
    this.constraintValidatorfactoryEntry = constraintValidatorfactory;
  }
  return this;
}
项目:InSpider    文件:ValidCollectionValidator.java   
@Override
public boolean isValid(List<?> entries,
        ConstraintValidatorContext context) {
    boolean valid = true;

    if(entries == null){
        return valid;
    }

    if(ArrayUtils.getLength(constraints) != ArrayUtils.getLength(messages)){
        throw new ConstraintDeclarationException("Number of messages must be the same as number of constraints");
    }

    ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
    ConstraintValidatorFactory constraintValidatorFactory = validatorFactory.getConstraintValidatorFactory();

    for(Object element : entries) {
        for(Class<?> constraint : constraints) {
            Constraint constraintAnnotation = constraint.getAnnotation(Constraint.class);
            Class<? extends ConstraintValidator<?, ?>>[] constraintValidators = constraintAnnotation.validatedBy();
            for (int i = 0; i < constraintValidators.length; i++) {
                ConstraintValidator constraintValidator = constraintValidatorFactory.getInstance(constraintValidators[i]);
                if(!constraintValidator.isValid(element, context)){
                    context.buildConstraintViolationWithTemplate(messages[i]).addConstraintViolation().disableDefaultConstraintViolation();
                    valid = false;
                }
            }
        }

    }

    return valid;
}
项目:lams    文件:LocalValidatorFactoryBean.java   
@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());
}
项目:lams    文件:LocalValidatorFactoryBean.java   
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    Assert.notNull(this.validatorFactory, "No target ValidatorFactory set");
    return this.validatorFactory.getConstraintValidatorFactory();
}
项目:minijax    文件:MinijaxValidatorContext.java   
@Override
public MinijaxValidatorContext constraintValidatorFactory(final ConstraintValidatorFactory factory) {
    return this;
}
项目:minijax    文件:MinijaxValidatorFactory.java   
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    throw new UnsupportedOperationException();
}
项目:minijax    文件:MinijaxValidationProvider.java   
@Override
public ConstraintValidatorFactory getDefaultConstraintValidatorFactory() {
    throw new UnsupportedOperationException();
}
项目:spring4-understanding    文件:LocalValidatorFactoryBean.java   
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    Assert.notNull(this.validatorFactory, "No target ValidatorFactory set");
    return this.validatorFactory.getConstraintValidatorFactory();
}
项目:my-spring-cache-redis    文件:LocalValidatorFactoryBean.java   
@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());
}
项目:my-spring-cache-redis    文件:LocalValidatorFactoryBean.java   
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    Assert.notNull(this.validatorFactory, "No target ValidatorFactory set");
    return this.validatorFactory.getConstraintValidatorFactory();
}
项目:spring    文件:LocalValidatorFactoryBean.java   
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    Assert.notNull(this.validatorFactory, "No target ValidatorFactory set");
    return this.validatorFactory.getConstraintValidatorFactory();
}
项目:Camel    文件:BeanValidatorEndpoint.java   
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    return constraintValidatorFactory;
}
项目:Camel    文件:BeanValidatorEndpoint.java   
/**
 * To use a custom {@link ConstraintValidatorFactory}
 */
public void setConstraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory) {
    this.constraintValidatorFactory = constraintValidatorFactory;
}
项目:nexus-public    文件:ValidationModule.java   
@Override
protected void configure() {
  final MethodInterceptor interceptor = new ValidationInterceptor();
  bindInterceptor(Matchers.any(), Matchers.annotatedWith(Validate.class), interceptor);
  requestInjection(interceptor);
  bind(ConstraintValidatorFactory.class).to(GuiceConstraintValidatorFactory.class);
}
项目:gwt-bean-validators    文件:AbstractBaseConfigurationState.java   
/**
 * constructor.
 */
public AbstractBaseConfigurationState(final ConstraintValidatorFactory constraintValidatorFactory,
    final MessageInterpolator messageInterpolator, final Map<String, String> properties,
    final TraversableResolver traversableResolver) {
  this.constraintValidatorFactory = constraintValidatorFactory;
  this.messageInterpolator = messageInterpolator;
  this.properties = Collections.unmodifiableMap(properties);
  this.traversableResolver = traversableResolver;
}
项目:gwt-bean-validators    文件:AbstractBaseConfigurationState.java   
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
  return this.constraintValidatorFactory;
}
项目:gwt-bean-validators    文件:GwtConfigurationState.java   
public GwtConfigurationState(final ConstraintValidatorFactory constraintValidatorFactory,
    final MessageInterpolator messageInterpolator, final Map<String, String> properties,
    final TraversableResolver traversableResolver) {
  super(constraintValidatorFactory, messageInterpolator, properties, traversableResolver);
}
项目:gwt-bean-validators    文件:GwtConstraintValidatorFactory.java   
/**
 * Always throws {@link UnsupportedOperationException}.
 *
 * @throws UnsupportedOperationException unsupported on gwt
 */
@Override
public <T extends ConstraintValidator<?, ?>> T getInstance(final Class<T> key) {
  throw new UnsupportedOperationException("GWT does not support "
      + ConstraintValidatorFactory.class.getName() + " use GWT.create instead");
}
项目:gwt-bean-validators    文件:AbstractGwtValidator.java   
/**
 * initialize values.
 *
 * @param factory constraint validator factory to set
 * @param messageInterpolator message interpolator to set
 * @param traversableResolver traversable resolver to set
 * @param pparameterNameProvider parameter resolver to set
 */
public void init(final ConstraintValidatorFactory factory,
    final MessageInterpolator messageInterpolator, final TraversableResolver traversableResolver,
    final ParameterNameProvider pparameterNameProvider) {
  this.contraintValidatorFactory = factory;
  this.messageInterpolator = messageInterpolator;
  this.traversableResolver = traversableResolver;
  this.parameterNameProvider = pparameterNameProvider;
}
项目:gwt-bean-validators    文件:AbstractGwtValidator.java   
protected ConstraintValidatorFactory getConstraintValidatorFactory() {
  return this.contraintValidatorFactory;
}
项目:gwt-bean-validators    文件:AbstractBaseGwtConfiguration.java   
@Override
public final ConstraintValidatorFactory getDefaultConstraintValidatorFactory() {
  return GWT.create(ConstraintValidatorFactory.class);
}
项目:gwt-bean-validators    文件:AbstractGwtValidatorFactory.java   
/**
 * GWT does not support {@link ConstraintValidatorFactory}, so the object returned by this method
 * will not work.
 */
@Override
public final ConstraintValidatorFactory getConstraintValidatorFactory() {
  return this.constraintValidatorFactory;
}
项目:gwt-bean-validators    文件:AbstractGwtValidatorFactory.java   
/**
 * initialize factory.
 *
 * @param configState ConfigurationState
 */
public final void init(final ConfigurationState configState) {
  final ConstraintValidatorFactory configConstraintValidatorFactory =
      configState.getConstraintValidatorFactory();
  this.constraintValidatorFactory = configConstraintValidatorFactory == null
      ? GWT.<ConstraintValidatorFactory>create(ConstraintValidatorFactory.class)
      : configConstraintValidatorFactory;
  final TraversableResolver configTraversableResolver = configState.getTraversableResolver();
  this.traversableResolver = configTraversableResolver == null ? new DefaultTraversableResolver()
      : configTraversableResolver;
  final MessageInterpolator configMessageInterpolator = configState.getMessageInterpolator();
  this.messageInterpolator = configMessageInterpolator == null ? new GwtMessageInterpolator()
      : configMessageInterpolator;
  this.parameterNameProvider = configState.getParameterNameProvider();
}
项目:gwt-bean-validators    文件:GwtConfigurationState.java   
public GwtConfigurationState(final ConstraintValidatorFactory pconstraintValidatorFactory,
    final MessageInterpolator pmessageInterpolator, final Map<String, String> pproperties,
    final TraversableResolver ptraversableResolver) {
  super(pconstraintValidatorFactory, pmessageInterpolator, pproperties, ptraversableResolver);
}
项目:gwt-bean-validators    文件:GwtConfigurationState.java   
public GwtConfigurationState(final ConstraintValidatorFactory pconstraintValidatorFactory,
    final MessageInterpolator pmessageInterpolator, final Map<String, String> pproperties,
    final TraversableResolver ptraversableResolver) {
  super(pconstraintValidatorFactory, pmessageInterpolator, pproperties, ptraversableResolver);
}
项目:nest-old    文件:ValidatorFactoryImpl513.java   
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    return constraintValidatorManager.getDefaultConstraintValidatorFactory();
}
项目:nest-old    文件:ValidatorContextImpl513.java   
@Override
public HibernateValidatorContext constraintValidatorFactory(ConstraintValidatorFactory factory) {
    if (factory == null) {
        this.constraintValidatorFactory = validatorFactory.getConstraintValidatorFactory();
    } else {
        this.constraintValidatorFactory = factory;
    }
    return this;
}
项目:class-guard    文件:LocalValidatorFactoryBean.java   
@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());
}
项目:class-guard    文件:LocalValidatorFactoryBean.java   
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    return this.validatorFactory.getConstraintValidatorFactory();
}
项目:ironjacamar    文件:SerializableValidatorFactory.java   
/**
 * {@inheritDoc}
 */
public ConstraintValidatorFactory getConstraintValidatorFactory()
{
   return validatorFactory.getConstraintValidatorFactory();
}
项目:ironjacamar    文件:IronJacamarValidatorFactory.java   
/**
 * {@inheritDoc}
 */
public ConstraintValidatorFactory getConstraintValidatorFactory()
{
   return validatorFactory.getConstraintValidatorFactory();
}
项目:tomee    文件:ValidatorFactoryWrapper.java   
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    return factory().getConstraintValidatorFactory();
}
项目:tomee    文件:SingleValidatorFactoryWrapper.java   
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    return factory().getConstraintValidatorFactory();
}
项目:tomee    文件:ValidatorBuilder.java   
@Override
public ConstraintValidatorFactory getDefaultConstraintValidatorFactory() {
    return delegate.getDefaultConstraintValidatorFactory();
}
项目:tomee    文件:ValidatorBuilder.java   
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    return delegate().getConstraintValidatorFactory();
}
项目:tomee    文件:CustomValidatorProvider.java   
@Override
public ConstraintValidatorFactory getDefaultConstraintValidatorFactory() {
    return null;
}
项目:tomee    文件:CustomValidatorProvider.java   
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    return null;
}