incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1128505 - in /incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src: main/java/org/apache/bval/jsr303/dynamic/ test/java/org/apache/bval/jsr303/dynamic/
Date Fri, 27 May 2011 23:04:47 GMT
Author: mbenson
Date: Fri May 27 23:04:47 2011
New Revision: 1128505

URL: http://svn.apache.org/viewvc?rev=1128505&view=rev
Log:
finish/refactor basic dynamic bean validation extval validation integration

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorContext.java
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/NestedValidator.java
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/NestedValidatorTest.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorContext.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorContext.java?rev=1128505&r1=1128504&r2=1128505&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorContext.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorContext.java
Fri May 27 23:04:47 2011
@@ -80,7 +80,19 @@ public class DynamicValidatorContext ext
 
     }
 
-    private final DynamicMetaGraphManagerImpl metaGraphManager;
+    private static class CustomizableContext extends DynamicValidatorContext {
+
+        /**
+         * Create a new NestedContext instance.
+         * 
+         * @param factory
+         * @param metaBeanFinder
+         */
+        CustomizableContext(DynamicValidatorFactory factory, MetaBeanFinder metaBeanFinder)
{
+            super(factory, metaBeanFinder);
+        }
+
+    }
 
     /**
      * Create a new {@link DynamicValidatorContext} instance.
@@ -89,7 +101,16 @@ public class DynamicValidatorContext ext
      */
     public DynamicValidatorContext(DynamicValidatorFactory validatorFactory) {
         super(validatorFactory);
-        this.metaGraphManager = ((DynamicMetaBeanFinder) getMetaBeanFinder()).metaGraphManager;
+    }
+
+    /**
+     * Create a new DynamicValidatorContext instance.
+     * 
+     * @param factory
+     * @param metaBeanFinder
+     */
+    protected DynamicValidatorContext(DynamicValidatorFactory factory, MetaBeanFinder metaBeanFinder)
{
+        super(factory, metaBeanFinder);
     }
 
     /**
@@ -120,28 +141,28 @@ public class DynamicValidatorContext ext
      * @return whether applying the specified annotation resulted in a change
      */
     public boolean constrain(Class<?> beanType, String propertyPath, Annotation annotation)
{
-        return metaGraphManager.constrain(beanType, propertyPath, annotation);
+        return getDynamicMetaBeanFinder().metaGraphManager.constrain(beanType, propertyPath,
annotation);
     }
 
     /**
      * {@inheritDoc}
      */
     public DynamicMetaGraphManager.Interface writable() {
-        return metaGraphManager.writable();
+        return getDynamicMetaBeanFinder().metaGraphManager.writable();
     }
 
     /**
      * {@inheritDoc}
      */
     public DynamicMetaGraphManager.Interface readOnly() {
-        return metaGraphManager.readOnly();
+        return getDynamicMetaBeanFinder().metaGraphManager.readOnly();
     }
 
     /**
      * {@inheritDoc}
      */
     public void clear() {
-        metaGraphManager.clear();
+        getDynamicMetaBeanFinder().metaGraphManager.clear();
     }
 
     /**
@@ -153,6 +174,16 @@ public class DynamicValidatorContext ext
     }
 
     /**
+     * Get a customizable copy of this context; i.e. with the same backing store, but permitting
the customizations of
+     * the {@code ValidatorContext} interface.
+     * 
+     * @return DynamicValidatorContext
+     */
+    public DynamicValidatorContext customizable() {
+        return new CustomizableContext(getFactory(), getMetaBeanFinder());
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override
@@ -160,4 +191,12 @@ public class DynamicValidatorContext ext
         return new DynamicMetaBeanFinder(getFactory().metaBeanFinder);
     }
 
+    /**
+     * Get this {@code DynamicValidatorContext}'s {@code DynamicMetaBeanFinder}.
+     * 
+     * @return DynamicMetaBeanFinder
+     */
+    protected DynamicMetaBeanFinder getDynamicMetaBeanFinder() {
+        return (DynamicMetaBeanFinder) getMetaBeanFinder();
+    }
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/NestedValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/NestedValidator.java?rev=1128505&r1=1128504&r2=1128505&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/NestedValidator.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/main/java/org/apache/bval/jsr303/dynamic/NestedValidator.java
Fri May 27 23:04:47 2011
@@ -25,12 +25,14 @@ import javax.validation.metadata.BeanDes
 
 import org.apache.bval.DynamicMetaBean;
 import org.apache.bval.jsr303.GroupValidationContext;
