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); } }
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; }
@Override protected boolean isSupported(final Class<?> c, final MappedField optionalExtraInfo) { if (optionalExtraInfo != null) { return optionalExtraInfo.isMap(); } else { return ReflectionUtils.implementsInterface(c, Map.class); } }
@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); }