bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1002666 - /incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NestedPathNavigator.java
Date Wed, 29 Sep 2010 15:08:22 GMT
Author: mbenson
Date: Wed Sep 29 15:08:21 2010
New Revision: 1002666

URL: http://svn.apache.org/viewvc?rev=1002666&view=rev
Log:
use graph context to determine whether a given iterable is indexed or keyed rather than relying
on the index/key value

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NestedPathNavigator.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NestedPathNavigator.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NestedPathNavigator.java?rev=1002666&r1=1002665&r2=1002666&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NestedPathNavigator.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NestedPathNavigator.java
Wed Sep 29 15:08:21 2010
@@ -40,7 +40,7 @@ public class NestedPathNavigator {
 
         /**
          * Create a new NullSafePropertyAccess instance.
-         * 
+         *
          * @param clazz
          * @param propertyName
          */
@@ -59,7 +59,7 @@ public class NestedPathNavigator {
 
     /**
      * Navigate a {@link ValidationContext} down a nested path.
-     * 
+     *
      * @param validationContext
      * @param propertyPath
      */
@@ -91,19 +91,26 @@ public class NestedPathNavigator {
             moveDownIfNecessary();
 
             AccessStrategy access;
-            try {
-                int index = Integer.parseInt(token);
-                validationContext.setCurrentIndex(index);
-                access = new IndexedAccess(type, index);
-            } catch (NumberFormatException e) {
-                validationContext.setCurrentKey(token);
+            if (IndexedAccess.getJavaElementType(type) != null) {
+                try {
+                    int index = Integer.parseInt(token);
+                    access = new IndexedAccess(type, index);
+                    validationContext.setCurrentIndex(index);
+                } catch (NumberFormatException e) {
+                    throw new UnknownPropertyException(String.format("Cannot parse %s as
an array/iterable index",
+                        token), e);
+                }
+            } else if (KeyedAccess.getJavaElementType(type) != null) {
                 access = new KeyedAccess(type, token);
+                validationContext.setCurrentKey(token);
+            } else {
+                throw new UnknownPropertyException(String.format("Cannot determine index/key
type for %s", type));
             }
             Object value = validationContext.getBean();
             Object child = access.get(value);
             setType(access.getJavaType());
-            validationContext.setBean(child, validationContext.getMetaBean().resolveMetaBean(
-                child == null ? rawType : child));
+            validationContext.setBean(child,
+                validationContext.getMetaBean().resolveMetaBean(child == null ? rawType :
child));
         }
 
         /**
@@ -130,7 +137,7 @@ public class NestedPathNavigator {
         /**
          * If we currently have a property, navigate the context such that the
          * property becomes the bean, in preparation for another property.
-         * 
+         *
          * @param validationContext
          */
         protected void moveDownIfNecessary() {
@@ -143,7 +150,7 @@ public class NestedPathNavigator {
 
         /**
          * Set the type of the expression processed thus far.
-         * 
+         *
          * @param type
          */
         protected void setType(Type type) {



Mime
View raw message