• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PropertyDescriptor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: resolveForProperty

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
@Override
public List<Constraint> resolveForProperty(String property, Class<?> clazz) {
    List<Constraint> constraints = new ArrayList<>();

    String[] properties = property.split("\\.");
    Class<?> clazzforLoop = clazz;
    for (int i = 0; i < properties.length; i++) {
        String propertyForLoop = properties[i];
        propertyForLoop = propertyForLoop.replace("[]", "");

        BeanDescriptor beanDescriptor = this.validator.getConstraintsForClass(clazzforLoop);
        PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty(
                propertyForLoop);
        if (propertyDescriptor != null) {
            if (isLastElement(properties, i)) {
                collectConstraints(constraints, propertyDescriptor);
            }
            clazzforLoop = getFollowUpClass(propertyDescriptor, clazzforLoop);
        } else {
            break;
        }
    }
    return constraints;
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:25,代码来源:ValidatorConstraintResolver.java


示例2: 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


示例3: getAnnotation

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
private Annotation getAnnotation(final PropertyDescriptor ppropertyDescription,
    final boolean useField, final Class<? extends Annotation> expectedAnnotationClass) {
  Annotation annotation = null;
  if (useField) {
    final JField field = this.beanType.findField(ppropertyDescription.getPropertyName());
    if (field.getEnclosingType().equals(this.beanType)) {
      annotation = field.getAnnotation(expectedAnnotationClass);
    }
  } else {
    final JMethod method = this.beanType.findMethod(asGetter(ppropertyDescription), NO_ARGS);
    if (method.getEnclosingType().equals(this.beanType)) {
      annotation = method.getAnnotation(expectedAnnotationClass);
    }
  }
  return annotation;
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:17,代码来源:GwtSpecificValidatorCreator.java


示例4: 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


示例5: writeValidateAllNonInheritedProperties

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
private void writeValidateAllNonInheritedProperties(final SourceWriter sw) {
  // private <T> void validateAllNonInheritedProperties(
  sw.println("private <T> void validateAllNonInheritedProperties(");
  sw.indent();
  sw.indent();

  // GwtValidationContext<T> context, BeanType object,
  // Set<ConstraintViolation<T>> violations, Class<?>... groups) {
  sw.println("GwtValidationContext<T> context,");
  sw.println(this.beanHelper.getTypeCanonicalName() + " object,");
  sw.println("Set<ConstraintViolation<T>> violations,");
  sw.println("Class<?>... groups) {");
  sw.outdent();

  for (final PropertyDescriptor p : this.beanHelper.getBeanDescriptor()
      .getConstrainedProperties()) {
    this.writeValidatePropertyCall(sw, p, false, true);
  }

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


示例6: getAssociationType

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
/**
 * get association type.
 *
 * @param ppropertyDescriptor property description
 * @param puseField use field
 * @return JClassType
 */
public JClassType getAssociationType(final PropertyDescriptor ppropertyDescriptor,
    final boolean puseField) {
  final JType type = this.getElementType(ppropertyDescriptor, puseField);
  if (type == null) {
    return null;
  }
  final JArrayType jarray = type.isArray();
  if (jarray != null) {
    return jarray.getComponentType().isClassOrInterface();
  }
  final JParameterizedType jptype = type.isParameterized();
  JClassType[] typeArgs;
  if (jptype == null) {
    final JRawType jrtype = type.isRawType();
    typeArgs = jrtype.getGenericType().getTypeParameters();
  } else {
    typeArgs = jptype.getTypeArgs();
  }
  // it is either a Iterable or a Map use the last type arg.
  return typeArgs[typeArgs.length - 1].isClassOrInterface();
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:29,代码来源:BeanHelper.java


示例7: getElementType

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
JType getElementType(final PropertyDescriptor ppropertyDescriptor, final boolean puseField) {
  if (puseField) {
    final JField field =
        this.findRecursiveField(this.jclass, ppropertyDescriptor.getPropertyName());
    if (field == null) {
      return null;
    }
    return field.getType();
  } else {
    final JMethod method = this.findRecursiveMethod(this.jclass,
        GwtSpecificValidatorCreator.asGetter(ppropertyDescriptor),
        GwtSpecificValidatorCreator.NO_ARGS);
    if (method == null) {
      return null;
    }
    return method.getReturnType();
  }
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:19,代码来源:BeanHelper.java


示例8: getPropertyDescriptor

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
/**
 * @return PropertyDescriptor may be null when JavaBean do not have any Bean Validation
 *         annotations.
 */
private PropertyDescriptor getPropertyDescriptor() throws JspException {
    String path = getBindStatus().getPath();
    int dotPos = path.indexOf('.');
    if (dotPos == -1) {
        return null;
    }
    String beanName = path.substring(0, dotPos);
    String expression = path.substring(dotPos + 1);

    Map<String, Object> model = getRequestContext().getModel();
    Object bean = getBean(beanName, model);

    Validator validator = getRequestContext().getWebApplicationContext().getBean(Validator.class);
    BeanDescriptor constraints = validator.getConstraintsForClass(bean.getClass());
    return constraints.getConstraintsForProperty(expression);
}
 
开发者ID:arey,项目名称:spring-mvc-toolkit,代码行数:21,代码来源:Html5InputTag.java


示例9: applyDDL

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
private static void applyDDL(
		String prefix,
		PersistentClass persistentClass,
		Class<?> clazz,
		ValidatorFactory factory,
		Set<Class<?>> groups,
		boolean activateNotNull,
		Dialect dialect) {
	final BeanDescriptor descriptor = factory.getValidator().getConstraintsForClass( clazz );
	//no bean level constraints can be applied, go to the properties

	for ( PropertyDescriptor propertyDesc : descriptor.getConstrainedProperties() ) {
		Property property = findPropertyByName( persistentClass, prefix + propertyDesc.getPropertyName() );
		boolean hasNotNull;
		if ( property != null ) {
			hasNotNull = applyConstraints(
					propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull, dialect
			);
			if ( property.isComposite() && propertyDesc.isCascaded() ) {
				Class<?> componentClass = ( (Component) property.getValue() ).getComponentClass();

				/*
				 * we can apply not null if the upper component let's us activate not null
				 * and if the property is not null.
				 * Otherwise, all sub columns should be left nullable
				 */
				final boolean canSetNotNullOnColumns = activateNotNull && hasNotNull;
				applyDDL(
						prefix + propertyDesc.getPropertyName() + ".",
						persistentClass, componentClass, factory, groups,
						canSetNotNullOnColumns,
                           dialect
				);
			}
			//FIXME add collection of components
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:TypeSafeActivator.java


示例10: applyConstraints

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
private static boolean applyConstraints(
		Set<ConstraintDescriptor<?>> constraintDescriptors,
		Property property,
		PropertyDescriptor propertyDesc,
		Set<Class<?>> groups,
		boolean canApplyNotNull,
		Dialect dialect) {
	boolean hasNotNull = false;
	for ( ConstraintDescriptor<?> descriptor : constraintDescriptors ) {
		if ( groups != null && Collections.disjoint( descriptor.getGroups(), groups ) ) {
			continue;
		}

		if ( canApplyNotNull ) {
			hasNotNull = hasNotNull || applyNotNull( property, descriptor );
		}

		// apply bean validation specific constraints
		applyDigits( property, descriptor );
		applySize( property, descriptor, propertyDesc );
		applyMin( property, descriptor, dialect );
		applyMax( property, descriptor, dialect );

		// apply hibernate validator specific constraints - we cannot import any HV specific classes though!
		// no need to check explicitly for @Range. @Range is a composed constraint using @Min and @Max which
		// will be taken care later
		applyLength( property, descriptor, propertyDesc );

		// pass an empty set as composing constraints inherit the main constraint and thus are matching already
		hasNotNull = hasNotNull || applyConstraints(
				descriptor.getComposingConstraints(),
				property, propertyDesc, null,
				canApplyNotNull,
                   dialect
		);
	}
	return hasNotNull;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:TypeSafeActivator.java


示例11: applySize

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
	if ( Size.class.equals( descriptor.getAnnotation().annotationType() )
			&& String.class.equals( propertyDescriptor.getElementClass() ) ) {
		@SuppressWarnings("unchecked")
		ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor;
		int max = sizeConstraint.getAnnotation().max();
		Column col = (Column) property.getColumnIterator().next();
		if ( max < Integer.MAX_VALUE ) {
			col.setLength( max );
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:TypeSafeActivator.java


示例12: applyLength

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
private static void applyLength(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
	if ( "org.hibernate.validator.constraints.Length".equals(
			descriptor.getAnnotation().annotationType().getName()
	)
			&& String.class.equals( propertyDescriptor.getElementClass() ) ) {
		@SuppressWarnings("unchecked")
		int max = (Integer) descriptor.getAttributes().get( "max" );
		Column col = (Column) property.getColumnIterator().next();
		if ( max < Integer.MAX_VALUE ) {
			col.setLength( max );
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:TypeSafeActivator.java


示例13: validate

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
@Override
public <T> Set<ConstraintViolation<T>> validate(final T object, final Class<?>... groups) {
    final MinijaxConstraintValidatorContext<T> context = new MinijaxConstraintValidatorContext<>(object);
    final BeanDescriptor descriptor = getConstraintsForClass(object.getClass());

    for (final PropertyDescriptor propertyDescriptor : descriptor.getConstrainedProperties()) {
        final Object value = ((MinijaxPropertyDescriptor) propertyDescriptor).getValue(object);
        validateProperty(context, propertyDescriptor, value);
    }

    return context.getResult();
}
 
开发者ID:minijax,项目名称:minijax,代码行数:13,代码来源:MinijaxValidator.java


示例14: validateProperty

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
@Override
public <T> Set<ConstraintViolation<T>> validateProperty(final T object, final String propertyName, final Class<?>... groups) {
    final MinijaxConstraintValidatorContext<T> context = new MinijaxConstraintValidatorContext<>(object);
    final BeanDescriptor descriptor = getConstraintsForClass(object.getClass());
    final PropertyDescriptor propertyDescriptor = descriptor.getConstraintsForProperty(propertyName);
    final Object value = ((MinijaxPropertyDescriptor) propertyDescriptor).getValue(object);
    validateProperty(context, propertyDescriptor, value);
    return context.getResult();
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:MinijaxValidator.java


示例15: validateValue

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
@Override
public <T> Set<ConstraintViolation<T>> validateValue(final Class<T> beanType, final String propertyName, final Object value, final Class<?>... groups) {
    final MinijaxConstraintValidatorContext<T> context = new MinijaxConstraintValidatorContext<>(null);
    final PropertyDescriptor property = getConstraintsForClass(beanType).getConstraintsForProperty(propertyName);
    validateProperty(context, property, value);
    return context.getResult();
}
 
开发者ID:minijax,项目名称:minijax,代码行数:8,代码来源:MinijaxValidator.java


示例16: 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


示例17: validatePropertyElementConstraints

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

    for (final ContainerElementTypeDescriptor descriptor : property.getConstrainedContainerElementTypes()) {
        for (final ConstraintDescriptor constraint : descriptor.getConstraintDescriptors()) {
            final ConstraintValidator validator = ((MinijaxConstraintDescriptor) constraint).getValidator();

            if (value instanceof List) {
                validateList(context, constraint, validator, (List) value);

            } else if (value instanceof Iterable) {
                validateIterable(context, constraint, validator, (Iterable) value);

            } else if (value instanceof Map && descriptor.getTypeArgumentIndex() == 0) {
                validateMapKeys(context, constraint, validator, (Map<?, ?>) value);

            } else if (value instanceof Map) {
                validateMapValues(context, constraint, validator, (Map<?, ?>) value);

            } else if (value instanceof Optional) {
                validateOptional(context, constraint, validator, (Optional) value);
            }
        }
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:29,代码来源:MinijaxValidator.java


示例18: getConstraintsForProperty

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
@Override
public PropertyDescriptor getConstraintsForProperty(final String propertyName) {
    for (final PropertyDescriptor propertyDescriptor : constrainedProperties) {
        if (propertyDescriptor.getPropertyName().equals(propertyName)) {
            return propertyDescriptor;
        }
    }
    return null;
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:MinijaxBeanDescriptor.java


示例19: buildProperties

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
private static Set<PropertyDescriptor> buildProperties(final Class<?> c) {
    final Set<PropertyDescriptor> results = new HashSet<>();
    Class<?> currClass = c;

    while (currClass != null) {
        buildFields(results, currClass);
        buildGetters(results, currClass);
        currClass = currClass.getSuperclass();
    }

    return results;
}
 
开发者ID:minijax,项目名称:minijax,代码行数:13,代码来源:MinijaxBeanDescriptor.java


示例20: buildFields

import javax.validation.metadata.PropertyDescriptor; //导入依赖的package包/类
private static void buildFields(final Set<PropertyDescriptor> results, final Class<?> currClass) {
    for (final Field field : currClass.getDeclaredFields()) {
        final MinijaxFieldDescriptor fieldDescriptor = new MinijaxFieldDescriptor(field);
        if (fieldDescriptor.hasConstraints()) {
            field.setAccessible(true);
            results.add(fieldDescriptor);
        }
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:MinijaxBeanDescriptor.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LibsChecker类代码示例发布时间:2022-05-22
下一篇:
Java CompositeTokenGranter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap