You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by mb...@apache.org on 2011/01/31 23:14:54 UTC

svn commit: r1065828 - in /incubator/bval/sandbox/lang3-work: bval-core/src/main/java/org/apache/bval/util/ bval-jsr303/src/main/java/org/apache/bval/jsr303/ bval-jsr303/src/main/java/org/apache/bval/jsr303/util/ bval-jsr303/src/test/java/org/apache/bv...

Author: mbenson
Date: Mon Jan 31 22:14:53 2011
New Revision: 1065828

URL: http://svn.apache.org/viewvc?rev=1065828&view=rev
Log:
upgrade to TCK v1.0.5.Beta1

Modified:
    incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/util/ValidationHelper.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/GroupValidationContextImpl.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeBuilderCustomizableContextImpl.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeContextBuilderImpl.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeImpl.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathImpl.java
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/PathImplTest.java
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagerImpl.java
    incubator/bval/sandbox/lang3-work/bval-tck/pom.xml

Modified: incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/util/ValidationHelper.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/util/ValidationHelper.java?rev=1065828&r1=1065827&r2=1065828&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/util/ValidationHelper.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/util/ValidationHelper.java Mon Jan 31 22:14:53 2011
@@ -21,6 +21,7 @@ package org.apache.bval.util;
 import java.util.List;
 import java.util.Map;
 import org.apache.bval.DynamicMetaBean;
+import org.apache.bval.model.MetaBean;
 import org.apache.bval.model.MetaProperty;
 import org.apache.bval.model.Validation;
 import org.apache.bval.model.ValidationContext;
@@ -98,17 +99,24 @@ public class ValidationHelper {
     static protected <VL extends ValidationListener> void validateArrayInContext(ValidationContext<VL> context, ValidateCallback s) {
         int index = 0;
         DynamicMetaBean dyn = getDynamicMetaBean(context);
-        for (Object each : ((Object[]) context.getBean())) {
-            context.setCurrentIndex(index++);
-            if (each == null) {
-                continue; // Null values are not validated
-            }
-            if (dyn != null) {
-                context.setBean(each, dyn.resolveMetaBean(each));
-            } else {
-                context.setBean(each);
+        Object[] array = (Object[]) context.getBean();
+        MetaBean metaBean = context.getMetaBean();
+        context.setCurrentIndex(null);
+        try {
+            for (Object each : array) {
+                context.setCurrentIndex(index++);
+                if (each == null) {
+                    continue; // Null values are not validated
+                }
+                if (dyn != null) {
+                    context.setBean(each, dyn.resolveMetaBean(each));
+                } else {
+                    context.setBean(each);
+                }
+                s.validate();
             }
-            s.validate();
+        } finally {
+            context.moveUp(array, metaBean);
         }
     }
 
@@ -125,23 +133,29 @@ public class ValidationHelper {
 
         final boolean positional = context.getBean() instanceof List<?>;
         int index = 0;
+        Iterable<?> iterable = (Iterable<?>) context.getBean();
+        MetaBean metaBean = context.getMetaBean();
         context.setCurrentIndex(null);
 
-        // jsr303 spec: Each object provided by the iterator is validated.
-        final DynamicMetaBean dyn = getDynamicMetaBean(context);
-        for (Object each : (Iterable<?>) context.getBean()) {
-            if (positional) {
-                context.setCurrentIndex(index++);
-            }
-            if (each == null) {
-                continue; // Null values are not validated
+        try {
+            // jsr303 spec: Each object provided by the iterator is validated.
+            final DynamicMetaBean dyn = getDynamicMetaBean(context);
+            for (Object each : iterable) {
+                if (positional) {
+                    context.setCurrentIndex(index++);
+                }
+                if (each == null) {
+                    continue; // Null values are not validated
+                }
+                if (dyn != null) {
+                    context.setBean(each, dyn.resolveMetaBean(each));
+                } else {
+                    context.setBean(each);
+                }
+                s.validate();
             }
-            if (dyn != null) {
-                context.setBean(each, dyn.resolveMetaBean(each));
-            } else {
-                context.setBean(each);
-            }
-            s.validate();
+        } finally {
+            context.moveUp(iterable, metaBean);
         }
     }
 
@@ -155,21 +169,28 @@ public class ValidationHelper {
      *            {@link Map}.
      */
     static protected <VL extends ValidationListener> void validateMapInContext(ValidationContext<VL> context, ValidateCallback s) {
-        // jsr303 spec: For Map, the value of each Map.Entry is validated (key is not validated).
+        // jsr303 spec: For Map, the value of each Map.Entry is validated (key
+        // is not validated).
         Map<?, ?> currentBean = (Map<?, ?>) context.getBean();
+        MetaBean metaBean = context.getMetaBean();
         final DynamicMetaBean dyn = getDynamicMetaBean(context);
-        for (Object key : currentBean.keySet()) {
-            context.setCurrentKey(key);
-            Object value = currentBean.get(key);
-            if (value == null) {
-                continue; // Null values are not validated
-            }
-            if (dyn != null) {
-                context.setBean(value, dyn.resolveMetaBean(value));
-            } else {
-                context.setBean(value);
+        context.setCurrentKey(null);
+        try {
+            for (Object key : currentBean.keySet()) {
+                context.setCurrentKey(key);
+                Object value = currentBean.get(key);
+                if (value == null) {
+                    continue; // Null values are not validated
+                }
+                if (dyn != null) {
+                    context.setBean(value, dyn.resolveMetaBean(value));
+                } else {
+                    context.setBean(value);
+                }
+                s.validate();
             }
-            s.validate();
+        } finally {
+            context.moveUp(currentBean, metaBean);
         }
     }
 

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/GroupValidationContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/GroupValidationContextImpl.java?rev=1065828&r1=1065827&r2=1065828&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/GroupValidationContextImpl.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/GroupValidationContextImpl.java Mon Jan 31 22:14:53 2011
@@ -88,7 +88,12 @@ final class GroupValidationContextImpl<T
      */
     @Override
     public void setCurrentIndex(Integer index) {
-        path.getLeafNode().setIndex(index);
+        NodeImpl leaf = path.getLeafNode();
+        if (leaf.getName() == null) {
+            leaf.setIndex(index);
+        } else {
+            path.addNode(NodeImpl.atIndex(index));
+        }
     }
 
     /**
@@ -96,7 +101,12 @@ final class GroupValidationContextImpl<T
      */
     @Override
     public void setCurrentKey(Object key) {
-        path.getLeafNode().setKey(key);
+        NodeImpl leaf = path.getLeafNode();
+        if (leaf.getName() == null) {
+            leaf.setKey(key);
+        } else {
+            path.addNode(NodeImpl.atKey(key));
+        }
     }
 
     /**
@@ -104,7 +114,7 @@ final class GroupValidationContextImpl<T
      */
     @Override
     public void moveDown(MetaProperty prop, AccessStrategy access) {
-        path.addNode(new NodeImpl(prop.getName()));
+        path.addProperty(prop.getName());
         super.moveDown(prop, access);
     }
 
@@ -113,7 +123,12 @@ final class GroupValidationContextImpl<T
      */
     @Override
     public void moveUp(Object bean, MetaBean metaBean) {
-        path.removeLeafNode();
+        NodeImpl leaf = path.getLeafNode();
+        if (leaf.isInIterable() && leaf.getName() != null) {
+            leaf.setName(null);
+        } else {
+            path.removeLeafNode();
+        }
         super.moveUp(bean, metaBean); // call super!
     }
 
@@ -172,7 +187,7 @@ final class GroupValidationContextImpl<T
     public PathImpl getPropertyPath() {
         PathImpl currentPath = PathImpl.copy(path);
         if (getMetaProperty() != null) {
-            currentPath.addNode(new NodeImpl(getMetaProperty().getName()));
+            currentPath.addProperty(getMetaProperty().getName());
         }
         return currentPath;
     }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeBuilderCustomizableContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeBuilderCustomizableContextImpl.java?rev=1065828&r1=1065827&r2=1065828&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeBuilderCustomizableContextImpl.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeBuilderCustomizableContextImpl.java Mon Jan 31 22:14:53 2011
@@ -31,9 +31,7 @@ final class NodeBuilderCustomizableConte
     private final ConstraintValidatorContextImpl parent;
     private final String messageTemplate;
     private final PathImpl propertyPath;
-    // The name of the last "added" node, it will only be added if it has a non-null name
-    // The actual incorporation in the path will take place when the definition of the current leaf node is complete
-    private String lastNodeName; // Not final as it can be re-used
+    private NodeImpl node;
 
     /**
      * Create a new NodeBuilderCustomizableContextImpl instance.
@@ -47,7 +45,7 @@ final class NodeBuilderCustomizableConte
         parent = contextImpl;
         messageTemplate = template;
         propertyPath = path;
-        lastNodeName = name;
+        node = new NodeImpl(name);
     }
 
     /**
@@ -55,8 +53,8 @@ final class NodeBuilderCustomizableConte
      */
     public ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder inIterable() {
         // Modifies the "previous" node in the path
-        this.propertyPath.getLeafNode().setInIterable( true );
-        return new NodeContextBuilderImpl(parent, messageTemplate, propertyPath, lastNodeName);
+        node.setInIterable(true);
+        return new NodeContextBuilderImpl(parent, messageTemplate, propertyPath, node);
     }
 
     /**
@@ -64,8 +62,8 @@ final class NodeBuilderCustomizableConte
      */
     public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(
           String name) {
-        addLastNodeIfNeeded();
-        lastNodeName = name;
+        propertyPath.addNode(node);
+        node = new NodeImpl(name);
         return this; // Re-use this instance
     }
 
@@ -73,15 +71,10 @@ final class NodeBuilderCustomizableConte
      * {@inheritDoc}
      */
     public ConstraintValidatorContext addConstraintViolation() {
-        addLastNodeIfNeeded();
+        propertyPath.addNode(node);
+        node = null;
         parent.addError(messageTemplate, propertyPath);
         return parent;
     }
     
-    private void addLastNodeIfNeeded() {
-        if (lastNodeName != null) {
-            NodeImpl node = new NodeImpl(lastNodeName);
-            propertyPath.addNode(node);
-        }
-    }
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeContextBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeContextBuilderImpl.java?rev=1065828&r1=1065827&r2=1065828&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeContextBuilderImpl.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeContextBuilderImpl.java Mon Jan 31 22:14:53 2011
@@ -34,21 +34,20 @@ final class NodeContextBuilderImpl
     private final PathImpl propertyPath;
     // The name of the last "added" node, it will only be added if it has a non-null name
     // The actual incorporation in the path will take place when the definition of the current leaf node is complete
-    private final String lastNodeName;
+    private final NodeImpl node;
 
     /**
      * Create a new NodeContextBuilderImpl instance.
      * @param contextImpl
      * @param template
      * @param path
-     * @param name
      */
     NodeContextBuilderImpl(ConstraintValidatorContextImpl contextImpl,
-                                    String template, PathImpl path, String name) {
+                                    String template, PathImpl path, NodeImpl node) {
         parent = contextImpl;
         messageTemplate = template;
         propertyPath = path;
-        lastNodeName = name;
+        this.node = node;
     }
 
     /**
@@ -56,9 +55,8 @@ final class NodeContextBuilderImpl
      */
     public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext atKey(
           Object key) {
-        // Modifies the "previous" node in the path
-        propertyPath.getLeafNode().setKey(key);
-        addLastNodeIfNeeded();
+        node.setKey(key);
+        propertyPath.addNode(node);
         return new NodeBuilderDefinedContextImpl(parent, messageTemplate, propertyPath);
     }
 
@@ -67,9 +65,8 @@ final class NodeContextBuilderImpl
      */
     public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext atIndex(
           Integer index) {
-        // Modifies the "previous" node in the path
-        propertyPath.getLeafNode().setIndex(index);
-        addLastNodeIfNeeded();
+        node.setIndex(index);
+        propertyPath.addNode(node);
         return new NodeBuilderDefinedContextImpl(parent, messageTemplate, propertyPath);
     }
 
@@ -78,23 +75,17 @@ final class NodeContextBuilderImpl
      */
     public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(
           String name) {
-        addLastNodeIfNeeded();
-        return new NodeBuilderCustomizableContextImpl(parent, messageTemplate, propertyPath, lastNodeName);
+        propertyPath.addNode(node);
+        return new NodeBuilderCustomizableContextImpl(parent, messageTemplate, propertyPath, name);
     }
 
     /**
      * {@inheritDoc}
      */
     public ConstraintValidatorContext addConstraintViolation() {
-        addLastNodeIfNeeded();
+        propertyPath.addNode(node);
         parent.addError(messageTemplate, propertyPath);
         return parent;
     }
     
-    private void addLastNodeIfNeeded() {
-        if (lastNodeName != null) {
-            NodeImpl node = new NodeImpl(lastNodeName);
-            propertyPath.addNode(node);
-        }
-    }
 }
\ No newline at end of file

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeImpl.java?rev=1065828&r1=1065827&r2=1065828&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeImpl.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeImpl.java Mon Jan 31 22:14:53 2011
@@ -19,6 +19,8 @@
 package org.apache.bval.jsr303.util;
 
 import javax.validation.Path;
+import javax.validation.Path.Node;
+
 import java.io.Serializable;
 import java.util.Map;
 
@@ -32,7 +34,54 @@ public final class NodeImpl implements P
     private static final String INDEX_OPEN = "[";
     private static final String INDEX_CLOSE = "]";
 
-    private final String name;
+    /**
+     * Append a Node to the specified StringBuilder.
+     * @param node
+     * @param to
+     * @return to
+     */
+    public static StringBuilder appendNode(Node node, StringBuilder to) {
+        if (node.isInIterable()) {
+            to.append(INDEX_OPEN);
+            if (node.getIndex() != null) {
+                to.append(node.getIndex());
+            } else if (node.getKey() != null) {
+                to.append(node.getKey());
+            }
+            to.append(INDEX_CLOSE);
+        }
+        if (node.getName() != null) {
+            if (to.length() > 0) {
+                to.append(PathImpl.PROPERTY_PATH_SEPARATOR);
+            }
+            to.append(node.getName());
+        }
+        return to;
+    }
+
+    /**
+     * Get a NodeImpl indexed from the preceding node (or root).
+     * @param index
+     * @return NodeImpl
+     */
+    public static NodeImpl atIndex(Integer index) {
+        NodeImpl result = new NodeImpl();
+        result.setIndex(index);
+        return result;
+    }
+    
+    /**
+     * Get a NodeImpl keyed from the preceding node (or root).
+     * @param key
+     * @return NodeImpl
+     */
+    public static NodeImpl atKey(Object key) {
+        NodeImpl result = new NodeImpl();
+        result.setKey(key);
+        return result;
+    }
+
+    private String name;
     private boolean inIterable;
     private Integer index;
     private Object key;
@@ -56,6 +105,9 @@ public final class NodeImpl implements P
         this.key = node.getKey();
     }
 
+    private NodeImpl() {
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -64,6 +116,13 @@ public final class NodeImpl implements P
     }
 
     /**
+     * @param name the name to set
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
      * {@inheritDoc}
      */
     public boolean isInIterable() {
@@ -92,6 +151,7 @@ public final class NodeImpl implements P
     public void setIndex(Integer index) {
         inIterable = true;
         this.index = index;
+        this.key = null;
     }
 
     /**
@@ -108,6 +168,7 @@ public final class NodeImpl implements P
     public void setKey(Object key) {
         inIterable = true;
         this.key = key;
+        this.index = null;
     }
 
     /**
@@ -115,17 +176,7 @@ public final class NodeImpl implements P
      */
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder(name == null ? "" : name);
-        if (inIterable) {
-            builder.append(INDEX_OPEN);
-            if (getIndex() != null) {
-                builder.append(getIndex());
-            } else if (getKey() != null) {
-                builder.append(getKey());
-            }
-            builder.append(INDEX_CLOSE);
-        }
-        return builder.toString();
+        return appendNode(this, new StringBuilder()).toString();
     }
 
     /**

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathImpl.java?rev=1065828&r1=1065827&r2=1065828&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathImpl.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/PathImpl.java Mon Jan 31 22:14:53 2011
@@ -48,7 +48,7 @@ public class PathImpl implements Path, S
          * {@inheritDoc}
          */
         public void handleProperty(String name) {
-            result.addNode(new NodeImpl(name));
+            result.addProperty(name);
         }
 
         /**
@@ -56,16 +56,13 @@ public class PathImpl implements Path, S
          */
         public void handleIndexOrKey(String value) {
             // with no context to guide us, we can only parse ints and fall back to String keys:
-            NodeImpl leaf = result.getLeafNode();
-            if (leaf.isInIterable()) {
-                leaf = new NodeImpl((String) null);
-                result.addNode(leaf);
-            }
+            NodeImpl node;
             try {
-                leaf.setIndex(Integer.parseInt(value));
+                node = NodeImpl.atIndex(Integer.parseInt(value));
             } catch (NumberFormatException e) {
-                leaf.setKey(value);
+                node = NodeImpl.atKey(value);
             }
+            result.addNode(node);
         }
 
         /**
@@ -82,12 +79,7 @@ public class PathImpl implements Path, S
          * {@inheritDoc}
          */
         public void handleGenericInIterable() {
-            NodeImpl leaf = result.getLeafNode();
-            if (leaf.isInIterable()) {
-                leaf = new NodeImpl((String) null);
-                result.addNode(leaf);
-            }
-            leaf.setInIterable(true);
+            result.addNode(NodeImpl.atIndex(null));
         }
 
     }
@@ -194,6 +186,22 @@ public class PathImpl implements Path, S
     }
 
     /**
+     * Encapsulate the node manipulations needed to add a named property to this path.
+     * 
+     * @param name
+     */
+    public void addProperty(String name) {
+        if (!nodeList.isEmpty()) {
+            NodeImpl leaf = getLeafNode();
+            if (leaf != null && leaf.isInIterable() && leaf.getName() == null) {
+                leaf.setName(name);
+                return;
+            }
+        }
+        addNode(new NodeImpl(name));
+    }
+
+    /**
      * Trim the leaf node from this {@link PathImpl}.
      * 
      * @return the node removed
@@ -245,9 +253,25 @@ public class PathImpl implements Path, S
                 return false;
             }
             Node thisNode = thisIter.next();
-            if (!thisNode.equals(pathNode)) {
+            if (pathNode.isInIterable()) {
+                if (!thisNode.isInIterable()) {
+                    return false;
+                }
+                if (pathNode.getIndex() != null && !pathNode.getIndex().equals(thisNode.getIndex())) {
+                    return false;
+                }
+                if (pathNode.getKey() != null && !pathNode.getKey().equals(thisNode.getKey())) {
+                    return false;
+                }
+            } else if (thisNode.isInIterable()) {
+                // in this case we have shown that the proposed parent is not
+                // indexed, and we are, thus the paths cannot match
                 return false;
             }
+            if (pathNode.getName() == null || pathNode.getName().equals(thisNode.getName())) {
+                continue;
+            }
+            return false;
         }
         return true;
     }
@@ -258,13 +282,8 @@ public class PathImpl implements Path, S
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();
-        Iterator<Path.Node> iter = iterator();
-        while (iter.hasNext()) {
-            Node node = iter.next();
-            builder.append(node.toString());
-            if (iter.hasNext() && builder.length() > 0) {
-                builder.append(PROPERTY_PATH_SEPARATOR);
-            }
+        for (Path.Node node : this) {
+            NodeImpl.appendNode(node, builder);
         }
         return builder.toString();
     }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/PathImplTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/PathImplTest.java?rev=1065828&r1=1065827&r2=1065828&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/PathImplTest.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/PathImplTest.java Mon Jan 31 22:14:53 2011
@@ -45,26 +45,31 @@ public class PathImplTest extends TestCa
         String property = "order[3].deliveryAddress.addressline[1]";
         Path path = PathImpl.createPathFromString(property);
         assertEquals(property, path.toString());
-        
+
         Iterator<Path.Node> propIter = path.iterator();
 
         assertTrue(propIter.hasNext());
         Path.Node elem = propIter.next();
+        assertFalse(elem.isInIterable());
         assertEquals("order", elem.getName());
+
+        assertTrue(propIter.hasNext());
+        elem = propIter.next();
         assertTrue(elem.isInIterable());
         assertEquals(new Integer(3), elem.getIndex());
+        assertEquals("deliveryAddress", elem.getName());
 
         assertTrue(propIter.hasNext());
         elem = propIter.next();
-        assertEquals("deliveryAddress", elem.getName());
         assertFalse(elem.isInIterable());
         assertEquals(null, elem.getIndex());
+        assertEquals("addressline", elem.getName());
 
         assertTrue(propIter.hasNext());
         elem = propIter.next();
-        assertEquals("addressline", elem.getName());
         assertTrue(elem.isInIterable());
         assertEquals(new Integer(1), elem.getIndex());
+        assertNull(elem.getName());
 
         assertFalse(propIter.hasNext());
     }
@@ -76,16 +81,50 @@ public class PathImplTest extends TestCa
 
         assertTrue(propIter.hasNext());
         Path.Node elem = propIter.next();
+        assertFalse(elem.isInIterable());
         assertEquals("order", elem.getName());
+
+        assertTrue(propIter.hasNext());
+        elem = propIter.next();
         assertTrue(elem.isInIterable());
         assertEquals("foo", elem.getKey());
+        assertEquals("deliveryAddress", elem.getName());
+
+        assertFalse(propIter.hasNext());
+    }
+
+    //some of the examples from the 1.0 bean validation spec, section 4.2
+    public void testSpecExamples() {
+        String fourthAuthor = "authors[3]";
+        Path path = PathImpl.createPathFromString(fourthAuthor);
+        Iterator<Path.Node> propIter = path.iterator();
+
+        assertTrue(propIter.hasNext());
+        Path.Node elem = propIter.next();
+        assertFalse(elem.isInIterable());
+        assertEquals("authors", elem.getName());
+
+        assertTrue(propIter.hasNext());
+        elem = propIter.next();
+        assertTrue(elem.isInIterable());
+        assertEquals(3, elem.getIndex().intValue());
+        assertNull(elem.getName());
+        assertFalse(propIter.hasNext());
+
+        String firstAuthorCompany = "authors[0].company";
+        path = PathImpl.createPathFromString(firstAuthorCompany);
+        propIter = path.iterator();
 
         assertTrue(propIter.hasNext());
         elem = propIter.next();
-        assertEquals("deliveryAddress", elem.getName());
         assertFalse(elem.isInIterable());
-        assertEquals(null, elem.getIndex());
+        assertEquals("authors", elem.getName());
 
+        assertTrue(propIter.hasNext());
+        elem = propIter.next();
+        assertTrue(elem.isInIterable());
+        assertEquals(0, elem.getIndex().intValue());
+        assertEquals("company", elem.getName());
         assertFalse(propIter.hasNext());
     }
 

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagerImpl.java?rev=1065828&r1=1065827&r2=1065828&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagerImpl.java (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagerImpl.java Mon Jan 31 22:14:53 2011
@@ -271,6 +271,7 @@ final class DynamicMetaGraphManagerImpl 
                             mergeFeatures(targetProperty, sourceProperty);
                         }
 
+                        // TODO try paring down data returned from readOnly implementation
                     }
                 }
 
@@ -321,11 +322,15 @@ final class DynamicMetaGraphManagerImpl 
             PathImpl path = PathImpl.createPathFromString(propertyPath);
             String propertyName;
             NodeImpl leafNode = path.getLeafNode();
-            if (!leafNode.isInIterable()) {
-            	propertyName = leafNode.getName();
-            	path.removeLeafNode();
-            } else {
+            if (leafNode == null || leafNode.getName() == null) {
                 propertyName = null;
+            } else {
+                propertyName = leafNode.getName();
+                if (leafNode.isInIterable()) {
+                    leafNode.setName(null);
+                } else {
+                    path.removeLeafNode();
+                }
             }
             FindType findType = new FindType(type);
             PathNavigation.navigate(path.toString(), findType);
@@ -420,6 +425,23 @@ final class DynamicMetaGraphManagerImpl 
 
         // iterate over the path; bail at the first null meta object:
         for (Path.Node node : path) {
+            if (node.isInIterable()) {
+                FeaturesCapable tip = property == null ? metaBean : property;
+                MetaContainer<?> container = tip.getFeature(META_CONTAINER);
+                if (container == null) {
+                    return null;
+                }
+                if (container.getIdType().equals(Integer.class)) {
+                    @SuppressWarnings("unchecked")
+                    MetaContainer<Integer> coll = (MetaContainer<Integer>) container;
+                    metaBean = coll.getMergedElement(node.getIndex());
+                } else {
+                    @SuppressWarnings("unchecked")
+                    MetaContainer<Object> map = (MetaContainer<Object>) container;
+                    metaBean = map.getMergedElement(node.getKey());
+                }
+                property = null;
+            }
             if (node.getName() != null) {
                 property = metaBean.getProperty(node.getName());
                 if (property == null) {
@@ -433,23 +455,6 @@ final class DynamicMetaGraphManagerImpl 
 
                 metaBean = property.getMetaBean();
             }
-            if (node.isInIterable()) {
-            	FeaturesCapable tip = property == null ? metaBean : property;
-            	MetaContainer<?> container = tip.getFeature(META_CONTAINER);
-            	if (container == null) {
-            		return null;
-            	}
-            	if (container.getIdType().equals(Integer.class)) {
-            		@SuppressWarnings("unchecked")
-            		MetaContainer<Integer> coll = (MetaContainer<Integer>) container;
-            		metaBean = coll.getMergedElement(node.getIndex());
-            	} else {
-            		@SuppressWarnings("unchecked")
-            		MetaContainer<Object> map = (MetaContainer<Object>) container;
-            		metaBean = map.getMergedElement(node.getKey());
-            	}
-            	property = null;
-            }
         }
         return metaBean;
     }
@@ -481,26 +486,6 @@ final class DynamicMetaGraphManagerImpl 
             }
             // handle the property:
             Path.Node node = nodes.remove(0);
-            if (node.getName() != null) {
-                PropertyAccess access = new PropertyAccess(rawType, node.getName());
-                if (bean != null) {
-                    bean = access.get(bean);
-                }
-                rawType = TypeUtils.getRawType(access.getJavaType(), type);
-                type = access.getJavaType();
-                if (node.isInIterable()) {
-                	//substitute a nameless indexed property node and repeat the loop:
-                	NodeImpl sub = new NodeImpl(null);
-                	sub.setInIterable(true);
-                	if (IndexedAccess.getJavaElementType(type) != null) {
-                		sub.setIndex(node.getIndex());
-                	} else if (KeyedAccess.getJavaElementType(type) != null) {
-                		sub.setKey(node.getKey());
-                	}
-                	nodes.add(0, sub);
-                	continue;
-                }
-            }
             if (node.isInIterable()) {
                 AccessStrategy access;
                 if (IndexedAccess.getJavaElementType(type) != null) {
@@ -517,6 +502,19 @@ final class DynamicMetaGraphManagerImpl 
                 }
                 rawType = TypeUtils.getRawType(access.getJavaType(), type);
                 type = access.getJavaType();
+                if (node.getName() != null) {
+                    //substitute a name-only node and repeat the loop:
+                    nodes.add(0, new NodeImpl(node.getName()));
+                    continue;
+                }
+            }
+            if (node.getName() != null) {
+                PropertyAccess access = new PropertyAccess(rawType, node.getName());
+                if (bean != null) {
+                    bean = access.get(bean);
+                }
+                rawType = TypeUtils.getRawType(access.getJavaType(), type);
+                type = access.getJavaType();
             }
         }
         return stack;

Modified: incubator/bval/sandbox/lang3-work/bval-tck/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-tck/pom.xml?rev=1065828&r1=1065827&r2=1065828&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-tck/pom.xml (original)
+++ incubator/bval/sandbox/lang3-work/bval-tck/pom.xml Mon Jan 31 22:14:53 2011
@@ -92,7 +92,7 @@
                 <dependency>
                     <groupId>org.hibernate.jsr303.tck</groupId>
                     <artifactId>jsr303-tck</artifactId>
-                    <version>1.0.4.GA</version>
+                    <version>1.0.5.Beta1</version>
                 </dependency>
                 <dependency>
                     <groupId>org.jboss.test-harness</groupId>