incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romanst...@apache.org
Subject svn commit: r938970 - in /incubator/bval/trunk/bval-core/src/main/java/org/apache/bval: BeanValidationContext.java BeanValidator.java model/ValidationContext.java
Date Wed, 28 Apr 2010 12:34:24 GMT
Author: romanstumm
Date: Wed Apr 28 12:34:24 2010
New Revision: 938970

URL: http://svn.apache.org/viewvc?rev=938970&view=rev
Log:
BVAL-28 Property path for nodes inside iterables that do not implement List should not contain
the index
- merged, reviewed and adapted the fixes from Carlos Varla

Modified:
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidationContext.java
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidator.java
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationContext.java

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidationContext.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidationContext.java?rev=938970&r1=938969&r2=938970&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidationContext.java
(original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidationContext.java
Wed Apr 28 12:34:24 2010
@@ -225,7 +225,7 @@ public class BeanValidationContext<T ext
         setBean(bean, aMetaBean); // reset context state
     }
 
-    public void setCurrentIndex(int index) {
+    public void setCurrentIndex(Integer index) {
         // do nothing
     }
 

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidator.java?rev=938970&r1=938969&r2=938970&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidator.java (original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/BeanValidator.java Wed Apr
28 12:34:24 2010
@@ -16,21 +16,17 @@
  */
 package org.apache.bval;
 
+import org.apache.bval.model.*;
+import org.apache.bval.util.AccessStrategy;
+import org.apache.bval.util.PropertyAccess;
+
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
-import org.apache.bval.model.Features;
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.MetaProperty;
-import org.apache.bval.model.Validation;
-import org.apache.bval.model.ValidationContext;
-import org.apache.bval.model.ValidationListener;
-import org.apache.bval.util.AccessStrategy;
-import org.apache.bval.util.PropertyAccess;
-
 /**
  * Description: Top-Level API-class to validate objects or object-trees.
  * You can invoke, extend or utilize this class if you need other ways to integrate
@@ -207,8 +203,10 @@ public class BeanValidator<T extends Val
         if (context.getBean() != null) {
             if (!treatMapsLikeBeans && context.getBean() instanceof Map<?, ?>)
{
                 validateMapInContext(context);
+            } else if (context.getBean() instanceof List<?>) {
+            	validateIteratableInContext(context);
             } else if (context.getBean() instanceof Iterable<?>) {
-                validateIteratableInContext(context);
+                validateNonPositionalIteratableInContext(context);
             } else if (context.getBean() instanceof Object[]) {
                 validateArrayInContext(context);
             } else { // to One Bean (or Map like Bean) 
@@ -264,6 +262,24 @@ public class BeanValidator<T extends Val
             validateBeanNet(context);
         }
     }
+    
+    private <VL extends ValidationListener> void validateNonPositionalIteratableInContext(ValidationContext<VL>
context) {
+        Iterator<?> it = ((Iterable<?>) context.getBean()).iterator();
+        // jsr303 spec: Each object provided by the iterator is validated.
+        context.setCurrentIndex(null);
+        final DynamicMetaBean dyn = getDynamicMetaBean(context);
+        while (it.hasNext()) { // to Many
+            Object each = it.next();
+            if (each == null)
+                continue; // enhancement: throw IllegalArgumentException? (=> spec)
+            if (dyn != null) {
+                context.setBean(each, dyn.resolveMetaBean(each));
+            } else {
+                context.setBean(each);
+            }
+            validateBeanNet(context);
+        }
+    }
 
     private <VL extends ValidationListener> void validateMapInContext(ValidationContext<VL>
context) {
         // jsr303 spec: For Map, the value of each Map.Entry is validated (key is not validated).

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationContext.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationContext.java?rev=938970&r1=938969&r2=938970&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationContext.java
(original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationContext.java
Wed Apr 28 12:34:24 2010
@@ -58,7 +58,7 @@ public interface ValidationContext<T ext
      * set the index of the object currently validated into the context.
      * used to create the propertyPath with [index] information for collections.
      */
-    void setCurrentIndex(int index);
+    void setCurrentIndex(Integer index);
 
     /**
      * set the key of the object in a map currently validated into the context.



Mime
View raw message