bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r981299 - in /incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice: ValidateMethodInterceptor.java ValidatorProvider.java
Date Sun, 01 Aug 2010 19:56:15 GMT
Author: simonetripodi
Date: Sun Aug  1 19:56:15 2010
New Revision: 981299

URL: http://svn.apache.org/viewvc?rev=981299&view=rev
Log:
Validator reference not cached in the Interceptor, according to spec 4.1

    "Validator API:
    It is recommended to leave the caching of Validator instances to the
	ValidatorFactory. Validator implementations are thread-safe."

No needs to keep ValidatorProvider as public

Modified:
    incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java
    incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java

Modified: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java?rev=981299&r1=981298&r2=981299&view=diff
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java
(original)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java
Sun Aug  1 19:56:15 2010
@@ -39,18 +39,18 @@ import com.google.inject.Inject;
 public final class ValidateMethodInterceptor implements MethodInterceptor {
 
     /**
-     * The Validator reference.
+     * The {@link ValidatorProvider} reference.
      */
     @Inject
-    private Validator validator;
+    private ValidatorProvider validatorProvider;
 
     /**
-     * Sets the Validator reference.
+     * Sets the {@link ValidatorProvider} reference.
      *
-     * @param validator the Validator reference.
+     * @param validatorProvider the {@link ValidatorProvider} reference.
      */
-    public void setValidator(Validator validator) {
-        this.validator = validator;
+    public void setValidatorProvider(ValidatorProvider validatorProvider) {
+        this.validatorProvider = validatorProvider;
     }
 
     /**
@@ -58,7 +58,9 @@ public final class ValidateMethodInterce
      */
     public Object invoke(MethodInvocation invocation) throws Throwable {
         Validate validate = invocation.getMethod().getAnnotation(Validate.class);
-        MethodValidator methodValidator = this.validator.unwrap(MethodValidator.class);
+
+        Validator validator = this.validatorProvider.get();
+        MethodValidator methodValidator = validator.unwrap(MethodValidator.class);
 
         Set<ConstraintViolation<?>> constraintViolations = new HashSet<ConstraintViolation<?>>();
         Class<?> clazz = invocation.getMethod().getDeclaringClass();

Modified: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java?rev=981299&r1=981298&r2=981299&view=diff
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java
(original)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java
Sun Aug  1 19:56:15 2010
@@ -29,12 +29,12 @@ import com.google.inject.Singleton;
  * @version $Id$
  */
 @Singleton
-public final class ValidatorProvider implements Provider<Validator> {
+final class ValidatorProvider implements Provider<Validator> {
 
     /**
      * The validator reference.
      */
-    private final Validator validator;
+    private final ValidatorFactory validatorFactory;
 
     /**
      * Build a new ValidatorProvider by ValidatorFactory.
@@ -43,14 +43,14 @@ public final class ValidatorProvider imp
      */
     @Inject
     public ValidatorProvider(ValidatorFactory validatorFactory) {
-        this.validator = validatorFactory.getValidator();
+        this.validatorFactory = validatorFactory;
     }
 
     /**
      * {@inheritDoc}
      */
     public Validator get() {
-        return this.validator;
+        return this.validatorFactory.getValidator();
     }
 
 }



Mime
View raw message