+import org.apache.bval.jsr303.UnknownPropertyException;
 import org.apache.bval.jsr303.util.PathImpl;
 import org.apache.bval.jsr303.util.PathNavigation;
 import org.apache.bval.jsr303.util.ValidationContextTraversal;
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.model.MetaProperty;
 import org.apache.bval.util.AccessStrategy;
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.Validate;
 
@@ -88,42 +90,51 @@ public class NestedValidator extends Dyn
      */
     protected GroupValidationContext createContext(MetaBean metaBean, final Object object,
Class objectClass,
         Class... groups) {
-        if (StringUtils.isEmpty(path)) {
-            return super.createContext(metaBean, object, objectClass, groups);
-        }
-        GroupValidationContext result = super.createContext(rootBean, null, rootBean.getBeanClass(),
groups);
-        ValidationContextTraversal validationContextTraversal = createValidationContextTraversal(result);
-        PathNavigation.navigate(path, validationContextTraversal);
-        final MetaProperty prop = result.getMetaProperty();
-        if (prop != null) {
-            result.moveDown(prop, new AccessStrategy() {
-
-                @Override
-                public String getPropertyName() {
-                    return prop.getName();
-                }
-
-                @Override
-                public Type getJavaType() {
-                    return prop.getType();
+        if (StringUtils.isNotEmpty(path)) {
+            try {
+                GroupValidationContext result = super.createContext(rootBean, null, rootBean.getBeanClass(),
groups);
+                ValidationContextTraversal validationContextTraversal = createValidationContextTraversal(result);
+                PathNavigation.navigate(path, validationContextTraversal);
+                final MetaProperty prop = result.getMetaProperty();
+                if (prop != null) {
+                    if (prop.getMetaBean() == null) {
+                        // should we do this here, or is there a better place?
+                        prop.setMetaBean(new DynamicMetaBean(getMetaBeanFinder()));
+                    }
+                    result.moveDown(prop, new AccessStrategy() {
+
+                        @Override
+                        public String getPropertyName() {
+                            return prop.getName();
+                        }
+
+                        @Override
+                        public Type getJavaType() {
+                            return prop.getType();
+                        }
+
+                        @Override
+                        public ElementType getElementType() {
+                            return ElementType.LOCAL_VARIABLE;
+                        }
+
+                        @Override
+                        public Object get(Object arg0) {
+                            return object;
+                        }
+                    });
+                } else {
+                    result.setBean(object);
                 }
-
-                @Override
-                public ElementType getElementType() {
-                    return ElementType.LOCAL_VARIABLE;
+                if (result.getMetaBean() instanceof DynamicMetaBean) {
+                    result.setMetaBean(((DynamicMetaBean) result.getMetaBean()).resolveMetaBean(ObjectUtils
+                        .defaultIfNull(object, objectClass)));
                 }
+                return result;
+            } catch (UnknownPropertyException e) {
 
-                @Override
-                public Object get(Object arg0) {
-                    return object;
-                }
-            });
-        } else {
-            result.setBean(object);
-        }
-        if (result.getMetaBean() instanceof DynamicMetaBean) {
-            result.setMetaBean(((DynamicMetaBean) result.getMetaBean()).resolveMetaBean(object));
+            }
         }
-        return result;
+        return super.createContext(metaBean, object, objectClass, groups);
     }
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/NestedValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/NestedValidatorTest.java?rev=1128505&r1=1128504&r2=1128505&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/NestedValidatorTest.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/provider/src/test/java/org/apache/bval/jsr303/dynamic/NestedValidatorTest.java
Fri May 27 23:04:47 2011
@@ -19,7 +19,6 @@ package org.apache.bval.jsr303.dynamic;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.beans.PropertyDescriptor;
 import java.util.ArrayList;
 import java.util.Locale;
 import java.util.Set;
@@ -29,7 +28,6 @@ import javax.validation.Validation;
 import javax.validation.Validator;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Pattern;
-import javax.validation.metadata.BeanDescriptor;
 
 import org.apache.bval.jsr303.ApacheValidationProvider;
 import org.apache.bval.jsr303.ApacheValidatorConfiguration;



Mime
View raw message