当前位置: 首页>>代码示例>>Java>>正文


Java ConstraintValidatorFactory类代码示例

本文整理汇总了Java中javax.validation.ConstraintValidatorFactory的典型用法代码示例。如果您正苦于以下问题:Java ConstraintValidatorFactory类的具体用法?Java ConstraintValidatorFactory怎么用?Java ConstraintValidatorFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConstraintValidatorFactory类属于javax.validation包,在下文中一共展示了ConstraintValidatorFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createValidator

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:bradwoo8621,项目名称:nest-old,代码行数:29,代码来源:ValidatorFactoryImpl513.java

示例2: isValid

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
@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;
}
 
开发者ID:CDS-INSPIRE,项目名称:InSpider,代码行数:34,代码来源:ValidCollectionValidator.java

示例3: afterPropertiesSet

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
@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());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:52,代码来源:LocalValidatorFactoryBean.java

示例4: getConstraintValidatorFactory

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
	Assert.notNull(this.validatorFactory, "No target ValidatorFactory set");
	return this.validatorFactory.getConstraintValidatorFactory();
}
 
开发者ID:panguixiang,项目名称:my-spring-cache-redis,代码行数:6,代码来源:LocalValidatorFactoryBean.java

示例5: getConstraintValidatorFactory

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
public ConstraintValidatorFactory getConstraintValidatorFactory() {
    return constraintValidatorFactory;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:BeanValidatorEndpoint.java

示例6: setConstraintValidatorFactory

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
/**
 * To use a custom {@link ConstraintValidatorFactory}
 */
public void setConstraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory) {
    this.constraintValidatorFactory = constraintValidatorFactory;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:7,代码来源:BeanValidatorEndpoint.java

示例7: buildValidatorFactory

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:30,代码来源:ValidatorFactories.java

示例8: configure

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
@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);
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:8,代码来源:ValidationModule.java

示例9: validatorFactory

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:30,代码来源:ValidationModule.java

示例10: AbstractBaseConfigurationState

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:12,代码来源:AbstractBaseConfigurationState.java

示例11: getConstraintValidatorFactory

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
@Override
public ConstraintValidatorFactory getConstraintValidatorFactory() {
  return this.constraintValidatorFactory;
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:5,代码来源:AbstractBaseConfigurationState.java

示例12: GwtConfigurationState

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
public GwtConfigurationState(final ConstraintValidatorFactory constraintValidatorFactory,
    final MessageInterpolator messageInterpolator, final Map<String, String> properties,
    final TraversableResolver traversableResolver) {
  super(constraintValidatorFactory, messageInterpolator, properties, traversableResolver);
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:6,代码来源:GwtConfigurationState.java

示例13: getInstance

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
/**
 * 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");
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:11,代码来源:GwtConstraintValidatorFactory.java

示例14: constraintValidatorFactory

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
@Override
public ValidatorContext constraintValidatorFactory(
    final ConstraintValidatorFactory constraintValidatorfactory) {
  if (constraintValidatorfactory == null) {
    this.constraintValidatorfactoryEntry = this.factoryConstraintValidatorfactory;
  } else {
    this.constraintValidatorfactoryEntry = constraintValidatorfactory;
  }
  return this;
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:11,代码来源:GwtValidatorContext.java

示例15: init

import javax.validation.ConstraintValidatorFactory; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:17,代码来源:AbstractGwtValidator.java


注:本文中的javax.validation.ConstraintValidatorFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。