myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r920520 - in /myfaces/extensions/validator/branches/experimental/trunk_with_extval-83: core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/ validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/v...
Date Mon, 08 Mar 2010 21:24:48 GMT
Author: gpetracek
Date: Mon Mar  8 21:24:47 2010
New Revision: 920520

URL: http://svn.apache.org/viewvc?rev=920520&view=rev
Log:
EXTVAL-83 minor improvements

Modified:
    myfaces/extensions/validator/branches/experimental/trunk_with_extval-83/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultMappedConstraintSourceStorage.java
    myfaces/extensions/validator/branches/experimental/trunk_with_extval-83/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals.java

Modified: myfaces/extensions/validator/branches/experimental/trunk_with_extval-83/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultMappedConstraintSourceStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/experimental/trunk_with_extval-83/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultMappedConstraintSourceStorage.java?rev=920520&r1=920519&r2=920520&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/experimental/trunk_with_extval-83/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultMappedConstraintSourceStorage.java
(original)
+++ myfaces/extensions/validator/branches/experimental/trunk_with_extval-83/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultMappedConstraintSourceStorage.java
Mon Mar  8 21:24:47 2010
@@ -23,9 +23,11 @@
 import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
 import static org.apache.myfaces.extensions.validator.internal.UsageCategory.INTERNAL;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.util.ClassUtils;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.ResourceBundle;
 
 /**
  * @author Gerhard Petracek
@@ -36,36 +38,68 @@
 {
     protected final Log logger = LogFactory.getLog(getClass());
 
-    private Map<String, PropertyDetails> propertyDetailsMap = new HashMap<String,
PropertyDetails>();
+    private Map<String, Map<String, PropertyDetails>> propertyDetailsMap =
+            new HashMap<String, Map<String, PropertyDetails>>();
 
     public void storeMapping(Class originalClass, String originalProperty, PropertyDetails
targetPropertyDetails)
     {
+        if(targetPropertyDetails == null)
+        {
+            if(isFilteredClass(originalClass))
+            {
+                return;
+            }
+
+            Map<String, PropertyDetails> classMap = getMapForClass(originalClass);
+            classMap.put(originalProperty, null);
+            return;
+        }
+
         PropertyDetails propertyDetails = new PropertyDetails(targetPropertyDetails.getKey(),
                 targetPropertyDetails.getBaseObject(), targetPropertyDetails.getProperty());
 
-        this.propertyDetailsMap.put(createKey(originalClass, originalProperty), propertyDetails);
+        getMapForClass(originalClass).put(originalProperty, propertyDetails);
+    }
+
+    protected boolean isFilteredClass(Class originalClass)
+    {
+        return ResourceBundle.class.isAssignableFrom(originalClass);
     }
 
     public PropertyDetails getMappedConstraintSource(Class originalClass, String originalProperty)
     {
-        PropertyDetails foundEntry = this.propertyDetailsMap.get(createKey(originalClass,
originalProperty));
-        PropertyDetails result = null;
+        if(isFilteredClass(originalClass))
+        {
+            return null;
+        }
+
+        PropertyDetails foundEntry = getMapForClass(originalClass).get(originalProperty);
 
-        if(foundEntry != null)
+        if(foundEntry == null)
         {
-            result = new PropertyDetails(foundEntry.getKey(), foundEntry.getBaseObject(),
foundEntry.getProperty());
+            return null;
         }
-        
-        return result;
+
+        return new PropertyDetails(foundEntry.getKey(), foundEntry.getBaseObject(), foundEntry.getProperty());
     }
 
     public boolean containsMapping(Class originalClass, String originalProperty)
     {
-        return this.propertyDetailsMap.containsKey(createKey(originalClass, originalProperty));
+        if(isFilteredClass(originalClass))
+        {
+            //avoid scanning process
+            return true;
+        }
+        return getMapForClass(originalClass).containsKey(originalProperty);
     }
 
-    private String createKey(Class originalClass, String originalProperty)
+    private Map<String, PropertyDetails> getMapForClass(Class target)
     {
-        return originalClass.getName() + "#" + originalProperty;
+        String key = ClassUtils.getClassName(target);
+        if(!this.propertyDetailsMap.containsKey(key))
+        {
+            this.propertyDetailsMap.put(key, new HashMap<String, PropertyDetails>());
+        }
+        return this.propertyDetailsMap.get(key);
     }
 }
\ No newline at end of file

Modified: myfaces/extensions/validator/branches/experimental/trunk_with_extval-83/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/experimental/trunk_with_extval-83/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals.java?rev=920520&r1=920519&r2=920520&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/experimental/trunk_with_extval-83/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals.java
(original)
+++ myfaces/extensions/validator/branches/experimental/trunk_with_extval-83/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals.java
Mon Mar  8 21:24:47 2010
@@ -32,6 +32,7 @@
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.myfaces.extensions.validator.util.ClassUtils;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -47,6 +48,7 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.Set;
+import java.util.Collections;
 
 /**
  * @author Gerhard Petracek
@@ -112,6 +114,11 @@
         PropertyDetails constraintSourcePropertyDetails =
                 resolveMappedConstraintSourceFor(originalKey, baseBeanClass, propertyName);
 
+        if(constraintSourcePropertyDetails == null)
+        {
+            return Collections.emptySet();
+        }
+
         baseBeanClass = (Class) constraintSourcePropertyDetails.getBaseObject();
         propertyName = constraintSourcePropertyDetails.getProperty();
 
@@ -148,11 +155,18 @@
             return getMappedConstraintSource(baseBeanClass, property);
         }
 
+        //unproxy class
+        if(ClassUtils.isProxiedClass(baseBeanClass))
+        {
+            baseBeanClass = ClassUtils.tryToLoadClassForName(ClassUtils.getClassName(baseBeanClass));
+        }
+
         Class newBaseBeanClass = findMappedClass(baseBeanClass, property);
 
         //mapped source is ignored via @IgnoreConstraintSource or there is just no mapping
annotation at the target
         if(newBaseBeanClass == null)
         {
+            tryToCacheMappedConstraintSourceMetaData(baseBeanClass, property, null);
             return null;
         }
 



Mime
View raw message