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


Java ConstraintDescriptor.getAnnotation方法代码示例

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


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

示例1: registerActionMessage

import javax.validation.metadata.ConstraintDescriptor; //导入方法依赖的package包/类
protected void registerActionMessage(UserMessages messages, ConstraintViolation<Object> vio) {
    final String propertyPath = extractPropertyPath(vio);
    final String plainMessage = filterMessageItem(extractMessage(vio), propertyPath);
    final String delimiter = MESSAGE_HINT_DELIMITER;
    final String messageItself;
    final String messageKey;
    if (plainMessage.contains(delimiter)) { // basically here
        messageItself = Srl.substringFirstRear(plainMessage, delimiter);
        messageKey = Srl.substringFirstFront(plainMessage, delimiter);
    } else { // just in case
        messageItself = plainMessage;
        messageKey = null;
    }
    final ConstraintDescriptor<?> descriptor = vio.getConstraintDescriptor();
    final Annotation annotation = descriptor.getAnnotation();
    final Set<Class<?>> groupSet = descriptor.getGroups();
    final Class<?>[] groups = groupSet.toArray(new Class<?>[groupSet.size()]);
    messages.add(propertyPath, createDirectMessage(messageItself, annotation, groups, messageKey));
}
 
开发者ID:lastaflute,项目名称:lastaflute,代码行数:20,代码来源:ActionValidator.java

示例2: getValidatorForType

import javax.validation.metadata.ConstraintDescriptor; //导入方法依赖的package包/类
/**
 * Gets the best {@link ConstraintValidator}.
 *
 * <p>
 * The ConstraintValidator chosen to validate a declared type {@code targetType} is the one where
 * the type supported by the ConstraintValidator is a supertype of {@code targetType} and where
 * there is no other ConstraintValidator whose supported type is a supertype of {@code type} and
 * not a supertype of the chosen ConstraintValidator supported type.
 * </p>
 *
 * @param constraint the constraint to find ConstraintValidators for.
 * @param targetType The type to find a ConstraintValidator for.
 * @return ConstraintValidator
 *
 * @throws UnexpectedTypeException if there is not exactly one maximally specific constraint
 *         validator for targetType.
 */
private static <A extends Annotation> Class<? extends ConstraintValidator<A, ?>> //
    getValidatorForType(final ConstraintDescriptor<A> constraint, final Class<?> targetType)
        throws UnexpectedTypeException {
  final List<Class<? extends ConstraintValidator<A, ?>>> constraintValidatorClasses =
      constraint.getConstraintValidatorClasses();
  if (constraintValidatorClasses.isEmpty()) {
    throw new UnexpectedTypeException(
        "No ConstraintValidator found for  " + constraint.getAnnotation());
  }
  final ImmutableSet<Class<? extends ConstraintValidator<A, ?>>> best =
      getValidatorForType(targetType, constraintValidatorClasses);
  if (best.isEmpty()) {
    throw new UnexpectedTypeException(
        "No " + constraint.getAnnotation() + " ConstraintValidator for type " + targetType);
  }
  if (best.size() > 1) {
    throw new UnexpectedTypeException("More than one maximally specific "
        + constraint.getAnnotation() + " ConstraintValidator for type " + targetType + ", found "
        + Ordering.usingToString().sortedCopy(best));
  }
  return Iterables.get(best, 0);
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:40,代码来源:GwtSpecificValidatorCreator.java

示例3: fromConstraintViolation

import javax.validation.metadata.ConstraintDescriptor; //导入方法依赖的package包/类
public static Violation fromConstraintViolation(final ConstraintViolation<?> constraintViolation) {
    final String property = constraintViolation.getPropertyPath().toString();
    final ConstraintDescriptor<?> constraintDescriptor = constraintViolation.getConstraintDescriptor();
    final Annotation annotation = constraintDescriptor.getAnnotation();
    final Class<? extends Annotation> annotationType = annotation.annotationType();
    final String error = annotationType.getSimpleName();
    final String message = constraintViolation.getMessage();

    return new Builder().property(property).error(error).message(message).build();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:11,代码来源:Violation.java

示例4: hasMatchingAnnotation

import javax.validation.metadata.ConstraintDescriptor; //导入方法依赖的package包/类
private boolean hasMatchingAnnotation(final ConstraintDescriptor<?> constraint)
    throws UnableToCompleteException {
  final Annotation expectedAnnotation = constraint.getAnnotation();
  final Class<? extends Annotation> expectedAnnotationClass = expectedAnnotation.annotationType();
  if (expectedAnnotation
      .equals(this.beanHelper.getClazz().getAnnotation(expectedAnnotationClass))) {
    return true;
  }

  // See spec section 2.2. Applying multiple constraints of the same type
  final Annotation[] annotations = this.beanHelper.getClazz().getAnnotations();
  return this.hasMatchingAnnotation(expectedAnnotation, annotations);
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:14,代码来源:GwtSpecificValidatorCreator.java


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