コード例 #1
0
 private void checkRecursivelyHasNoIdAnnotationPresent(
     final Set<Class<?>> classesToInspect,
     final HashSet<Class<?>> alreadyInspectedClasses,
     final MappedClass mc,
     final Set<ConstraintViolation> ve) {
   for (final Class<?> clazz : classesToInspect) {
     if (alreadyInspectedClasses.contains(clazz)) {
       continue;
     }
     if (hasTypeFieldAnnotation(clazz, Id.class)) {
       ve.add(
           new ConstraintViolation(
               Level.FATAL,
               mc,
               getClass(),
               "You cannot use @Id on any field of an Embedded/Property object"));
     }
     alreadyInspectedClasses.add(clazz);
     final Set<Class<?>> extraClassesToInspect = new HashSet<Class<?>>();
     for (final Field field : ReflectionUtils.getDeclaredAndInheritedFields(clazz, true)) {
       if (isFieldToInspect(field)) {
         extraClassesToInspect.add(field.getType());
       }
     }
     checkRecursivelyHasNoIdAnnotationPresent(
         extraClassesToInspect, alreadyInspectedClasses, mc, ve);
   }
 }
コード例 #2
0
 private boolean hasTypeFieldAnnotation(final Class<?> type, final Class<Id> class1) {
   for (final Field field : ReflectionUtils.getDeclaredAndInheritedFields(type, true)) {
     if (field.getAnnotation(class1) != null) {
       return true;
     }
   }
   return false;
 }
コード例 #3
0
 @Override
 public void check(final MappedClass mc, final Set<ConstraintViolation> ve) {
   final Set<Class<?>> classesToInspect = new HashSet<Class<?>>();
   for (final Field field : ReflectionUtils.getDeclaredAndInheritedFields(mc.getClazz(), true)) {
     if (isFieldToInspect(field) && !field.isAnnotationPresent(Id.class)) {
       classesToInspect.add(field.getType());
     }
   }
   checkRecursivelyHasNoIdAnnotationPresent(classesToInspect, new HashSet<Class<?>>(), mc, ve);
 }