incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1080644 - in /incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic: DynamicClassValidator.java DynamicMetaGraphManagerImpl.java DynamicValidationState.java DynamicValidatorContext.java
Date Fri, 11 Mar 2011 16:31:13 GMT
Author: mbenson
Date: Fri Mar 11 16:31:12 2011
New Revision: 1080644

URL: http://svn.apache.org/viewvc?rev=1080644&view=rev
Log:
simplify and make static DynamicValidationState ThreadLocal management; the whole interface
is package-private so we can go for efficiency rather than worry about a sexy API

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicClassValidator.java
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagerImpl.java
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidationState.java
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorContext.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicClassValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicClassValidator.java?rev=1080644&r1=1080643&r2=1080644&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicClassValidator.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicClassValidator.java
Fri Mar 11 16:31:12 2011
@@ -60,7 +60,7 @@ public class DynamicClassValidator exten
         try {
             return super.validate(object, groups);
         } finally {
-            factoryContext().clearValidationState();
+            DynamicValidationState.CURRENT.remove();
         }
     }
 
@@ -72,7 +72,7 @@ public class DynamicClassValidator exten
         try {
             return super.validateProperty(object, propertyName, cascade, groups);
         } finally {
-            factoryContext().clearValidationState();
+            DynamicValidationState.CURRENT.remove();
         }
     }
 
@@ -84,7 +84,7 @@ public class DynamicClassValidator exten
         try {
             return super.validateValue(beanType, propertyName, value, cascade, groups);
         } finally {
-            factoryContext().clearValidationState();
+            DynamicValidationState.CURRENT.remove();
         }
     }
 
@@ -104,7 +104,7 @@ public class DynamicClassValidator exten
     protected <T> GroupValidationContext<T> createContext(MetaBean metaBean,
T object, Class<T> objectClass,
         Class<?>... groups) {
         GroupValidationContext<T> result = super.createContext(metaBean, object, objectClass,
groups);
-        factoryContext().register(new GroupValidationContextValidationState(object, result));
+        DynamicValidationState.CURRENT.set(new GroupValidationContextValidationState(object,
result));
         return result;
     }
 
@@ -180,7 +180,7 @@ public class DynamicClassValidator exten
                 }
                 return new DynamicPropertyDescriptorImpl(metaBean, propertyName, propertyType,
cascaded, validations);
             } finally {
-                factoryContext().clearValidationState();
+                DynamicValidationState.CURRENT.remove();
             }
 
         }

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=1080644&r1=1080643&r2=1080644&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
Fri Mar 11 16:31:12 2011
@@ -498,8 +498,6 @@ final class DynamicMetaGraphManagerImpl 
 
     }
 
-    final ThreadLocal<DynamicValidationState> currentValidationState = new ThreadLocal<DynamicValidationState>();
-
     private final Logger log = LoggerFactory.getLogger(getClass());
     private final Timestamped.Context timeContext = new Timestamped.Context();
 
@@ -541,7 +539,7 @@ final class DynamicMetaGraphManagerImpl 
                 final Object rootBean;
                 final MetaBean rootMetaBean;
 
-                DynamicValidationState validationState = currentValidationState.get();
+                DynamicValidationState validationState = DynamicValidationState.CURRENT.get();
                 if (validationState == null) {
                     initial = metaBeanFinder.findForClass(type);
                     path = PathImpl.create(null);
@@ -661,7 +659,7 @@ final class DynamicMetaGraphManagerImpl 
                 Class<?> beanType = findType.rawType;
 
                 FeaturesCapable result;
-                currentValidationState.set(new DynamicValidationStateBean(null, rootMetaBean,
path));
+                DynamicValidationState.CURRENT.set(new DynamicValidationStateBean(null, rootMetaBean,
path));
                 try {
                     result = getMetaBean(beanType);
                     if (propertyName != null) {
@@ -683,7 +681,7 @@ final class DynamicMetaGraphManagerImpl 
                     }
                     return (T) result;
                 } finally {
-                    currentValidationState.remove();
+                    DynamicValidationState.CURRENT.remove();
                 }
             }
         });

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidationState.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidationState.java?rev=1080644&r1=1080643&r2=1080644&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidationState.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidationState.java
Fri Mar 11 16:31:12 2011
@@ -25,6 +25,12 @@ import org.apache.bval.model.MetaBean;
  * @version $Rev$ $Date$
  */
 interface DynamicValidationState {
+
+    /**
+     * ThreadLocal to manage instances.
+     */
+    static final ThreadLocal<DynamicValidationState> CURRENT = new ThreadLocal<DynamicValidationState>();
+
     /**
      * Get the root bean being validated.
      * @return Object

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorContext.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorContext.java?rev=1080644&r1=1080643&r2=1080644&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorContext.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorContext.java
Fri Mar 11 16:31:12 2011
@@ -105,7 +105,7 @@ public class DynamicValidatorContext ext
      * 
      * @param beanType
      * @param constraintCollectionManipulator
-     * @return whether applying the specified annotation resulted in a change 
+     * @return whether applying the specified annotation resulted in a change
      */
     public final boolean constrain(Class<?> beanType, Annotation constraint) {
         return constrain(beanType, null, constraint);
@@ -117,7 +117,7 @@ public class DynamicValidatorContext ext
      * @param beanType
      * @param propertyPath
      * @param constraintCollectionManipulator
-     * @return whether applying the specified annotation resulted in a change 
+     * @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);
@@ -160,22 +160,4 @@ public class DynamicValidatorContext ext
         return new DynamicMetaBeanFinder(getFactory().metaBeanFinder);
     }
 
-    /**
-     * Register a {@link DynamicValidationState} instance to the current thread. Etiquette
requires the caller to clear
-     * the instance when no longer needed.
-     * 
-     * @param validationState
-     * @see #clearValidationState()
-     */
-    void register(DynamicValidationState validationState) {
-        metaGraphManager.currentValidationState.set(validationState);
-    }
-
-    /**
-     * Clear the registered {@link DynamicValidationState}.
-     */
-    void clearValidationState() {
-        metaGraphManager.currentValidationState.remove();
-    }
-
 }



Mime
View raw message