myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r832498 [1/2] - in /myfaces/extensions/validator/trunk: core/src/main/java/org/apache/myfaces/extensions/validator/core/ core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ core/src/main/java/org/apache/myfaces/exte...
Date Tue, 03 Nov 2009 18:24:54 GMT
Author: gpetracek
Date: Tue Nov  3 18:24:53 2009
New Revision: 832498

URL: http://svn.apache.org/viewvc?rev=832498&view=rev
Log:
addition to EXTVAL-44 and small refactorings

Added:
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/ExtValBeanValidationMetaDataInternals.java
Removed:
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/WebXmlParameter.java
Modified:
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ComponentInitializationAwareMetaDataExtractionInterceptor.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorage.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/JsfUtils.java
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/annotation/ModelValidation.java
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/annotation/extractor/DefaultGroupControllerScanningExtractor.java
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/interceptor/ExtValBeanValidationMetaDataExtractionInterceptor.java
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/AbstractBeanValidationVirtualValidationStrategyToMetaDataTransformerNameMapper.java
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/NotNullNameMapper.java
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/SizeNameMapper.java
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorage.java
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
    myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationSkipValidationEvaluator.java

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java (original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java Tue Nov  3 18:24:53 2009
@@ -129,10 +129,6 @@
     //there is nothing like DEACTIVATE_DEFAULT_VALIDATION_INTERCEPTOR
     //use ExtValContext.getContext().denyRendererInterceptor(...) within an extval-StartupListener
 
-    //to display all violations via the messages-tag or to use the new jsf 2.0 support
-    static final String ACTIVATE_MULTIPLE_VIOLATION_MESSAGES_PER_FIELD = WebXmlUtils
-        .getInitParameter("ACTIVATE_MULTIPLE_VIOLATION_MESSAGES_PER_FIELD");
-
     /*
      * spec parameters
      */

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ComponentInitializationAwareMetaDataExtractionInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ComponentInitializationAwareMetaDataExtractionInterceptor.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ComponentInitializationAwareMetaDataExtractionInterceptor.java (original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ComponentInitializationAwareMetaDataExtractionInterceptor.java Tue Nov  3 18:24:53 2009
@@ -22,10 +22,7 @@
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
 import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
 import org.apache.myfaces.extensions.validator.core.InvocationOrderSupport;
-import org.apache.myfaces.extensions.validator.core.storage.FacesInformationStorage;
-import org.apache.myfaces.extensions.validator.util.ExtValUtils;
-
-import javax.faces.event.PhaseId;
+import org.apache.myfaces.extensions.validator.util.JsfUtils;
 
 /**
  * @author Gerhard Petracek
@@ -37,21 +34,11 @@
 {
     public final void afterExtracting(PropertyInformation propertyInformation)
     {
-        if(isRenderResponsePhase())
+        if(JsfUtils.isRenderResponsePhase())
         {
             afterExtractingForComponentInitialization(propertyInformation);
         }
     }
 
     protected abstract void afterExtractingForComponentInitialization(PropertyInformation propertyInformation);
-
-    private boolean isRenderResponsePhase()
-    {
-        return PhaseId.RENDER_RESPONSE.equals(getFacesInformationStorage().getCurrentPhaseId());
-    }
-
-    private FacesInformationStorage getFacesInformationStorage()
-    {
-        return ExtValUtils.getStorage(FacesInformationStorage.class, FacesInformationStorage.class.getName());
-    }
 }

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java (original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java Tue Nov  3 18:24:53 2009
@@ -24,8 +24,6 @@
 import org.apache.myfaces.extensions.validator.core.InvocationOrder;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
-import org.apache.myfaces.extensions.validator.internal.ToDo;
-import org.apache.myfaces.extensions.validator.internal.Priority;
 import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -41,7 +39,6 @@
  */
 @InvocationOrder(90)
 @UsageInformation(UsageCategory.INTERNAL)
-@ToDo(value = Priority.HIGH, description = "check compatibility with bv-integration")
 public class ViolationSeverityValidationExceptionInterceptor implements ValidationExceptionInterceptor
 {
     protected final Log logger = LogFactory.getLog(getClass());

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorage.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorage.java (original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorage.java Tue Nov  3 18:24:53 2009
@@ -30,11 +30,14 @@
 import java.util.Map;
 import java.util.HashMap;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 
 /**
  * @author Gerhard Petracek
  * @since x.x.3
  */
+@ToDo(value = Priority.LOW, description = "optional parameter to deactivate sorting")
 @UsageInformation(UsageCategory.API)
 public class DefaultFacesMessageStorage implements FacesMessageStorage
 {
@@ -83,9 +86,63 @@
         }
     }
 
-    @ToDo(Priority.HIGH)
     private void sortFacesMessageHolderList(List<FacesMessageHolder> facesMessageHolderList)
     {
-        //sort severities
+        Collections.sort(facesMessageHolderList, new Comparator<FacesMessageHolder>() {
+            public int compare(FacesMessageHolder holder1, FacesMessageHolder holder2)
+            {
+                if(holder1.getFacesMessage().getSeverity() == null)
+                {
+                    return 1;
+                }
+                if(isSameSeverity(holder1, holder2))
+                {
+                    return compareMessageText(holder1.getFacesMessage(), holder2.getFacesMessage());
+                }
+
+                if(holder1.getFacesMessage().getSeverity().getOrdinal() >
+                        holder2.getFacesMessage().getSeverity().getOrdinal())
+                {
+                    return -1;
+                }
+                else
+                {
+                    return 1;
+                }
+            }
+
+            private int compareMessageText(FacesMessage facesMessage1, FacesMessage facesMessage2)
+            {
+                String text1 = facesMessage1.getSummary();
+                String text2 = facesMessage2.getSummary();
+
+                if(text1 == null)
+                {
+                    text1 = facesMessage1.getDetail();
+                }
+
+                if(text2 == null)
+                {
+                    text2 = facesMessage2.getDetail();
+                }
+
+                if(text1 == null)
+                {
+                    return 1;
+                }
+
+                if(text2 == null)
+                {
+                    return -1;
+                }
+
+                return text1.compareToIgnoreCase(text2);
+            }
+        });
+    }
+
+    private boolean isSameSeverity(FacesMessageHolder holder1, FacesMessageHolder holder2)
+    {
+        return holder1.getFacesMessage().getSeverity().equals(holder2.getFacesMessage().getSeverity());
     }
 }

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=832498&r1=832497&r2=832498&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 Nov  3 18:24:53 2009
@@ -563,7 +563,7 @@
         }
     }
 
