views:

19

answers:

0

I have the following method that recursively breaks down a compound constraint into its component constraints:

private void handleComposingConstraints(String friendlyName, Constraint parentConstraint, ConstraintDescriptor<? extends Annotation> parentDescriptor) {

    if(parentDescriptor.getAnnotation().annotationType().getName().indexOf("javax.validation") < 0 &&
       parentDescriptor.getAnnotation().annotationType().getName().indexOf("org.hibernate") < 0) {

        parentConstraint.setCompound(true);

        for(ConstraintDescriptor<? extends Annotation> composingDescriptor : parentDescriptor.getComposingConstraints()) {

            Constraint composingConstraint = createConstraintFromDescriptor(friendlyName, composingDescriptor);

            if(composingDescriptor.getComposingConstraints().size() > 0) {
                handleComposingConstraints(friendlyName, composingConstraint, composingDescriptor);
            }

            parentConstraint.addComposingConstraint(composingConstraint);
        }
    }
}

Constraint is a class of my own that I use to keep track of constraint information. ConstraintDescriptor comes from Spring's BeanUtils. I am trying to skip compound constraints that come from javax.validation and org.hibernate (for example @NotBlank is a compound constraint that contains @NotNull). I don't like having to depend on the fully-qualified class-name. Is there a better way to do this?

related questions