/**
* @return A list of the class level annotations that the annotator will
* use.
*/
private List<MetaAnnotation> buildClassAnnotations() {
List<MetaAnnotation> anns = Lists.newArrayList();
HashMap<String, Object> annotParams;
// AlwaysValid
JDefinedClass alwaysValid = buildTemplateConstraint("AlwaysValid");
JDefinedClass alwaysValidValidator = buildTemplateConstraintValidator("AlwaysValidValidator", alwaysValid, Object.class);
JMethod isValid = getIsValidMethod(alwaysValidValidator);
isValid.body()._return(JExpr.TRUE);
alwaysValid.annotate(Constraint.class).param("validatedBy", alwaysValidValidator);
annotParams = Maps.newHashMap();
anns.add(new MetaAnnotation(alwaysValid, AnnotationType.JSR_303, annotParams));
return anns;
}
java类javax.validation.Constraint的实例源码
Jsr303Annotator.java 文件源码
项目:beanvalidation-benchmark
阅读 36
收藏 0
点赞 0
评论 0
ReflectionBasedJsr303AnnotationTrollerBase.java 文件源码
项目:backstopper
阅读 28
收藏 0
点赞 0
评论 0
/**
* @return true if this is a multi-value constraint class as per JSR 303 requirements (contains a value() method
* which returns an array of Constraints), false otherwise.
*/
private static boolean isMultiValueConstraintClass(Class<? extends Annotation> annotationClass) {
// It must have a value() method.
Method valueMethod;
try {
valueMethod = annotationClass.getDeclaredMethod("value");
}
catch (NoSuchMethodException e) {
return false;
}
// That value field must return a type of "array of Constraint"
//noinspection RedundantIfStatement
if (valueMethod.getReturnType().isArray()
&& valueMethod.getReturnType().getComponentType().getAnnotation(Constraint.class) != null) {
return true;
}
return false;
}
JValidator.java 文件源码
项目:EatDubbo
阅读 35
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:dubbo2
阅读 39
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
Jsr303Validator.java 文件源码
项目:jsf-sdk
阅读 27
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:dubbox-hystrix
阅读 36
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:dubbocloud
阅读 39
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:dubbos
阅读 38
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:dubbo-comments
阅读 33
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:dubbox
阅读 42
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:dubbo
阅读 31
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:dubbo-learning
阅读 37
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:DubboCode
阅读 54
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:jahhan
阅读 31
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
ObjectContext.java 文件源码
项目:rest-schemagen
阅读 34
收藏 0
点赞 0
评论 0
private boolean isRequired(Field field) {
if (field.isAnnotationPresent(NotNull.class)) {
return true;
}
Annotation[] annotations = field.getAnnotations();
for (Annotation annotation : annotations) {
Class<? extends Annotation> annotationType = annotation.annotationType();
if (annotationType.isAnnotationPresent(Constraint.class) && annotationType
.isAnnotationPresent(NotNull.class)) {
return true;
}
}
return false;
}
ObjectContext.java 文件源码
项目:rest-schemagen
阅读 30
收藏 0
点赞 0
评论 0
private <U, C extends Annotation> Optional<U> determineConstraints(Class<C> clazz, Field field, Function<C, U> callback) {
C constraint = field.getAnnotation(clazz);
if (constraint != null) {
return Optional.of(callback.apply(constraint));
}
for (Annotation annotation : field.getAnnotations()) {
Class<? extends Annotation> annotationType = annotation.annotationType();
if (annotationType.isAnnotationPresent(Constraint.class) && annotationType.isAnnotationPresent(clazz)) {
return Optional.of(callback.apply(annotationType.getAnnotation(clazz)));
}
}
return Optional.empty();
}
JValidator.java 文件源码
项目:dubbo2study
阅读 35
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:dubbo-comments
阅读 40
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:dubbo-ex
阅读 32
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:LetUsGo-Server
阅读 36
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
GwtSpecificValidatorCreator.java 文件源码
项目:gwt-bean-validators
阅读 46
收藏 0
点赞 0
评论 0
private boolean hasMatchingAnnotation(final Annotation expectedAnnotation,
final Annotation[] annotations) throws UnableToCompleteException {
// See spec section 2.2. Applying multiple constraints of the same type
for (final Annotation annotation : annotations) {
// annotations not annotated by @Constraint
if (annotation.annotationType().getAnnotation(Constraint.class) == null) {
try {
// value element has a return type of an array of constraint
// annotations
final Method valueMethod = annotation.annotationType().getMethod("value");
final Class<?> valueType = valueMethod.getReturnType();
if (valueType.isArray()
&& Annotation.class.isAssignableFrom(valueType.getComponentType())) {
if (Modifier.isAbstract(valueMethod.getModifiers())) {
// handle edge case where interface is marked "abstract"
valueMethod.setAccessible(true);
}
final Annotation[] valueAnnotions = (Annotation[]) valueMethod.invoke(annotation);
for (final Annotation annotation2 : valueAnnotions) {
if (expectedAnnotation.equals(annotation2)) {
return true;
}
}
}
} catch (final NoSuchMethodException ignore) { // NOPMD
// Expected Case.
} catch (final Exception e) {
throw error(this.logger, e);
}
}
}
return false;
}
AnnotationUtils.java 文件源码
项目:jsf-renderer-extensions
阅读 42
收藏 0
点赞 0
评论 0
public static boolean isBeanConstraint(String annotationName) {
boolean result = false;
try {
Class<?> annotationClass = Class.forName(annotationName);
result = annotationClass.getAnnotation(Constraint.class) != null;
} catch (ClassNotFoundException e) {
; // TODO At least log this, probably some class loading issue that we have to solve
}
return result;
}
AnnotationUtils.java 文件源码
项目:jsf-renderer-extensions
阅读 38
收藏 0
点赞 0
评论 0
private static List<Class<? extends ConstraintValidator<?, ?>>> getBeanConstraintValidator(Class annotationClass) {
Constraint annotation = (Constraint) annotationClass.getAnnotation(Constraint.class);
List<Class<? extends ConstraintValidator<?, ?>>> result = new ArrayList<>();
if (annotation != null) {
result = Arrays.asList(annotation.validatedBy());
}
return result;
}
JValidator.java 文件源码
项目:exDubbo
阅读 30
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
ValidCollectionValidator.java 文件源码
项目:InSpider
阅读 38
收藏 0
点赞 0
评论 0
@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;
}
JValidator.java 文件源码
项目:dangdangdotcom
阅读 36
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
JValidator.java 文件源码
项目:dubbo2.js
阅读 38
收藏 0
点赞 0
评论 0
private static boolean hasConstraintParameter(Method method) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
return true;
}
}
}
}
return false;
}
ValidatedMethodMatcher.java 文件源码
项目:guice-validator
阅读 29
收藏 0
点赞 0
评论 0
private boolean isValidationAnnotations(final Annotation... annotations) {
boolean matches = false;
for (Annotation ann : annotations) {
final Class<? extends Annotation> annotationType = ann.annotationType();
if (Valid.class.equals(annotationType) || annotationType.isAnnotationPresent(Constraint.class)) {
matches = true;
break;
}
}
return matches;
}
DayOfWeekValidatorTest.java 文件源码
项目:benerator
阅读 37
收藏 0
点赞 0
评论 0
@Test
public void testAnnotation() throws Exception {
DayOfWeek validationAnnotation = Dummy.class.getField("date").getAnnotation(DayOfWeek.class);
// instantiate validator from annotation info
Constraint validatorAnnotation = DayOfWeek.class.getAnnotation(Constraint.class);
Class<?>[] validatorClass = validatorAnnotation.validatedBy();
DayOfWeekValidator validator = (DayOfWeekValidator) BeanUtil.newInstance(validatorClass[0]);
validator.initialize(validationAnnotation);
// test
check(validator, true, false, true, false, false, false, false);
}
MinijaxConstraintDescriptor.java 文件源码
项目:minijax
阅读 39
收藏 0
点赞 0
评论 0
@SuppressWarnings("unchecked")
public static <T extends Annotation> MinijaxConstraintDescriptor<T> build(final AnnotatedType annotatedType, final T annotation) {
final Constraint constraint = annotation.annotationType().getAnnotation(Constraint.class);
if (constraint == null) {
return null;
}
final Class<?> valueClass = ReflectionUtils.getRawType(annotatedType);
final Class<?> annotationClass = annotation.annotationType();
if (constraint.validatedBy().length > 0) {
return buildDeclaredValidator(annotation, constraint.validatedBy()[0]);
} else if (annotationClass == AssertFalse.class) {
return (MinijaxConstraintDescriptor<T>) buildAssertFalseValidator((AssertFalse) annotation, valueClass);
} else if (annotationClass == AssertTrue.class) {
return (MinijaxConstraintDescriptor<T>) buildAssertTrueValidator((AssertTrue) annotation, valueClass);
} else if (annotationClass == Max.class) {
return (MinijaxConstraintDescriptor<T>) buildMaxValidator((Max) annotation, valueClass);
} else if (annotationClass == Min.class) {
return (MinijaxConstraintDescriptor<T>) buildMinValidator((Min) annotation, valueClass);
} else if (annotationClass == NotBlank.class) {
return (MinijaxConstraintDescriptor<T>) buildNotBlankValidator((NotBlank) annotation, valueClass);
} else if (annotationClass == NotEmpty.class) {
return (MinijaxConstraintDescriptor<T>) buildNotEmptyValidator((NotEmpty) annotation, valueClass);
} else if (annotationClass == NotNull.class) {
return (MinijaxConstraintDescriptor<T>) buildNotNullValidator((NotNull) annotation);
} else if (annotationClass == Pattern.class) {
return (MinijaxConstraintDescriptor<T>) buildPatternValidator((Pattern) annotation, valueClass);
} else if (annotationClass == Size.class) {
return (MinijaxConstraintDescriptor<T>) buildSizeValidator((Size) annotation, valueClass);
} else {
throw new ValidationException("Unrecognized constraint annotation: " + annotation);
}
}