-    @ToDo(value = Priority.HIGH, description = "is renaming ok?")
+    @ToDo(value = Priority.MEDIUM, description = "is renaming ok?")
     public static boolean executeGlobalBeforeValidationInterceptors(FacesContext facesContext,
                                                                     UIComponent uiComponent,
                                                                     Object convertedObject,
@@ -594,7 +594,7 @@
         return result;
     }
 
-    @ToDo(value = Priority.HIGH, description = "is renaming ok?")
+    @ToDo(value = Priority.MEDIUM, description = "is renaming ok?")
     public static void executeGlobalAfterValidationInterceptors(FacesContext facesContext,
                                                                 UIComponent uiComponent,
                                                                 Object convertedObject,

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/JsfUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/JsfUtils.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/JsfUtils.java (original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/util/JsfUtils.java Tue Nov  3 18:24:53 2009
@@ -20,11 +20,13 @@
 
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.core.storage.FacesInformationStorage;
 
 import javax.faces.FactoryFinder;
 import javax.faces.application.FacesMessage;
 import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseListener;
+import javax.faces.event.PhaseId;
 import javax.faces.lifecycle.Lifecycle;
 import javax.faces.lifecycle.LifecycleFactory;
 import java.util.Iterator;
@@ -80,4 +82,19 @@
 
         return ResourceBundle.getBundle(bundleName, facesContext.getViewRoot().getLocale());
     }
+
+    public static boolean isRenderResponsePhase()
+    {
+        return PhaseId.RENDER_RESPONSE.equals(getFacesInformationStorage().getCurrentPhaseId());
+    }
+
+    public static PhaseId getCurrentPhaseId()
+    {
+        return getFacesInformationStorage().getCurrentPhaseId();
+    }
+
+    private static FacesInformationStorage getFacesInformationStorage()
+    {
+        return ExtValUtils.getStorage(FacesInformationStorage.class, FacesInformationStorage.class.getName());
+    }
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java Tue Nov  3 18:24:53 2009
@@ -29,7 +29,6 @@
 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.beanval.util.BeanValidationUtils;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -130,11 +129,6 @@
         this.bviUtils.validate(facesContext, uiComponent, convertedObject, propertyInformation);
     }
 
-    protected boolean supportMultipleViolationsPerField()
-    {
-        return BeanValidationUtils.supportMultipleViolationsPerField();
-    }
-
     /*
      * e.g. extract groups for validation
      */

Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/annotation/ModelValidation.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/annotation/ModelValidation.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/annotation/ModelValidation.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/annotation/ModelValidation.java Tue Nov  3 18:24:53 2009
@@ -49,7 +49,7 @@
 
     boolean displayInline() default false;
 
-    @ToDo(value = Priority.HIGH, description = "support property chain syntax")
+    @ToDo(value = Priority.MEDIUM, description = "support property chain syntax")
     String[] validationTargets() default DEFAULT_TARGET;
 
     String message() default DEFAULT_MESSAGE;

Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/annotation/extractor/DefaultGroupControllerScanningExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/annotation/extractor/DefaultGroupControllerScanningExtractor.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/annotation/extractor/DefaultGroupControllerScanningExtractor.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/annotation/extractor/DefaultGroupControllerScanningExtractor.java Tue Nov  3 18:24:53 2009
@@ -47,12 +47,16 @@
         PropertyInformation propertyInformation = new DefaultPropertyInformation();
         propertyInformation.setInformation(PropertyInformationKeys.PROPERTY_DETAILS, propertyDetails);
 
-        /*
-         * find and add annotations
-         */
-        addPropertyAccessAnnotations(entityClass, propertyDetails.getProperty(), propertyInformation);
-        addFieldAccessAnnotations(entityClass, propertyDetails.getProperty(), propertyInformation);
+        findAndAddAnnotations(propertyInformation, propertyDetails, entityClass);
 
         return propertyInformation;
     }
+
+    private void findAndAddAnnotations(PropertyInformation propertyInformation,
+                                       PropertyDetails propertyDetails,
+                                       Class entityClass)
+    {
+        addPropertyAccessAnnotations(entityClass, propertyDetails.getProperty(), propertyInformation);
+        addFieldAccessAnnotations(entityClass, propertyDetails.getProperty(), propertyInformation);
+    }
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/interceptor/ExtValBeanValidationMetaDataExtractionInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/interceptor/ExtValBeanValidationMetaDataExtractionInterceptor.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/interceptor/ExtValBeanValidationMetaDataExtractionInterceptor.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/interceptor/ExtValBeanValidationMetaDataExtractionInterceptor.java Tue Nov  3 18:24:53 2009
@@ -20,21 +20,18 @@
 
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
-import org.apache.myfaces.extensions.validator.internal.ToDo;
-import org.apache.myfaces.extensions.validator.internal.Priority;
 import org.apache.myfaces.extensions.validator.core.interceptor.MetaDataExtractionInterceptor;
 import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
 import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
 import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
 import org.apache.myfaces.extensions.validator.core.ValidationModuleAware;
 import org.apache.myfaces.extensions.validator.core.InvocationOrder;
