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


Java PropertyDescriptor.getConstraintDescriptors方法代码示例

本文整理汇总了Java中javax.validation.metadata.PropertyDescriptor.getConstraintDescriptors方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyDescriptor.getConstraintDescriptors方法的具体用法?Java PropertyDescriptor.getConstraintDescriptors怎么用?Java PropertyDescriptor.getConstraintDescriptors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.validation.metadata.PropertyDescriptor的用法示例。


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

示例1: describe

import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
/**
 * Return the validation descriptors of given bean.
 * 
 * @param className
 *            the class to describe.
 * @return the validation descriptors of given bean.
 * @throws ClassNotFoundException
 *             when the bean is not found.
 */
@GET
public Map<String, List<String>> describe(final String className) throws ClassNotFoundException {
	final Class<?> beanClass = Class.forName(className);
	final Map<String, List<String>> result = new HashMap<>();
	for (final PropertyDescriptor property : validator.getValidator().getConstraintsForClass(beanClass).getConstrainedProperties()) {
		final List<String> list = new ArrayList<>();
		result.put(property.getPropertyName(), list);
		for (final ConstraintDescriptor<?> constraint : property.getConstraintDescriptors()) {
			// Since constraints are annotation, get the annotation class (interface)
			list.add(constraint.getAnnotation().getClass().getInterfaces()[0].getName());
		}
	}

	return result;
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:25,代码来源:ValidationResource.java

示例2: isPropertyConstrained

import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
private boolean isPropertyConstrained(final PropertyDescriptor ppropertyDescription,
    final boolean useField) {
  // cascaded counts as constrained
  // we must know if the @Valid annotation is on a field or a getter
  final JClassType jClass = this.beanHelper.getJClass();
  if (useField && jClass.findField(ppropertyDescription.getPropertyName())
      .isAnnotationPresent(Valid.class)) {
    return true;
  } else if (!useField && jClass.findMethod(asGetter(ppropertyDescription), NO_ARGS)
      .isAnnotationPresent(Valid.class)) {
    return true;
  }
  // for non-cascaded properties
  for (final ConstraintDescriptor<?> constraint : ppropertyDescription
      .getConstraintDescriptors()) {
    final org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl<?> constraintHibernate =
        (org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl<?>) constraint;
    if (constraintHibernate
        .getElementType() == (useField ? ElementType.FIELD : ElementType.METHOD)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:25,代码来源:GwtSpecificValidatorCreator.java

示例3: validatePropertyConstraints

import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private <T> void validatePropertyConstraints(
        final MinijaxConstraintValidatorContext<T> context,
        final PropertyDescriptor property,
        final Object value) {

    for (final ConstraintDescriptor constraint : property.getConstraintDescriptors()) {
        final ConstraintValidator validator = ((MinijaxConstraintDescriptor) constraint).getValidator();
        if (!validator.isValid(value, context)) {
            context.buildViolation(constraint, value);
        }
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:14,代码来源:MinijaxValidator.java

示例4: collectConstraints

import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
private void collectConstraints(List<Constraint> constraints,
        PropertyDescriptor propertyDescriptor) {
    for (ConstraintDescriptor<?> constraintDescriptor : propertyDescriptor
            .getConstraintDescriptors()) {
        constraints.add(new Constraint(constraintDescriptor.getAnnotation()
                .annotationType()
                .getName(), constraintDescriptor.getAttributes()));
    }
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:10,代码来源:ValidatorConstraintResolver.java

示例5: constrainteByAnnotationType

import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
private Map<Class<? extends Annotation>, ConstraintDescriptor<?>> constrainteByAnnotationType(
        PropertyDescriptor propertyDescriptor) {
    Map<Class<? extends Annotation>, ConstraintDescriptor<?>> annotationMap = new HashMap<Class<? extends Annotation>, ConstraintDescriptor<?>>();
    Set<ConstraintDescriptor<?>> constraintDescriptors = propertyDescriptor.getConstraintDescriptors();
    for (ConstraintDescriptor<?> constraintDescriptor : constraintDescriptors) {
        annotationMap.put(constraintDescriptor.getAnnotation().annotationType(), constraintDescriptor);
    }
    return annotationMap;
}
 
开发者ID:arey,项目名称:spring-mvc-toolkit,代码行数:10,代码来源:Html5InputTag.java

示例6: getConstraintDescriptors

import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
@Override
public Set<ConstraintDescriptor<?>> getConstraintDescriptors(final Object keyObj) {
	String key = String.valueOf(keyObj);
	final Validator validator = Validation.byDefaultProvider().configure().buildValidatorFactory().getValidator();

	BeanDescriptor beanDesc = validator.getConstraintsForClass(getClass());
	for(PropertyDescriptor prop : beanDesc.getConstrainedProperties()) {
		if(prop.getPropertyName().equalsIgnoreCase(key)) {
			return prop.getConstraintDescriptors();
		}
	}
	return new HashSet<ConstraintDescriptor<?>>();
}
 
开发者ID:jesse-gallagher,项目名称:XPages-Scaffolding,代码行数:14,代码来源:AbstractModelObject.java

示例7: writePropertyDescriptor

import javax.validation.metadata.PropertyDescriptor; //导入方法依赖的package包/类
private void writePropertyDescriptor(final SourceWriter sw,
    final PropertyDescriptor ppropertyDescription) {
  // private final PropertyDescriptor myProperty_pd =
  sw.print("private final ");
  sw.print(PropertyDescriptorImpl.class.getCanonicalName());
  sw.print(" ");
  sw.print(ppropertyDescription.getPropertyName());
  sw.println("_pd =");
  sw.indent();
  sw.indent();

  // new PropertyDescriptorImpl(
  sw.println("new " + PropertyDescriptorImpl.class.getCanonicalName() + "(");
  sw.indent();
  sw.indent();

  // "myProperty",
  sw.println("\"" + ppropertyDescription.getPropertyName() + "\",");

  // MyType.class,
  sw.println(ppropertyDescription.getElementClass().getCanonicalName() + ".class,");

  // isCascaded,
  sw.print(Boolean.toString(ppropertyDescription.isCascaded()) + ",");

  // beanMetadata,
  sw.print("beanMetadata");

  // myProperty_c0,
  // myProperty_c1 );
  int count = 0;
  for (final ConstraintDescriptor<?> constraint : ppropertyDescription
      .getConstraintDescriptors()) {
    if (this.areConstraintDescriptorGroupsValid(constraint)) {
      sw.println(","); // Print the , for the previous line
      sw.print(this.constraintDescriptorVar(ppropertyDescription.getPropertyName(), count));
      count++;
    }
  }
  sw.println(");");

  sw.outdent();
  sw.outdent();
  sw.outdent();
  sw.outdent();
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:47,代码来源:GwtSpecificValidatorCreator.java


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