incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romanst...@apache.org
Subject svn commit: r936275 - /incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
Date Wed, 21 Apr 2010 12:09:21 GMT
Author: romanstumm
Date: Wed Apr 21 12:09:21 2010
New Revision: 936275

URL: http://svn.apache.org/viewvc?rev=936275&view=rev
Log:
BVAL-20 - merged fixes from Carlos: when building a MetaBean, the full tree of subclasses/interfaces
must be considered, not only subclasses and interfaces of the original class

Modified:
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java?rev=936275&r1=936274&r2=936275&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
Wed Apr 21 12:09:21 2010
@@ -39,10 +39,7 @@ import javax.validation.*;
 import javax.validation.groups.Default;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.*;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * Description: process the class annotations for JSR303 constraint validations
@@ -75,17 +72,11 @@ public class Jsr303MetaBeanFactory imple
         try {
             final Class<?> beanClass = metabean.getBeanClass();
             processGroupSequence(beanClass, metabean);
-            for (Class<?> interfaceClass : beanClass.getInterfaces()) {
-                processClass(interfaceClass, metabean);
-            }
 
             // process class, superclasses and interfaces
             List<Class<?>> classSequence = new ArrayList<Class<?>>();
-            Class<?> theClass = beanClass;
-            while (theClass != null && theClass != Object.class) {
-                classSequence.add(theClass);
-                theClass = theClass.getSuperclass();
-            }
+            fillFullClassHierarchyAsList(classSequence, beanClass);
+
             // start with superclasses and go down the hierarchy so that
             // the child classes are processed last to have the chance to overwrite some
declarations
             // of their superclasses and that they see what they inherit at the time of processing
@@ -99,6 +90,39 @@ public class Jsr303MetaBeanFactory imple
             throw new IllegalArgumentException(e.getTargetException());
         }
     }
+    
+    /**
+     * Fill the list with the full class/interface hierarchy of the given class.
+     * List is ordered from the most to less specific.
+     * 
+     * @param allClasses
+     *            The current list of classes in the hierarchy.
+     * @param clazz
+     *            The current class, root of the hierarchy to traverse.
+     */
+    private void fillFullClassHierarchyAsList(List<Class<?>> allClasses, Class<?>
clazz) {
+        
+        if ( clazz == null || clazz == Object.class ) {
+            return;
+        }
+        
+        if ( allClasses.contains(clazz) ) {
+            // No duplicates wanted, and if it is already in the list, then
+            // its superclasses/interfaces will also be
+            return;
+        }
+        
+        allClasses.add(clazz);
+
+        // Obtain the list of interfaces and superclass
+        List<Class<?>> subClasses = new ArrayList<Class<?>>(Arrays.asList(clazz.getInterfaces()));
+        subClasses.add(0, clazz.getSuperclass());
+        
+        for ( Class<?> subClass : subClasses ) {
+            fillFullClassHierarchyAsList(allClasses, subClass);
+        }
+        
+    }
 
     /**
      * process class annotations, field and method annotations



Mime
View raw message