incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1128504 - in /incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic: extval-shared/ extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/ extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/spi/ extval20/src/main...
Date Fri, 27 May 2011 23:03:58 GMT
Author: mbenson
Date: Fri May 27 23:03:58 2011
New Revision: 1128504

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

Added:
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/spi/DynamicValidatorContextProvider.java
      - copied, changed from r1126537, incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/spi/ValidatorContextProvider.java
Removed:
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/spi/ValidatorContextProvider.java
Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/pom.xml
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidation.java
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationELHelper.java
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationModuleValidationInterceptor.java
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener.java
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicValidatorFactoryProxy.java
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/PathRecordingELResolver.java
    incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationELHelper20.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/pom.xml?rev=1128504&r1=1128503&r2=1128504&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/pom.xml (original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/pom.xml Fri May 27
23:03:58 2011
@@ -20,7 +20,8 @@
 <!--
 	Maven release plugin requires the project tag to be on a single line.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
     <groupId>org.apache.bval</groupId>
@@ -29,23 +30,73 @@
   </parent>
   <artifactId>bval-jsr303-dynamic-extval-shared</artifactId>
   <name>Apache Bean Validation :: bval-jsr303-dynamic-extval-shared</name>
-  <url>http://maven.apache.org</url>
   <dependencies>
     <dependency>
-    	<groupId>org.apache.bval</groupId>
-    	<artifactId>bval-jsr303-dynamic-provider</artifactId>
+      <groupId>org.apache.bval</groupId>
+      <artifactId>bval-jsr303-dynamic-provider</artifactId>
     </dependency>
     <dependency>
-    	<groupId>org.apache.myfaces.extensions.validator.validation-modules</groupId>
-    	<artifactId>myfaces-extval-bean-validation</artifactId>
+      <groupId>org.apache.myfaces.extensions.validator.validation-modules</groupId>
+      <artifactId>myfaces-extval-bean-validation</artifactId>
     </dependency>
     <dependency>
-        <groupId>org.apache.myfaces.core</groupId>
-        <artifactId>myfaces-api</artifactId>
+      <groupId>org.apache.myfaces.core</groupId>
+      <artifactId>myfaces-api</artifactId>
     </dependency>
     <dependency>
-        <groupId>de.odysseus.juel</groupId>
-        <artifactId>juel-api</artifactId>
+      <groupId>de.odysseus.juel</groupId>
+      <artifactId>juel-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.myfaces.extensions.validator.test-modules</groupId>
+      <artifactId>myfaces-extval-base-test-infrastructure</artifactId>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.myfaces.extensions.validator.test-modules</groupId>
+      <artifactId>myfaces-extval-bean-validation-tests</artifactId>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.myfaces.test</groupId>
+      <artifactId>myfaces-test12</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-proxy2-stub</artifactId>
     </dependency>
   </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <goals>
+              <goal>jar</goal>
+              <!-- goal>test-jar</goal -->
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <!-- plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin -->
+    </plugins>
+  </build>
 </project>

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidation.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidation.java?rev=1128504&r1=1128503&r2=1128504&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidation.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidation.java
Fri May 27 23:03:58 2011
@@ -37,7 +37,7 @@ class DynamicBeanValidation {
      * @throws IllegalStateException
      *             if > 1 found
      */
-    public static <T> T uniqueService(Class<T> serviceType) {
+    static <T> T uniqueService(Class<T> serviceType) {
         Iterator<T> iter = ServiceLoader.load(serviceType).iterator();
         try {
             return iter.next();
@@ -47,4 +47,5 @@ class DynamicBeanValidation {
             }
         }
     }
+
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationELHelper.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationELHelper.java?rev=1128504&r1=1128503&r2=1128504&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationELHelper.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationELHelper.java
Fri May 27 23:03:58 2011
@@ -27,7 +27,7 @@ import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
 
 import org.apache.bval.jsr303.dynamic.extval.spi.FacesContextAttributesFactory;
-import org.apache.commons.lang3.StringUtils;
+import org.apache.myfaces.extensions.validator.core.JsfProjectStage;
 import org.apache.myfaces.extensions.validator.core.el.AbstractELHelperFactory;
 import org.apache.myfaces.extensions.validator.core.el.DefaultELHelper;
 import org.apache.myfaces.extensions.validator.core.el.ELHelper;
@@ -43,6 +43,8 @@ public abstract class DynamicBeanValidat
     private static final String PROPERTY_DETAILS_CACHE_KEY =
         "org.apache.bval.jsr303.dynamic.extval.DynamicBeanValidationELHelper.Factory.propertyDetailsCache";
 
+    private final boolean projectStageDevelopment = JsfProjectStage.is(JsfProjectStage.Development);
+
     /**
      * {@link FacesContextAttributesFactory} instance used.
      */
@@ -116,12 +118,11 @@ public abstract class DynamicBeanValidat
                 return cache.get(expr);
             }
             PathRecordingELResolver elResolver =
-                new PathRecordingELResolver(facesContext.getELContext().getELResolver());
+                new PathRecordingELResolver(facesContext.getELContext().getELResolver(),
projectStageDevelopment);
             resolve(valueExpression, elResolver, facesContext);
-            String key = StringUtils.join(StringUtils.split(elResolver.getPath().toString(),
"[]."), '.');
             PathBasedPropertyDetails result =
-                new PathBasedPropertyDetails(key, elResolver.getBaseObject(), elResolver.getLeafProperty(),
-                    elResolver.getPath());
+                new PathBasedPropertyDetails(elResolver.getPath(), elResolver.getBaseObject(),
+                    elResolver.getProperty(), elResolver.getBeanValidationPath());
             cache.put(expr, result);
             return result;
         }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationModuleValidationInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationModuleValidationInterceptor.java?rev=1128504&r1=1128503&r2=1128504&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationModuleValidationInterceptor.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationModuleValidationInterceptor.java
Fri May 27 23:03:58 2011
@@ -16,17 +16,15 @@
  */
 package org.apache.bval.jsr303.dynamic.extval;
 
-import java.util.Iterator;
-
-import javax.el.ValueExpression;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
-import javax.validation.Path;
 
-import org.apache.bval.jsr303.util.NodeImpl;
-import org.apache.bval.jsr303.util.PathImpl;
+import org.apache.bval.jsr303.dynamic.extval.DynamicValidatorFactoryProxy.LocalizedFunction;
+import org.apache.bval.jsr303.dynamic.extval.DynamicValidatorFactoryProxy.LocalizedProcedure;
 import org.apache.myfaces.extensions.validator.beanval.BeanValidationModuleValidationInterceptor;
 import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
 
 /**
  * Dynamic {@code BeanValidationModuleValidationInterceptor}.
@@ -39,41 +37,51 @@ public class DynamicBeanValidationModule
      * {@inheritDoc}
      */
     @Override
-    protected void initComponentWithPropertyDetails(FacesContext facesContext, UIComponent
uiComponent,
-        PropertyDetails propertyDetails) {
-        Path path = null;
-        try {
-            if (propertyDetails instanceof PathBasedPropertyDetails) {
-                path = ((PathBasedPropertyDetails) propertyDetails).getPath();
-                processPath(facesContext, path);
-            }
-            super.initComponentWithPropertyDetails(facesContext, uiComponent, propertyDetails);
-        } finally {
-            if (path != null) {
-                DynamicValidatorFactoryProxy.INSTANCE.popPath();
+    protected void initComponentWithPropertyDetails(final FacesContext facesContext, final
UIComponent uiComponent,
+        final PropertyDetails propertyDetails) {
+        DynamicValidatorFactoryProxy.performLocalized(facesContext, propertyDetails, new
LocalizedProcedure() {
+
+            @Override
+            public void run() {
+                DynamicBeanValidationModuleValidationInterceptor.super.initComponentWithPropertyDetails(facesContext,
+                    uiComponent, propertyDetails);
+
             }
-        }
+        });
     }
 
-    private static void processPath(FacesContext facesContext, Path path) {
-        PathImpl subPath = PathImpl.create(null);
-        Iterator<Path.Node> nodes = path.iterator();
-        String bean = nodes.next().getName();
-        ValueExpression valueExpression =
-            facesContext.getApplication().getExpressionFactory()
-                .createValueExpression(facesContext.getELContext(), bean, Object.class);
-        Object rootBean = valueExpression.getValue(facesContext.getELContext());
-        while (nodes.hasNext()) {
-            subPath.addNode(nodes.next());
-        }
-        Path.Node leaf = subPath.removeLeafNode();
-        if (leaf.isInIterable()) {
-            if (leaf.getIndex() != null) {
-                subPath.addNode(NodeImpl.atIndex(leaf.getIndex()));
-            } else {
-                subPath.addNode(NodeImpl.atKey(leaf.getKey()));
-            }
-        }
-        DynamicValidatorFactoryProxy.INSTANCE.pushPath(rootBean.getClass(), subPath.toString());
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected boolean hasBeanValidationConstraints(final PropertyInformation propertyInformation)
{
+        return DynamicValidatorFactoryProxy.performLocalized(FacesContext.getCurrentInstance(),
+            propertyInformation.getInformation(PropertyInformationKeys.PROPERTY_DETAILS,
PropertyDetails.class),
+            new LocalizedFunction<Boolean>() {
+
+                public Boolean get() {
+                    return DynamicBeanValidationModuleValidationInterceptor.super
+                        .hasBeanValidationConstraints(propertyInformation);
+                }
+            });
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void processFieldValidation(final FacesContext facesContext, final UIComponent
uiComponent,
+        final Object convertedObject, final PropertyInformation propertyInformation) {
+        DynamicValidatorFactoryProxy.performLocalized(facesContext,
+            propertyInformation.getInformation(PropertyInformationKeys.PROPERTY_DETAILS,
PropertyDetails.class),
+            new LocalizedProcedure() {
+
+                @Override
+                public void run() {
+                    DynamicBeanValidationModuleValidationInterceptor.super.processFieldValidation(facesContext,
+                        uiComponent, convertedObject, propertyInformation);
+
+                }
+            });
     }
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener.java?rev=1128504&r1=1128503&r2=1128504&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationStartupListener.java
Fri May 27 23:03:58 2011
@@ -22,6 +22,7 @@ import org.apache.myfaces.extensions.val
 import org.apache.myfaces.extensions.validator.core.ExtValContext;
 import org.apache.myfaces.extensions.validator.core.el.AbstractELHelperFactory;
 import org.apache.myfaces.extensions.validator.core.factory.FactoryNames;
+import org.apache.myfaces.extensions.validator.core.interceptor.RendererInterceptor;
 import org.apache.myfaces.extensions.validator.core.startup.AbstractStartupListener;
 import org.apache.myfaces.extensions.validator.util.JsfUtils;
 
@@ -41,15 +42,20 @@ public class DynamicBeanValidationStartu
     protected void init() {
         final ExtValContext extValContext = ExtValContext.getContext();
 
-        extValContext.addGlobalProperty(ValidatorFactory.class.getName(), DynamicValidatorFactoryProxy.INSTANCE,
true);
+        extValContext.addGlobalProperty(ValidatorFactory.class.getName(), new DynamicValidatorFactoryProxy(),
true);
         DynamicBeanValidationELHelper.Factory<?> elHelperFactory =
             DynamicBeanValidation.uniqueService(DynamicBeanValidationELHelper.Factory.class);
         extValContext.getFactoryFinder().getFactory(FactoryNames.EL_HELPER_FACTORY, AbstractELHelperFactory.class)
             .setCustomELHelperFactory(elHelperFactory);
         JsfUtils.registerPhaseListener(elHelperFactory);
 
-        extValContext.denyRendererInterceptor(BeanValidationModuleValidationInterceptor.class);
-        extValContext.registerRendererInterceptor(new DynamicBeanValidationModuleValidationInterceptor());
+        swap(extValContext, BeanValidationModuleValidationInterceptor.class,
+            new DynamicBeanValidationModuleValidationInterceptor());
     }
 
+    private <R extends RendererInterceptor, S extends R> void swap(ExtValContext extValContext,
+        Class<R> rendererInterceptorType, S replacement) {
+        extValContext.denyRendererInterceptor(rendererInterceptorType);
+        extValContext.registerRendererInterceptor(replacement);
+    }
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicValidatorFactoryProxy.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicValidatorFactoryProxy.java?rev=1128504&r1=1128503&r2=1128504&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicValidatorFactoryProxy.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicValidatorFactoryProxy.java
Fri May 27 23:03:58 2011
@@ -16,8 +16,14 @@
  */
 package org.apache.bval.jsr303.dynamic.extval;
 
-import java.util.ServiceLoader;
+import java.util.Iterator;
 
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.Path;
+import javax.validation.TraversableResolver;
 import javax.validation.Validator;
 import javax.validation.ValidatorContext;
 import javax.validation.ValidatorFactory;
@@ -25,8 +31,11 @@ import javax.validation.ValidatorFactory
 import org.apache.bval.jsr303.ApacheFactoryContext;
 import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
 import org.apache.bval.jsr303.dynamic.NestedValidator;
-import org.apache.bval.jsr303.dynamic.extval.spi.ValidatorContextProvider;
+import org.apache.bval.jsr303.dynamic.extval.spi.DynamicValidatorContextProvider;
+import org.apache.bval.jsr303.util.NodeImpl;
+import org.apache.bval.jsr303.util.PathImpl;
 import org.apache.myfaces.extensions.validator.beanval.ValidatorFactoryProxy;
+import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
 
 /**
  * Forwards {@link ValidatorFactory} calls per {@link ValidatorContext}.
@@ -34,25 +43,99 @@ import org.apache.myfaces.extensions.val
  * @version $Rev$ $Date$
  */
 public class DynamicValidatorFactoryProxy extends ValidatorFactoryProxy {
+
     /**
-     * Statically available instance.
+     * Internal function interface.
      */
-    public static final DynamicValidatorFactoryProxy INSTANCE = new DynamicValidatorFactoryProxy();
+    interface LocalizedFunction<T> {
+        T get();
+    }
 
     /**
-     * Thread-registered validator delegate.
+     * LocalizedFunction with irrelevant return value.
      */
-    private static ThreadLocal<Validator> VALIDATOR = new ThreadLocal<Validator>();
+    static abstract class LocalizedProcedure implements LocalizedFunction<Object> {
+        public final Object get() {
+            run();
+            return null;
+        }
+
+        public abstract void run();
+    }
 
-    private final ValidatorContextProvider validatorContextProvider;
+    private static class NestingInfo {
+        final Class<?> rootType;
+        final String path;
+
+        /**
+         * Create a new NestingInfo instance.
+         * 
+         * @param rootType
+         * @param path
+         */
+        public NestingInfo(Class<?> rootType, String path) {
+            super();
+            this.rootType = rootType;
+            this.path = path;
+        }
+
+    }
+
+    private static class ValidatorContextProxy implements ValidatorContext {
+        private final DynamicValidatorContext delegate;
+
+        /**
+         * Create a new ValidatorContextProxy instance.
+         * 
+         * @param delegate
+         */
+        ValidatorContextProxy(DynamicValidatorContext delegate) {
+            super();
+            this.delegate = delegate;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public ValidatorContext messageInterpolator(MessageInterpolator messageInterpolator)
{
+            delegate.messageInterpolator(messageInterpolator);
+            return this;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public ValidatorContext traversableResolver(TraversableResolver traversableResolver)
{
+            delegate.traversableResolver(traversableResolver);
+            return this;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public ValidatorContext constraintValidatorFactory(ConstraintValidatorFactory factory)
{
+            delegate.constraintValidatorFactory(factory);
+            return this;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public Validator getValidator() {
+            NestingInfo nesting = NESTING_INFO.get();
+            if (nesting == null) {
+                return delegate.getValidator();
+            }
+            return new NestedValidator(delegate, nesting.rootType, nesting.path);
+        }
 
-    /**
-     * Create a new DynamicValidatorFactoryProxy instance.
-     */
-    private DynamicValidatorFactoryProxy() {
-        validatorContextProvider = ServiceLoader.load(ValidatorContextProvider.class).iterator().next();
     }
 
+    private static ThreadLocal<NestingInfo> NESTING_INFO = new ThreadLocal<NestingInfo>();
+
+    private static final DynamicValidatorContextProvider DYNAMIC_VALIDATOR_CONTEXT_PROVIDER
= DynamicBeanValidation
+        .uniqueService(DynamicValidatorContextProvider.class);
+
     /**
      * {@inheritDoc}
      */
@@ -70,7 +153,7 @@ public class DynamicValidatorFactoryProx
      */
     @Override
     public ValidatorContext usingContext() {
-        return validatorContextProvider.get();
+        return new ValidatorContextProxy(DYNAMIC_VALIDATOR_CONTEXT_PROVIDER.get().customizable());
     }
 
     /**
@@ -78,24 +161,56 @@ public class DynamicValidatorFactoryProx
      */
     @Override
     public Validator getValidator() {
-        Validator result = VALIDATOR.get();
-        return result == null ? usingContext().getValidator() : result;
+        return usingContext().getValidator();
     }
 
     /**
-     * Register a {@code ThreadLocal} {@code NestedValidator}.
+     * Perform a localized operation in context.
      * 
-     * @param rootBean
-     * @param path
-     */
-    void pushPath(Class<?> rootType, String path) {
-        VALIDATOR.set(new NestedValidator(((DynamicValidatorContext) usingContext()), rootType,
path));
+     * @param <T>
+     * @param facesContext
+     * @param propertyDetails
+     * @param operation
+     * @return operation result
+     */
+    static <T> T performLocalized(FacesContext facesContext, PropertyDetails propertyDetails,
+        LocalizedFunction<T> operation) {
+        Path path = null;
+        try {
+            if (propertyDetails instanceof PathBasedPropertyDetails) {
+                path = ((PathBasedPropertyDetails) propertyDetails).getPath();
+                pushPath(facesContext, path);
+            }
+            return operation.get();
+        } finally {
+            if (path != null) {
+                NESTING_INFO.remove();
+            }
+        }
     }
 
-    /**
-     * Deregister any {@code ThreadLocal} {@code NestedValidator}.
-     */
-    void popPath() {
-        VALIDATOR.remove();
+    private static void pushPath(FacesContext facesContext, Path path) {
+        PathImpl subPath = PathImpl.create(null);
+        Iterator<Path.Node> nodes = path.iterator();
+        ValueExpression valueExpression =
+            facesContext
+                .getApplication()
+                .getExpressionFactory()
+                .createValueExpression(facesContext.getELContext(), String.format("#{%s}",
nodes.next().getName()),
+                    Object.class);
+        Object rootBean = valueExpression.getValue(facesContext.getELContext());
+        while (nodes.hasNext()) {
+            subPath.addNode(nodes.next());
+        }
+        Path.Node leaf = subPath.removeLeafNode();
+        if (leaf.isInIterable()) {
+            if (leaf.getIndex() != null) {
+                subPath.addNode(NodeImpl.atIndex(leaf.getIndex()));
+            } else {
+                subPath.addNode(NodeImpl.atKey(leaf.getKey()));
+            }
+        }
+        NESTING_INFO.set(new NestingInfo(rootBean.getClass(), subPath.toString()));
     }
+
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/PathRecordingELResolver.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/PathRecordingELResolver.java?rev=1128504&r1=1128503&r2=1128504&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/PathRecordingELResolver.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/PathRecordingELResolver.java
Fri May 27 23:03:58 2011
@@ -22,12 +22,15 @@ import java.util.Map;
 
 import javax.el.ELContext;
 import javax.el.ELResolver;
+import javax.faces.context.FacesContext;
 import javax.validation.Path;
 
 import org.apache.bval.jsr303.util.NodeImpl;
 import org.apache.bval.jsr303.util.PathImpl;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.Validate;
 import org.apache.commons.lang3.mutable.MutableInt;
+import org.apache.myfaces.extensions.validator.core.el.ExtValELResolver;
 
 /**
  * Adapted from {@link org.apache.myfaces.extensions.validator.core.el.ExtValELResolver}
to get the direct property path
@@ -36,7 +39,7 @@ import org.apache.commons.lang3.mutable.
  * 
  * @version $Rev$ $Date$
  */
-public class PathRecordingELResolver extends ELResolver {
+public class PathRecordingELResolver extends ExtValELResolver {
     private final ELResolver wrapped;
     private final MutableInt depth = new MutableInt(0);
     private PathImpl path;
@@ -46,10 +49,11 @@ public class PathRecordingELResolver ext
 
     /**
      * Create a new PathRecordingELResolver instance.
+     * 
      * @param wrapped
      */
-    public PathRecordingELResolver(ELResolver wrapped) {
-        super();
+    public PathRecordingELResolver(ELResolver wrapped, boolean projectStageDevelopment) {
+        super(wrapped, projectStageDevelopment);
         Validate.notNull(wrapped);
         this.wrapped = wrapped;
         reset();
@@ -93,7 +97,7 @@ public class PathRecordingELResolver ext
     @Override
     public Object getValue(ELContext context, Object base, Object property) {
         Object value = wrapped.getValue(context, base, property);
-        handle(base, property, value);
+        handle(context, base, property, value);
         return value;
     }
 
@@ -103,13 +107,13 @@ public class PathRecordingELResolver ext
     @Override
     public void setValue(ELContext context, Object base, Object property, Object value) {
         Validate.isTrue(base == tip);
-        handle(base, property, value);
+        handle(context, base, property, value);
         context.setPropertyResolved(true);
         baseObject = base;
         leafProperty = property.toString();
     }
 
-    private void handle(Object base, Object property, Object value) {
+    private void handle(ELContext context, Object base, Object property, Object value) {
         // look for nested reads against tip:
         if (value == tip) {
             if (base == value) {
@@ -129,7 +133,10 @@ public class PathRecordingELResolver ext
             tip = value;
             if (base != null) {
                 if (base instanceof Iterable || base.getClass().isArray()) {
-                    path.addNode(NodeImpl.atIndex(Integer.valueOf(((Number) property).intValue())));
+                    Integer index =
+                        (Integer) ((FacesContext) context.getContext(FacesContext.class)).getApplication()
+                            .getExpressionFactory().coerceToType(property, Integer.class);
+                    path.addNode(NodeImpl.atIndex(index));
                     return;
                 }
                 if (base instanceof Map) {
@@ -142,20 +149,18 @@ public class PathRecordingELResolver ext
     }
 
     /**
-     * Get the baseObject.
-     * 
-     * @return Object
+     * {@inheritDoc}
      */
+    @Override
     public Object getBaseObject() {
         return baseObject;
     }
 
     /**
-     * Get the leafProperty.
-     * 
-     * @return String
+     * {@inheritDoc}
      */
-    public String getLeafProperty() {
+    @Override
+    public String getProperty() {
         return leafProperty;
     }
 
@@ -164,11 +169,19 @@ public class PathRecordingELResolver ext
      * 
      * @return Path
      */
-    public Path getPath() {
+    public Path getBeanValidationPath() {
         return PathImpl.copy(path);
     }
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getPath() {
+        return StringUtils.join(StringUtils.split(path.toString(), "[]."), '.');
+    }
+
+    /**
      * Reset this {@code PathRecordingELResolver}.
      */
     public void reset() {

Copied: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/spi/DynamicValidatorContextProvider.java
(from r1126537, incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/spi/ValidatorContextProvider.java)
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/spi/DynamicValidatorContextProvider.java?p2=incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/spi/DynamicValidatorContextProvider.java&p1=incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/spi/ValidatorContextProvider.java&r1=1126537&r2=1128504&rev=1128504&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/spi/ValidatorContextProvider.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval-shared/src/main/java/org/apache/bval/jsr303/dynamic/extval/spi/DynamicValidatorContextProvider.java
Fri May 27 23:03:58 2011
@@ -20,14 +20,16 @@ package org.apache.bval.jsr303.dynamic.e
 
 import javax.validation.ValidatorContext;
 
+import org.apache.bval.jsr303.dynamic.DynamicValidatorContext;
+
 /**
  * Specifies the interface to retrieve the correct {@link ValidatorContext}.
  */
-public interface ValidatorContextProvider {
+public interface DynamicValidatorContextProvider {
     /**
-     * Get the provided {@link ValidatorContext}.
+     * Get the provided {@link DynamicValidatorContext}.
      * 
-     * @return ValidatorContext
+     * @return DynamicValidatorContext
      */
-    ValidatorContext get();
+    DynamicValidatorContext get();
 }

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationELHelper20.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationELHelper20.java?rev=1128504&r1=1128503&r2=1128504&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationELHelper20.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303-dynamic/extval20/src/main/java/org/apache/bval/jsr303/dynamic/extval/DynamicBeanValidationELHelper20.java
Fri May 27 23:03:58 2011
@@ -58,7 +58,7 @@ public class DynamicBeanValidationELHelp
             valueExpression.setValue(contextWrapper, null);
             Object baseObject = elResolver.getBaseObject();
             if (baseObject instanceof CompositeComponentExpressionHolder) {
-                expr = ((CompositeComponentExpressionHolder) baseObject).getExpression(elResolver.getLeafProperty());
+                expr = ((CompositeComponentExpressionHolder) baseObject).getExpression(elResolver.getProperty());
                 elResolver.reset();
                 continue;
             }



Mime
View raw message