myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r762672 - in /myfaces/extensions/validator/trunk: component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/interceptor/ core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/con...
Date Tue, 07 Apr 2009 10:17:52 GMT
Author: gpetracek
Date: Tue Apr  7 10:17:51 2009
New Revision: 762672

URL: http://svn.apache.org/viewvc?rev=762672&view=rev
Log:
EXTVAL-39 basic mechanism

Modified:
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/interceptor/TrinidadRendererInterceptor.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/configuration/StaticConfigurationNames.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleStartupListener.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/ValidationInterceptorWithSkipValidationSupport.java

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/interceptor/TrinidadRendererInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/interceptor/TrinidadRendererInterceptor.java?rev=762672&r1=762671&r2=762672&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/interceptor/TrinidadRendererInterceptor.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/interceptor/TrinidadRendererInterceptor.java
Tue Apr  7 10:17:51 2009
@@ -26,7 +26,6 @@
 import org.apache.myfaces.extensions.validator.core.metadata.extractor.MetaDataExtractor;
 import org.apache.myfaces.extensions.validator.core.factory.FactoryNames;
 import org.apache.myfaces.extensions.validator.core.ExtValContext;
-import org.apache.myfaces.extensions.validator.core.CustomInformation;
 import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
 import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
@@ -39,8 +38,6 @@
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.List;
-import java.lang.annotation.Annotation;
 
 /**
  * @author Gerhard Petracek
@@ -110,7 +107,7 @@
                 }
 
                 if(Boolean.TRUE.equals(skipInitialization) && !metaData.isEmpty()
&&
-                        isSkipableValidationStrategy(validationStrategy.getClass()))
+                        ExtValUtils.isSkipableValidationStrategy(validationStrategy.getClass()))
                 {
                     metaData.put(CommonMetaDataKeys.SKIP_VALIDATION, true);
                 }
@@ -133,38 +130,4 @@
 
         return !(isReadOnly || isDisabled);
     }
-    
-    @SuppressWarnings({"unchecked"})
-    private boolean isSkipableValidationStrategy(Class<? extends ValidationStrategy>
validationStrategyClass)
-    {
-        String key = ExtValContext.getContext().getInformationProviderBean()
-                .get(CustomInformation.BASE_PACKAGE) + CommonMetaDataKeys.SKIP_VALIDATION.toUpperCase();
-        List<Class<? extends Annotation>> markerList =
-                (List<Class<? extends Annotation>>)ExtValContext.getContext().getGlobalProperty(key);
-
-        if(markerList == null)
-        {
-            return false;
-        }
-
-        for(Class<? extends Annotation> currentClass : markerList)
-        {
-            if(currentClass.isAnnotation())
-            {
-                if(validationStrategyClass.isAnnotationPresent(currentClass))
-                {
-                    return true;
-                }
-            }
-            else
-            {
-                if(currentClass.isAssignableFrom(validationStrategyClass))
-                {
-                    return true;
-                }
-            }
-        }
-
-        return false;
-    }
 }

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/configuration/StaticConfigurationNames.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/configuration/StaticConfigurationNames.java?rev=762672&r1=762671&r2=762672&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/configuration/StaticConfigurationNames.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/initializer/configuration/StaticConfigurationNames.java
Tue Apr  7 10:17:51 2009
@@ -30,5 +30,7 @@
 {
     META_DATA_TO_VALIDATION_STRATEGY_CONFIG,
     VALIDATION_STRATEGY_TO_MESSAGE_RESOLVER_CONFIG,
-    VALIDATION_STRATEGY_TO_META_DATA_TRANSFORMER_CONFIG
+    VALIDATION_STRATEGY_TO_META_DATA_TRANSFORMER_CONFIG,
+
+    SKIP_VALIDATION_SUPPORT_CONFIG
 }
\ No newline at end of file

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java?rev=762672&r1=762671&r2=762672&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
Tue Apr  7 10:17:51 2009
@@ -36,11 +36,16 @@
 import org.apache.myfaces.extensions.validator.core.metadata.extractor.MetaDataExtractor;
 import org.apache.myfaces.extensions.validator.core.metadata.extractor.ComponentMetaDataExtractorFactory;
 import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
+import org.apache.myfaces.extensions.validator.core.initializer.configuration.StaticConfigurationNames;
+import org.apache.myfaces.extensions.validator.core.initializer.configuration.StaticConfiguration;
+import org.apache.myfaces.extensions.validator.core.initializer.configuration.StaticConfigurationEntry;
 import org.apache.myfaces.extensions.validator.core.metadata.transformer.MetaDataTransformer;
 import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
 import org.apache.myfaces.extensions.validator.core.factory.FactoryNames;
 import org.apache.myfaces.extensions.validator.core.factory.NameMapperAwareFactory;
 import org.apache.myfaces.extensions.validator.core.factory.FacesMessageFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -48,7 +53,8 @@
 import javax.faces.application.FacesMessage;
 import java.util.Map;
 import java.util.MissingResourceException;
-
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * @author Gerhard Petracek
@@ -57,6 +63,8 @@
 @UsageInformation(UsageCategory.INTERNAL)
 public class ExtValUtils
 {
+    private static final Log LOGGER = LogFactory.getLog(ExtValUtils.class);
+
     private static final String JAVAX_FACES_REQUIRED = "javax.faces.component.UIInput.REQUIRED";
     private static final String JAVAX_FACES_REQUIRED_DETAIL = "javax.faces.component.UIInput.REQUIRED_detail";
 
@@ -339,4 +347,69 @@
         facesMessage.setSummary(facesRequiredMessage);
         facesMessage.setDetail(facesRequiredMessageDetail);
     }
+
+    public static boolean isSkipableValidationStrategy(Class<? extends ValidationStrategy>
targetClass)
+    {
+        for(Class currentClass : ExtValUtils.getSkipValidationSupportClassList())
+        {
+            if(ExtValUtils.isSkipValidationSupported(currentClass, targetClass))
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public static List<Class> getSkipValidationSupportClassList()
+    {
+        List<StaticConfiguration<String, String>> staticConfigurationList = ExtValContext.getContext()
+                .getStaticConfiguration(StaticConfigurationNames.SKIP_VALIDATION_SUPPORT_CONFIG);
+
+        List<Class> markerList = new ArrayList<Class>();
+
+        Class currentClass;
+        for(StaticConfiguration<String, String> currentEntry : staticConfigurationList)
+        {
+            for(StaticConfigurationEntry<String, String> currentConfigurationEntry
: currentEntry.getMapping())
+            {
+                currentClass = ClassUtils.tryToLoadClassForName(currentConfigurationEntry.getTarget());
+
+                if(currentClass != null)
+                {
+                    markerList.add(currentClass);
+                }
+                else
+                {
+                    if(LOGGER.isWarnEnabled())
+                    {
+                        LOGGER.warn("configuration entry provides an invalid entry: "
+                                + currentConfigurationEntry.getTarget());
+                    }
+                }
+            }
+        }
+
+        return markerList;
+    }
+
+    public static boolean isSkipValidationSupported(Class currentClass, Class targetClass)
+    {
+        if(currentClass.isAnnotation())
+        {
+            if(targetClass.isAnnotationPresent(currentClass))
+            {
+                return true;
+            }
+        }
+        else
+        {
+            if(currentClass.isAssignableFrom(targetClass))
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleStartupListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleStartupListener.java?rev=762672&r1=762671&r2=762672&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleStartupListener.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleStartupListener.java
Tue Apr  7 10:17:51 2009
@@ -22,21 +22,18 @@
 import org.apache.myfaces.extensions.validator.baseval.annotation.SkipValidationSupport;
 import org.apache.myfaces.extensions.validator.core.startup.AbstractStartupListener;
 import org.apache.myfaces.extensions.validator.core.ExtValContext;
-import org.apache.myfaces.extensions.validator.core.CustomInformation;
 import org.apache.myfaces.extensions.validator.core.metadata.CommonMetaDataKeys;
 import org.apache.myfaces.extensions.validator.core.interceptor.ValidationInterceptor;
 import org.apache.myfaces.extensions.validator.core.initializer.configuration.StaticResourceBundleConfiguration;
 import org.apache.myfaces.extensions.validator.core.initializer.configuration.StaticConfiguration;
 import org.apache.myfaces.extensions.validator.core.initializer.configuration.StaticConfigurationNames;
+import org.apache.myfaces.extensions.validator.core.initializer.configuration.StaticInMemoryConfiguration;
 import org.apache.myfaces.extensions.validator.internal.ToDo;
 import org.apache.myfaces.extensions.validator.internal.Priority;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
 import org.apache.myfaces.extensions.validator.crossval.recorder.CrossValidationUserInputRecorder;
 
-import java.util.List;
-import java.util.ArrayList;
-
 /**
  * @author Gerhard Petracek
  * @since 1.x.1
@@ -92,16 +89,13 @@
         ExtValContext.getContext().denyRendererInterceptor(ValidationInterceptor.class);
         ExtValContext.getContext().registerRendererInterceptor(new ValidationInterceptorWithSkipValidationSupport());
 
-        String key = ExtValContext.getContext().getInformationProviderBean()
-                    .get(CustomInformation.BASE_PACKAGE) + CommonMetaDataKeys.SKIP_VALIDATION.toUpperCase();
-        List<Class> markerList = (List<Class>)ExtValContext.getContext().getGlobalProperty(key);
+        StaticInMemoryConfiguration config = new StaticInMemoryConfiguration();
+        //it's just required to set the target
+        config.addMapping(CommonMetaDataKeys.SKIP_VALIDATION, SkipValidationSupport.class.getName());
 
-        if(markerList == null)
-        {
-            markerList = new ArrayList<Class>();
-            ExtValContext.getContext().addGlobalProperty(key, markerList);
-        }
-        
-        markerList.add(SkipValidationSupport.class);
+        ExtValContext.getContext()
+                .addStaticConfiguration(StaticConfigurationNames.SKIP_VALIDATION_SUPPORT_CONFIG,
config);
+
+        //config.addMapping(CommonMetaDataKeys.SKIP_VALIDATION, RequiredStrategy.class.getName());
     }
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/ValidationInterceptorWithSkipValidationSupport.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/ValidationInterceptorWithSkipValidationSupport.java?rev=762672&r1=762671&r2=762672&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/ValidationInterceptorWithSkipValidationSupport.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/ValidationInterceptorWithSkipValidationSupport.java
Tue Apr  7 10:17:51 2009
@@ -24,8 +24,8 @@
 import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
 import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
 import org.apache.myfaces.extensions.validator.core.interceptor.ValidationInterceptor;
-import org.apache.myfaces.extensions.validator.baseval.annotation.SkipValidationSupport;
 import org.apache.myfaces.extensions.validator.baseval.strategy.SkipValidationStrategy;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 
 import javax.faces.context.FacesContext;
 import javax.faces.component.UIComponent;
@@ -43,7 +43,7 @@
                                      ValidationStrategy validationStrategy,
                                      MetaDataEntry metaDataEntry)
     {
-        if(validationStrategy.getClass().isAnnotationPresent(SkipValidationSupport.class))
+        if(ExtValUtils.isSkipableValidationStrategy(validationStrategy.getClass()))
         {
             Boolean skipValidation = metaDataEntry.getProperty(
                 PropertyInformationKeys.SKIP_VALIDATION, Boolean.class);



Mime
View raw message