bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r993404 - in /incubator/bval/trunk: bval-guice/src/main/java/org/apache/bval/guice/ bval-jsr303/src/main/java/org/apache/bval/jsr303/
Date Tue, 07 Sep 2010 15:57:38 GMT
Author: mbenson
Date: Tue Sep  7 15:57:38 2010
New Revision: 993404

URL: http://svn.apache.org/viewvc?rev=993404&view=rev
Log:
make it possible for the ApacheValidationProvider to build different ValidatorFactory classes
based on a custom configuration property and standardize on a compatible constructor signature
of (ConfigurationState)

Modified:
    incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidationProvider.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorConfiguration.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java

Modified: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java?rev=993404&r1=993403&r2=993404&view=diff
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java
(original)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java
Tue Sep  7 15:57:38 2010
@@ -19,7 +19,7 @@ package org.apache.bval.guice;
 import javax.validation.ValidatorFactory;
 import javax.validation.spi.ConfigurationState;
 
-import org.apache.bval.jsr303.ApacheValidatorFactory;
+import org.apache.bval.jsr303.ApacheValidationProvider;
 
 import com.google.inject.Inject;
 import com.google.inject.Provider;
@@ -33,12 +33,11 @@ import com.google.inject.Singleton;
 @Singleton
 final class ValidatorFactoryProvider implements Provider<ValidatorFactory> {
 
-    private final ApacheValidatorFactory validatorFactory;
+    private final ValidatorFactory validatorFactory;
 
     @Inject
     public ValidatorFactoryProvider(ConfigurationState configurationState) {
-        this.validatorFactory = new ApacheValidatorFactory();
-        this.validatorFactory.configure(configurationState);
+        this.validatorFactory = new ApacheValidationProvider().buildValidatorFactory(configurationState);
     }
 
     /**

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidationProvider.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidationProvider.java?rev=993404&r1=993403&r2=993404&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidationProvider.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidationProvider.java
Tue Sep  7 15:57:38 2010
@@ -20,23 +20,31 @@ package org.apache.bval.jsr303;
 
 import javax.validation.Configuration;
 import javax.validation.ValidationException;
+import javax.validation.ValidatorFactory;
 import javax.validation.spi.BootstrapState;
 import javax.validation.spi.ConfigurationState;
 import javax.validation.spi.ValidationProvider;
 
+import org.apache.bval.jsr303.util.SecureActions;
+import org.apache.commons.lang.ClassUtils;
+
 /**
- * Description: Implementation of {@link ValidationProvider} for jsr303 implementation of
- * the apache-validation framework.
+ * Description: Implementation of {@link ValidationProvider} for jsr303
+ * implementation of the apache-validation framework.
  * <p/>
  * <br/>
  * User: roman.stumm <br/>
  * Date: 29.10.2008 <br/>
  * Time: 14:45:41 <br/>
  */
-public class ApacheValidationProvider
-      implements ValidationProvider<ApacheValidatorConfiguration> {
+public class ApacheValidationProvider implements ValidationProvider<ApacheValidatorConfiguration>
{
+
+    private static final Class<?>[] VALIDATOR_FACTORY_CONSTRUCTOR_ARGS = new Class[]
{ ConfigurationState.class };
+
     /**
-     * Learn whether a particular builder class is suitable for this {@link ValidationProvider}.
+     * Learn whether a particular builder class is suitable for this
+     * {@link ValidationProvider}.
+     * 
      * @param builderClass
      * @return boolean suitability
      */
@@ -60,17 +68,24 @@ public class ApacheValidationProvider
 
     /**
      * {@inheritDoc}
+     * 
      * @throws javax.validation.ValidationException
-     *          if the ValidatorFactory cannot be built
+     *             if the ValidatorFactory cannot be built
      */
-    public ApacheValidatorFactory buildValidatorFactory(ConfigurationState configuration)
{
+    public ValidatorFactory buildValidatorFactory(ConfigurationState configuration) {
         try {
-            ApacheValidatorFactory factory = new ApacheValidatorFactory();
-            factory.configure(configuration);
-            return factory;
-        } catch (RuntimeException ex) {
+            String validatorFactoryClassname =
+                configuration.getProperties().get(ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME);
+            @SuppressWarnings("unchecked")
+            final Class<? extends ValidatorFactory> validatorFactoryClass =
+                validatorFactoryClassname == null ? ApacheValidatorFactory.class
+                    : (Class<? extends ValidatorFactory>) ClassUtils.getClass(validatorFactoryClassname);
+            return SecureActions.newInstance(validatorFactoryClass, VALIDATOR_FACTORY_CONSTRUCTOR_ARGS,
+                new Object[] { configuration });
+        } catch (ValidationException ex) {
+            throw ex;
+        } catch (Exception ex) {
             throw new ValidationException("error building ValidatorFactory", ex);
         }
     }
-
 }

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorConfiguration.java?rev=993404&r1=993403&r2=993404&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorConfiguration.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorConfiguration.java
Tue Sep  7 15:57:38 2010
@@ -19,16 +19,18 @@
 package org.apache.bval.jsr303;
 
 import javax.validation.Configuration;
+import javax.validation.ValidatorFactory;
+import javax.validation.spi.ConfigurationState;
 
 /**
- * Description: Uniquely identify apache Validation in the Bean Validation bootstrap
- * strategy. Also contains apache validation specific configurations<br/>
+ * Description: Uniquely identify Apache Bean Validation in the Bean Validation bootstrap
+ * strategy. Also contains Apache Bean Validation specific configurations<br/>
  */
 public interface ApacheValidatorConfiguration
       extends Configuration<ApacheValidatorConfiguration> {
 
     /**
-     * proprietary property keys for {@link ConfigurationImpl}  
+     * Proprietary property keys for {@link ConfigurationImpl}  
      */
     public interface Properties {
         /**
@@ -63,5 +65,12 @@ public interface ApacheValidatorConfigur
          * default: false
          */
          String TREAT_MAPS_LIKE_BEANS = "apache.bval.treat-maps-like-beans";
+
+        /**
+         * Specifies the classname of the {@link ValidatorFactory} to use: this
+         * class is presumed have a constructor that accepts a single
+         * {@link ConfigurationState} argument.
+         */
+         String VALIDATOR_FACTORY_CLASSNAME = "apache.bval.validator-factory-classname";
     }
 }

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java?rev=993404&r1=993403&r2=993404&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
Tue Sep  7 15:57:38 2010
@@ -96,12 +96,13 @@ public class ApacheValidatorFactory impl
     /**
      * Create a new ApacheValidatorFactory instance.
      */
-    public ApacheValidatorFactory() {
+    public ApacheValidatorFactory(ConfigurationState configurationState) {
         properties = new HashMap<String, String>();
         defaultSequences = new HashMap<Class<?>, Class<?>[]>();
         validAccesses = new HashMap<Class<?>, List<AccessStrategy>>();
         constraintMap =
             new HashMap<Class<?>, List<MetaConstraint<?, ? extends Annotation>>>();
+        configure(configurationState);
     }
 
     /**
@@ -110,7 +111,7 @@ public class ApacheValidatorFactory impl
      * 
      * @param configuration
      */
-    public void configure(ConfigurationState configuration) {
+    protected void configure(ConfigurationState configuration) {
         getProperties().putAll(configuration.getProperties());
         setMessageInterpolator(configuration.getMessageInterpolator());
         setTraversableResolver(configuration.getTraversableResolver());



Mime
View raw message