本文整理汇总了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));
}
示例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);
}
示例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();
}
示例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);
}