-import org.apache.myfaces.extensions.validator.core.storage.FacesInformationStorage;
 import org.apache.myfaces.extensions.validator.beanval.BeanValidationModuleKey;
 import org.apache.myfaces.extensions.validator.beanval.util.BeanValidationUtils;
 import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.myfaces.extensions.validator.util.JsfUtils;
 
 import javax.faces.component.UIComponent;
-import javax.faces.event.PhaseId;
 import java.util.Map;
 
 /**
@@ -72,7 +69,7 @@
      */
     private void processExtValBeanValidationMetaData(UIComponent uiComponent, PropertyDetails propertyDetails)
     {
-        if(isRenderResponsePhase())
+        if(JsfUtils.isRenderResponsePhase())
         {
             BeanValidationUtils.addMetaDataToContext(uiComponent, propertyDetails, false);
         }
@@ -82,17 +79,6 @@
         }
     }
 
-    @ToDo(value = Priority.MEDIUM, description = "move to util class")
-    private boolean isRenderResponsePhase()
-    {
-        return PhaseId.RENDER_RESPONSE.equals(getFacesInformationStorage().getCurrentPhaseId());
-    }
-
-    private FacesInformationStorage getFacesInformationStorage()
-    {
-        return ExtValUtils.getStorage(FacesInformationStorage.class, FacesInformationStorage.class.getName());
-    }
-
     public String[] getModuleKeys()
     {
         return new String[] {BeanValidationModuleKey.class.getName()};

Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/AbstractBeanValidationVirtualValidationStrategyToMetaDataTransformerNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/AbstractBeanValidationVirtualValidationStrategyToMetaDataTransformerNameMapper.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/AbstractBeanValidationVirtualValidationStrategyToMetaDataTransformerNameMapper.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/AbstractBeanValidationVirtualValidationStrategyToMetaDataTransformerNameMapper.java Tue Nov  3 18:24:53 2009
@@ -35,7 +35,7 @@
 {
     public final String createName(ValidationStrategy source)
     {
-        if(source instanceof BeanValidationVirtualValidationStrategy)
+        if(isBeanValidationStrategy(source))
         {
             BeanValidationVirtualValidationStrategy beanValidationAdapter =
                     (BeanValidationVirtualValidationStrategy)source;
@@ -45,6 +45,11 @@
         return null;
     }
 
+    private boolean isBeanValidationStrategy(ValidationStrategy source)
+    {
+        return source instanceof BeanValidationVirtualValidationStrategy;
+    }
+
     protected  abstract String createBeanValidationTransformerName(
             BeanValidationVirtualValidationStrategy validationStrategy);
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/NotNullNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/NotNullNameMapper.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/NotNullNameMapper.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/NotNullNameMapper.java Tue Nov  3 18:24:53 2009
@@ -38,10 +38,16 @@
 {
     protected String createBeanValidationTransformerName(BeanValidationVirtualValidationStrategy adapter)
     {
-        if(NotNull.class.getName().equals(adapter.getConstraintDescriptor().getAnnotation().annotationType().getName()))
+        if(isNotNullConstraint(adapter))
         {
             return NotNullMetaDataTransformer.class.getName();
         }
         return null;
     }
+
+    private boolean isNotNullConstraint(BeanValidationVirtualValidationStrategy adapter)
+    {
+        return NotNull.class.getName().equals(
+                adapter.getConstraintDescriptor().getAnnotation().annotationType().getName());
+    }
 }
\ No newline at end of file

Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/SizeNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/SizeNameMapper.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/SizeNameMapper.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/mapper/SizeNameMapper.java Tue Nov  3 18:24:53 2009
@@ -38,11 +38,17 @@
 {
     protected String createBeanValidationTransformerName(BeanValidationVirtualValidationStrategy adapter)
     {
-        if(Size.class.getName().equals(adapter.getConstraintDescriptor().getAnnotation().annotationType().getName()) &&
-                String.class.getName().equals(adapter.getElementClass().getName()))
+        if(isStringSizeConstraint(adapter))
         {
             return StringSizeMetaDataTransformer.class.getName();
         }
         return null;
     }
+
+    private boolean isStringSizeConstraint(BeanValidationVirtualValidationStrategy adapter)
+    {
+        return Size.class.getName().equals(
+                adapter.getConstraintDescriptor().getAnnotation().annotationType().getName()) &&
+                String.class.getName().equals(adapter.getElementClass().getName());
+    }
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorage.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorage.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorage.java Tue Nov  3 18:24:53 2009
@@ -44,14 +44,33 @@
 
     public void addModelValidationEntry(ModelValidationEntry modelValidationEntry)
     {
+        String clientId = getCurrentClientId(modelValidationEntry);
+
+        List<ModelValidationEntry> modelValidationEntryList = resolveModelValidationEntryList(
+                modelValidationEntry, clientId);
+
+        addModelValidationEntry(modelValidationEntryList, modelValidationEntry);
+    }
+
+    private String getCurrentClientId(ModelValidationEntry modelValidationEntry)
+    {
         String clientId = null;
 
         if(modelValidationEntry.getComponent() != null)
         {
             clientId = modelValidationEntry.getComponent().getClientId(FacesContext.getCurrentInstance());
-            this.componentsOfRequest.add(clientId);
+
+            if(!this.componentsOfRequest.contains(clientId))
+            {
+                this.componentsOfRequest.add(clientId);
+            }
         }
+        return clientId;
+    }
 
+    private List<ModelValidationEntry> resolveModelValidationEntryList(
+            ModelValidationEntry modelValidationEntry, String clientId)
+    {
         List<ModelValidationEntry> modelValidationEntryList =
                 this.modelValidationEntries.get(GroupUtils.getGroupKey(
                         modelValidationEntry.getViewId(), clientId));
@@ -62,7 +81,12 @@
             this.modelValidationEntries.put(GroupUtils.getGroupKey(
                     modelValidationEntry.getViewId(), clientId), modelValidationEntryList);
         }
+        return modelValidationEntryList;
+    }
 
+    private void addModelValidationEntry(
+            List<ModelValidationEntry> modelValidationEntryList, ModelValidationEntry modelValidationEntry)
+    {
         if(!modelValidationEntryList.contains(modelValidationEntry))
         {
             modelValidationEntryList.add(modelValidationEntry);
@@ -74,16 +98,24 @@
         String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
         List<ModelValidationEntry> result = new ArrayList<ModelValidationEntry>();
 
-        //add entries for specific components
+        addEntriesForComponents(viewId, result);
+
+        addEntriesForPage(viewId, result);
+
+        return result;
+    }
+
+    private void addEntriesForComponents(String viewId, List<ModelValidationEntry> result)
+    {
         for(String currentClientId : this.componentsOfRequest)
         {
             result.addAll(getModelValidationEntries(viewId, currentClientId));
         }
+    }
 
-        //add entries for the whole page
+    private void addEntriesForPage(String viewId, List<ModelValidationEntry> result)
+    {
         result.addAll(getModelValidationEntries(viewId));
-
-        return result;
     }
 
     private List<ModelValidationEntry> buildModelValidationEntryList(
@@ -145,7 +177,12 @@
             return resultListForPage;
         }
 
-        //merge results
+        return mergeResults(resultListForPage, resultListForComponent);
+    }
+
+    private List<ModelValidationEntry> mergeResults(
+            List<ModelValidationEntry> resultListForPage, List<ModelValidationEntry> resultListForComponent)
+    {
         List<ModelValidationEntry> mergedResult = new ArrayList<ModelValidationEntry>();
         mergedResult.addAll(resultListForPage);
         mergedResult.addAll(resultListForComponent);

Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java?rev=832498&r1=832497&r2=832498&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java Tue Nov  3 18:24:53 2009
@@ -20,35 +20,19 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.extensions.validator.beanval.ExtValBeanValidationContext;
-import org.apache.myfaces.extensions.validator.beanval.annotation.BeanValidation;
-import org.apache.myfaces.extensions.validator.beanval.annotation.ModelValidation;
-import org.apache.myfaces.extensions.validator.beanval.annotation.extractor.DefaultGroupControllerScanningExtractor;
-import org.apache.myfaces.extensions.validator.beanval.payload.ViolationSeverity;
 import org.apache.myfaces.extensions.validator.beanval.storage.ModelValidationEntry;
-import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
-import org.apache.myfaces.extensions.validator.core.validation.message.FacesMessageHolder;
-import org.apache.myfaces.extensions.validator.core.el.ELHelper;
-import org.apache.myfaces.extensions.validator.core.el.ValueBindingExpression;
-import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
 import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
-import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
-import org.apache.myfaces.extensions.validator.internal.Priority;
-import org.apache.myfaces.extensions.validator.internal.ToDo;
+import org.apache.myfaces.extensions.validator.core.validation.message.FacesMessageHolder;
 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.ReflectionUtils;
 
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.validator.ValidatorException;
 import javax.validation.ConstraintViolation;
-import javax.validation.Payload;
-import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 
@@ -60,14 +44,7 @@
 public class BeanValidationUtils
 {
     private static final Log LOG = LogFactory.getLog(BeanValidationUtils.class);
-    private static LabeledMessageInternals labeledMessageInternals = new LabeledMessageInternals();
-
-    @ToDo(value = Priority.HIGH, description = "use it - also in ModelValidationPhaseListener" +
-            "attention: only add one message per client id")
-    public static boolean supportMultipleViolationsPerField()
-    {
-        return "true".equalsIgnoreCase(WebXmlParameter.ACTIVATE_MULTIPLE_VIOLATION_MESSAGES_PER_FIELD);
-    }
+    private static ExtValBeanValidationMetaDataInternals bvmi = new ExtValBeanValidationMetaDataInternals(LOG);
 
     public static void addMetaDataToContext(
             UIComponent component, PropertyDetails propertyDetails, boolean processModelValidation)
@@ -81,413 +58,21 @@
         List<ModelValidationEntry> modelValidationEntryList = new ArrayList<ModelValidationEntry>();
         List<Class> restrictedGroupsForModelValidation = new ArrayList<Class>();
 
-        //extract bv-controller-annotation of
-
-        //first bean
-        processClass(firstBean,
-                foundGroupsForPropertyValidation,
-                restrictedGroupsForPropertyValidation,
-                modelValidationEntryList,
-                restrictedGroupsForModelValidation,
-                processModelValidation);
-
-        //first property
-        processFieldsAndProperties(key[0] + "." + key[1],
+        bvmi.extractExtValBeanValidationMetaData(propertyDetails,
+                processModelValidation,
+                key,
                 firstBean,
-                key[1],
-                foundGroupsForPropertyValidation,
-                restrictedGroupsForPropertyValidation,
-                modelValidationEntryList,
-                restrictedGroupsForModelValidation,
-                processModelValidation);
-
-        //base object (of target property)
-        processClass(propertyDetails.getBaseObject(),
                 foundGroupsForPropertyValidation,
                 restrictedGroupsForPropertyValidation,
                 modelValidationEntryList,
-                restrictedGroupsForModelValidation,
-                processModelValidation);
+                restrictedGroupsForModelValidation);
 
-        //last property
-        processFieldsAndProperties(
-                propertyDetails.getKey(),
-                propertyDetails.getBaseObject(),
-                propertyDetails.getProperty(),
+        bvmi.processExtValBeanValidationMetaData(component,
+                propertyDetails,
                 foundGroupsForPropertyValidation,
                 restrictedGroupsForPropertyValidation,
                 modelValidationEntryList,
-                restrictedGroupsForModelValidation,
-                processModelValidation);
-
-        ExtValBeanValidationContext extValBeanValidationContext = ExtValBeanValidationContext.getCurrentInstance();
-        String currentViewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
-
-        String clientId = component.getClientId(FacesContext.getCurrentInstance());
-
-        processFoundGroups(extValBeanValidationContext, currentViewId, clientId,
-                foundGroupsForPropertyValidation);
-
-        processRestrictedGroups(extValBeanValidationContext, currentViewId, clientId,
-                restrictedGroupsForPropertyValidation);
-
-        initModelValidation(extValBeanValidationContext, component, propertyDetails,
-                modelValidationEntryList, restrictedGroupsForModelValidation);
-    }
-
-    private static void processClass(Object objectToInspect,
-                                     List<Class> foundGroupsForPropertyValidation,
-                                     List<Class> restrictedGroupsForPropertyValidation,
-                                     List<ModelValidationEntry> modelValidationEntryList,
-                                     List<Class> restrictedGroupsForModelValidation,
-                                     boolean processModelValidation)
-    {
-        Class classToInspect = objectToInspect.getClass();
-        while (!Object.class.getName().equals(classToInspect.getName()))
-        {
-            transferGroupValidationInformationToFoundGroups(objectToInspect,
-                    foundGroupsForPropertyValidation,
-                    restrictedGroupsForPropertyValidation,
-                    modelValidationEntryList,
-                    restrictedGroupsForModelValidation,
-                    processModelValidation);
-
-            processInterfaces(objectToInspect.getClass(), objectToInspect,
-                    foundGroupsForPropertyValidation,
-                    restrictedGroupsForPropertyValidation,
-                    modelValidationEntryList,
-                    restrictedGroupsForModelValidation,
-                    processModelValidation);
-
-            classToInspect = classToInspect.getSuperclass();
-        }
-    }
-
-    private static void processFieldsAndProperties(String key,
-                                                   Object base,
-                                                   String property,
-                                                   List<Class> foundGroupsForPropertyValidation,
-                                                   List<Class> restrictedGroupsForPropertyValidation,
-                                                   List<ModelValidationEntry> modelValidationEntryList,
-                                                   List<Class> restrictedGroupsForModelValidation,
-                                                   boolean processModelValidation)
-    {
-        PropertyInformation propertyInformation = new DefaultGroupControllerScanningExtractor()
-                .extract(FacesContext.getCurrentInstance(), new PropertyDetails(key, base, property));
-
-        for (MetaDataEntry metaDataEntry : propertyInformation.getMetaDataEntries())
-        {
-            if (metaDataEntry.getValue() instanceof BeanValidation)
-            {
-                tryToProcessMetaData((BeanValidation) metaDataEntry.getValue(),
-                        tryToCreateNewTarget(base, property),
-                        foundGroupsForPropertyValidation,
-                        restrictedGroupsForPropertyValidation,
-                        modelValidationEntryList,
-                        restrictedGroupsForModelValidation,
-                        processModelValidation);
-            }
-            else if (metaDataEntry.getValue() instanceof BeanValidation.List)
-            {
-                for (BeanValidation currentBeanValidation : ((BeanValidation.List) metaDataEntry.getValue()).value())
-                {
-                    tryToProcessMetaData(currentBeanValidation,
-                            tryToCreateNewTarget(base, property),
-                            foundGroupsForPropertyValidation,
-                            restrictedGroupsForPropertyValidation,
-                            modelValidationEntryList,
-                            restrictedGroupsForModelValidation,
-                            processModelValidation);
-                }
-            }
-        }
-    }
-
-    private static Object tryToCreateNewTarget(Object base, String property)
-    {
-        Object result = getValueOfProperty(base, property);
-
-        if (result == null)
-        {
-            return base;
-        }
-
-        return result;
-    }
-
-    private static Object getValueOfProperty(Object base, String property)
-    {
-        property = property.substring(0, 1).toUpperCase() + property.substring(1, property.length());
-        Method targetMethod = ReflectionUtils.tryToGetMethod(base.getClass(), "get" + property);
-
-        if (targetMethod == null)
-        {
-            targetMethod = ReflectionUtils.tryToGetMethod(base.getClass(), "is" + property);
-        }
-
-        if (targetMethod == null)
-        {
-            throw new IllegalStateException(
-                    "class " + base.getClass() + " has no public get/is " + property.toLowerCase());
-        }
-        return ReflectionUtils.tryToInvokeMethod(base, targetMethod);
-    }
-
-    private static void processFoundGroups(ExtValBeanValidationContext extValBeanValidationContext,
-                                           String currentViewId,
-                                           String clientId,
-                                           List<Class> foundGroupsForPropertyValidation)
-    {
-        /*
-         * add found groups to context
-         */
-        for (Class currentGroupClass : foundGroupsForPropertyValidation)
-        {
-            extValBeanValidationContext.addGroup(currentGroupClass, currentViewId, clientId);
-        }
-    }
-
-    private static void processRestrictedGroups(ExtValBeanValidationContext extValBeanValidationContext,
-                                                String currentViewId,
-                                                String clientId,
-                                                List<Class> restrictedGroupsForPropertyValidation)
-    {
-        /*
-         * add restricted groups
-         */
-        for (Class currentGroupClass : restrictedGroupsForPropertyValidation)
-        {
-            extValBeanValidationContext.restrictGroup(currentGroupClass, currentViewId, clientId);
-        }
-    }
-
-    private static void initModelValidation(ExtValBeanValidationContext extValBeanValidationContext,
-                                            UIComponent component,
-                                            PropertyDetails propertyDetails,
-                                            List<ModelValidationEntry> modelValidationEntryList,
-                                            List<Class> restrictedGroupsForModelValidation)
-    {
-        /*
-         * add model validation entry list
-         */
-        for (ModelValidationEntry modelValidationEntry : modelValidationEntryList)
-        {
-            for (Class restrictedGroup : restrictedGroupsForModelValidation)
-            {
-                modelValidationEntry.removeGroup(restrictedGroup);
-            }
-
-            if (modelValidationEntry.getGroups().length > 0)
-            {
-                if(modelValidationEntry.getValidationTargets().isEmpty())
-                {
-                    modelValidationEntry.addValidationTarget(propertyDetails.getBaseObject());
-                }
-                modelValidationEntry.setComponent(component);
-                extValBeanValidationContext.addModelValidationEntry(modelValidationEntry);
-            }
-        }
-    }
-
-    private static void transferGroupValidationInformationToFoundGroups(
-            Object objectToInspect,
-            List<Class> foundGroupsForPropertyValidation,
-            List<Class> restrictedGroupsForPropertyValidation,
-            List<ModelValidationEntry> modelValidationEntryList,
-            List<Class> restrictedGroupsForModelValidation,
-            boolean processModelValidation)
-    {
-        if (objectToInspect.getClass().isAnnotationPresent(BeanValidation.class))
-        {
-            tryToProcessMetaData(objectToInspect.getClass().getAnnotation(BeanValidation.class),
-                    objectToInspect,
-                    foundGroupsForPropertyValidation,
-                    restrictedGroupsForPropertyValidation,
-                    modelValidationEntryList,
-                    restrictedGroupsForModelValidation,
-                    processModelValidation);
-        }
-        else if (objectToInspect.getClass().isAnnotationPresent(BeanValidation.List.class))
-        {
-            for (BeanValidation currentBeanValidation :
-                    (objectToInspect.getClass().getAnnotation(BeanValidation.List.class)).value())
-            {
-                tryToProcessMetaData(currentBeanValidation,
-                        objectToInspect,
-                        foundGroupsForPropertyValidation,
-                        restrictedGroupsForPropertyValidation,
-                        modelValidationEntryList,
-                        restrictedGroupsForModelValidation,
-                        processModelValidation);
-            }
-        }
-    }
-
-    private static void processInterfaces(Class currentClass,
-                                          Object metaDataSourceObject,
-                                          List<Class> foundGroupsForPropertyValidation,
-                                          List<Class> restrictedGroupsForPropertyValidation,
-                                          List<ModelValidationEntry> modelValidationEntryList,
-                                          List<Class> restrictedGroupsForModelValidation,
-                                          boolean processModelValidation)
-    {
-        for (Class currentInterface : currentClass.getInterfaces())
-        {
-            transferGroupValidationInformationToFoundGroups(metaDataSourceObject,
-                    foundGroupsForPropertyValidation,
-                    restrictedGroupsForPropertyValidation,
-                    modelValidationEntryList,
-                    restrictedGroupsForModelValidation,
-                    processModelValidation);
-
-            processInterfaces(currentInterface, metaDataSourceObject,
-                    foundGroupsForPropertyValidation,
-                    restrictedGroupsForPropertyValidation,
-                    modelValidationEntryList,
-                    restrictedGroupsForModelValidation,
-                    processModelValidation);
-        }
-    }
-
-    private static void tryToProcessMetaData(BeanValidation beanValidation,
-                                        Object metaDataSourceObject,
-                                        List<Class> foundGroupsForPropertyValidation,
-                                        List<Class> restrictedGroupsForPropertyValidation,
-                                        List<ModelValidationEntry> modelValidationEntryList,
-                                        List<Class> restrictedGroupsForModelValidation,
-                                        boolean processModelValidation)
-    {
-        for (String currentViewId : beanValidation.viewIds())
-        {
-            if (useMetaDataForViewId(beanValidation, currentViewId))
-            {
-                processMetaData(beanValidation,
-                        metaDataSourceObject,
-                        foundGroupsForPropertyValidation,
-                        restrictedGroupsForPropertyValidation,
-                        modelValidationEntryList,
-                        restrictedGroupsForModelValidation,
-                        processModelValidation);
-                break;
-            }
-        }
-    }
-
-    private static boolean useMetaDataForViewId(BeanValidation beanValidation, String currentViewId)
-    {
-        return (currentViewId.equals(FacesContext.getCurrentInstance().getViewRoot().getViewId()) ||
-                currentViewId.equals("*")) && isValidationPermitted(beanValidation);
-    }
-
-    private static void processMetaData(BeanValidation beanValidation,
-                                                 Object metaDataSourceObject,
-                                                 List<Class> foundGroupsForPropertyValidation,
-                                                 List<Class> restrictedGroupsForPropertyValidation,
-                                                 List<ModelValidationEntry> modelValidationEntryList,
-                                                 List<Class> restrictedGroupsForModelValidation,
-                                                 boolean processModelValidation)
-    {
-        if (processModelValidation && isModelValidation(beanValidation))
-        {
-            addModelValidationEntry(
-                    beanValidation, metaDataSourceObject,
-                    modelValidationEntryList, restrictedGroupsForModelValidation);
-        }
-        else if(!isModelValidation(beanValidation))
-        {
-            processGroups(
-                    beanValidation, foundGroupsForPropertyValidation, restrictedGroupsForPropertyValidation);
-        }
-    }
-
-    private static boolean isValidationPermitted(BeanValidation beanValidation)
-    {
-        ELHelper elHelper = ExtValUtils.getELHelper();
-
-        for (String condition : beanValidation.conditions())
-        {
-            if (elHelper.isELTermWellFormed(condition) &&
-                    elHelper.isELTermValid(FacesContext.getCurrentInstance(), condition))
-            {
-                if (Boolean.TRUE.equals(elHelper.getValueOfExpression(
-                                FacesContext.getCurrentInstance(), new ValueBindingExpression(condition))))
-                {
-                    return true;
-                }
-            }
-            else
-            {
-                if (LOG.isErrorEnabled())
-                {
-                    LOG.error("an invalid condition is used: " + condition);
-                }
-            }
-        }
-        return false;
-    }
-
-    private static boolean isModelValidation(BeanValidation beanValidation)
-    {
-        return beanValidation.modelValidation().isActive();
-    }
-
-    private static void addModelValidationEntry(BeanValidation beanValidation,
-                                                Object metaDataSourceObject,
-                                                List<ModelValidationEntry> modelValidationEntryList,
-                                                List<Class> restrictedGroupsForModelValidation)
-    {
-        ModelValidationEntry modelValidationEntry = new ModelValidationEntry();
-
-        modelValidationEntry.setGroups(Arrays.asList(beanValidation.useGroups()));
-        modelValidationEntry.setDisplayMessageInline(beanValidation.modelValidation().displayInline());
-        modelValidationEntry.setCustomMessage(beanValidation.modelValidation().message());
-        modelValidationEntry.setMetaDataSourceObject(metaDataSourceObject);
-
-        Object validationTarget;
-        for(String validationTargetExpression : beanValidation.modelValidation().validationTargets())
-        {
-            if(ModelValidation.DEFAULT_TARGET.equals(validationTargetExpression))
-            {
-                continue;
-            }
-
-            validationTarget = tryToResolveValidationTargetExpression(validationTargetExpression);
-            if(validationTarget != null)
-            {
-                modelValidationEntry.addValidationTarget(validationTarget);
-            }
-        }
-
-        if (beanValidation.restrictGroups().length > 0)
-        {
-            restrictedGroupsForModelValidation.addAll(Arrays.asList(beanValidation.restrictGroups()));
-        }
-
-        if(modelValidationEntry.getValidationTargets().isEmpty())
-        {
-            modelValidationEntry.addValidationTarget(metaDataSourceObject);
-        }
-
-        modelValidationEntryList.add(modelValidationEntry);
-    }
-
-    private static Object tryToResolveValidationTargetExpression(String validationTargetExpression)
-    {
-        ValueBindingExpression valueBindingExpression = new ValueBindingExpression(validationTargetExpression);
-        return ExtValUtils.getELHelper()
-                .getValueOfExpression(FacesContext.getCurrentInstance(), valueBindingExpression);
-    }
-
-    private static void processGroups(BeanValidation beanValidation,
-                                      List<Class> foundGroupsForPropertyValidation,
-                                      List<Class> restrictedGroupsForPropertyValidation)
-    {
-        foundGroupsForPropertyValidation.addAll(Arrays.asList(beanValidation.useGroups()));
-
-        if (beanValidation.restrictGroups().length > 0)
-        {
-            restrictedGroupsForPropertyValidation.addAll(Arrays.asList(beanValidation.restrictGroups()));
-        }
+                restrictedGroupsForModelValidation);
     }
 
     public static void processConstraintViolations(FacesContext facesContext,
@@ -503,36 +88,35 @@
         {
             facesMessage = createFacesMessageForConstraintViolation(uiComponent, convertedObject, violation);
 
-            if(facesMessage == null)
+            if (facesMessage == null)
             {
                 continue;
             }
 
-            processFacesMessage(facesContext, uiComponent, facesMessageHolderList, facesMessage);
+            bvmi.processFacesMessage(facesContext, uiComponent, facesMessageHolderList, facesMessage);
         }
 
         processViolationMessages(facesMessageHolderList, firstErrorCausesAnException);
     }
 
-    @ToDo(value = Priority.HIGH, description = "support severity.warn and .info")
     public static FacesMessage createFacesMessageForConstraintViolation(UIComponent uiComponent,
                                                                         Object convertedObject,
                                                                         ConstraintViolation violation)
     {
         String violationMessage = violation.getMessage();
 
-        String labeledMessage = createLabeledMessage(violationMessage);
+        String labeledMessage = bvmi.createLabeledMessage(violationMessage);
 
-        FacesMessage.Severity severity = calcSeverity(violation);
+        FacesMessage.Severity severity = bvmi.calcSeverity(violation);
 
-        ValidatorException validatorException = createValidatorException(labeledMessage, severity);
+        ValidatorException validatorException = bvmi.createValidatorException(labeledMessage, severity);
 
-        if(!executeAfterThrowingInterceptors(uiComponent, convertedObject, validatorException))
+        if (!bvmi.executeAfterThrowingInterceptors(uiComponent, convertedObject, validatorException))
         {
             return null;
         }
 
-        if (isMessageTextUnchanged(validatorException, labeledMessage))
+        if (bvmi.isMessageTextUnchanged(validatorException, labeledMessage))
         {
             return ExtValUtils.createFacesMessage(severity, violationMessage, violationMessage);
         }
@@ -543,80 +127,21 @@
         }
     }
 
-    private static String createLabeledMessage(String violationMessage)
-    {
-        return labeledMessageInternals.createLabeledMessage(violationMessage);
-    }
-
-    private static FacesMessage.Severity calcSeverity(ConstraintViolation<?> violation)
-    {
-        for (Class<? extends Payload> payload : violation.getConstraintDescriptor().getPayload())
-        {
-            if (ViolationSeverity.Warn.class.isAssignableFrom(payload))
-            {
-                return FacesMessage.SEVERITY_WARN;
-            }
-            else if (ViolationSeverity.Info.class.isAssignableFrom(payload))
-            {
-                return FacesMessage.SEVERITY_INFO;
-            }
-            else if (ViolationSeverity.Fatal.class.isAssignableFrom(payload))
-            {
-                return FacesMessage.SEVERITY_FATAL;
-            }
-        }
-        return FacesMessage.SEVERITY_ERROR;
-    }
-
-    private static void processFacesMessage(FacesContext facesContext, UIComponent uiComponent,
-                                            List<FacesMessageHolder> facesMessageHolderList, FacesMessage facesMessage)
-    {
-        FacesMessageHolder facesMessageHolder = new FacesMessageHolder(facesMessage);
-
-        facesMessageHolder.setClientId(uiComponent.getClientId(facesContext));
-
-        facesMessageHolderList.add(facesMessageHolder);
-    }
-
-    private static boolean executeAfterThrowingInterceptors(UIComponent uiComponent,
-                                                         Object convertedObject,
-                                                         ValidatorException validatorException)
-    {
-        return ExtValUtils.executeAfterThrowingInterceptors(
-                uiComponent,
-                null,
-                convertedObject,
-                validatorException,
-                null);
-    }
-
-    private static boolean isMessageTextUnchanged(ValidatorException validatorException, String violationMessage)
-    {
-        return violationMessage.equals(validatorException.getFacesMessage().getSummary()) ||
-                violationMessage.equals(validatorException.getFacesMessage().getDetail());
-    }
-
-    private static ValidatorException createValidatorException(String violationMessage, FacesMessage.Severity severity)
-    {
-        return new ValidatorException(
-                ExtValUtils.createFacesMessage(severity, violationMessage, violationMessage));
-    }
-
     public static void processViolationMessages(List<FacesMessageHolder> violationMessageHolderList,
                                                 boolean firstErrorCausesAnException)
     {
-        if(violationMessageHolderList == null || violationMessageHolderList.isEmpty())
+        if (violationMessageHolderList == null || violationMessageHolderList.isEmpty())
         {
             return;
         }
 
         List<FacesMessageHolder> facesMessageListWithLowSeverity =
-                getFacesMessageListWithLowSeverity(violationMessageHolderList);
+                bvmi.getFacesMessageListWithLowSeverity(violationMessageHolderList);
         List<FacesMessageHolder> facesMessageListWithHighSeverity =
-                getFacesMessageListWithHighSeverity(violationMessageHolderList);
+                bvmi.getFacesMessageListWithHighSeverity(violationMessageHolderList);
 
-        addMessagesWithHighSeverity(facesMessageListWithHighSeverity, firstErrorCausesAnException);
-        addMessagesWithLowSeverity(facesMessageListWithLowSeverity);
+        bvmi.addMessagesWithHighSeverity(facesMessageListWithHighSeverity, firstErrorCausesAnException);
+        bvmi.addMessagesWithLowSeverity(facesMessageListWithLowSeverity);
 
         if (!facesMessageListWithHighSeverity.isEmpty() && firstErrorCausesAnException)
         {
@@ -625,64 +150,4 @@
                     facesMessageHolder.getClientId(), facesMessageHolder.getFacesMessage(), null);
         }
     }
-
-    private static List<FacesMessageHolder> getFacesMessageListWithLowSeverity(
-            List<FacesMessageHolder> violationMessages)
-    {
-        List<FacesMessageHolder> result = new ArrayList<FacesMessageHolder>();
-
-        for (FacesMessageHolder facesMessageHolder : violationMessages)
-        {
-            if (FacesMessage.SEVERITY_WARN.equals(facesMessageHolder.getFacesMessage().getSeverity()) ||
-                    FacesMessage.SEVERITY_INFO.equals(facesMessageHolder.getFacesMessage().getSeverity()))
-            {
-                result.add(facesMessageHolder);
-            }
-        }
-        return result;
-    }
-
-    private static List<FacesMessageHolder> getFacesMessageListWithHighSeverity(
-            List<FacesMessageHolder> violationMessageHolderList)
-    {
-        List<FacesMessageHolder> result = new ArrayList<FacesMessageHolder>();
-
-        for (FacesMessageHolder facesMessageHolder : violationMessageHolderList)
-        {
-            if (FacesMessage.SEVERITY_ERROR.equals(facesMessageHolder.getFacesMessage().getSeverity()) ||
-                    FacesMessage.SEVERITY_FATAL.equals(facesMessageHolder.getFacesMessage().getSeverity()))
-            {
-                result.add(facesMessageHolder);
-            }
-        }
-        return result;
-    }
-
-    private static void addMessagesWithHighSeverity(List<FacesMessageHolder> facesMessageHolderListWithHighSeverity,
-                                                    boolean firstErrorCausesAnException)
-    {
-        boolean firstMessage = true;
-        for (FacesMessageHolder facesMessageHolder : facesMessageHolderListWithHighSeverity)
-        {
-            if (firstMessage && firstErrorCausesAnException)
-            {
-                //the first error will be thrown as exception
-                firstMessage = false;
-            }
-            else
-            {
-                ExtValUtils.tryToAddViolationMessageForComponentId(
-                        facesMessageHolder.getClientId(), facesMessageHolder.getFacesMessage());
-            }
-        }
-    }
-
-    private static void addMessagesWithLowSeverity(List<FacesMessageHolder> facesMessageHolderListWithLowSeverity)
-    {
-        for (FacesMessageHolder facesMessageHolder : facesMessageHolderListWithLowSeverity)
-        {
-            ExtValUtils.tryToAddViolationMessageForComponentId(
-                    facesMessageHolder.getClientId(), facesMessageHolder.getFacesMessage());
-        }
-    }
 }



Mime
View raw message