myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r782423 - 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/extensions...
Date Sun, 07 Jun 2009 18:43:45 GMT
Author: gpetracek
Date: Sun Jun  7 18:43:45 2009
New Revision: 782423

URL: http://svn.apache.org/viewvc?rev=782423&view=rev
Log:
EXTVAL-42 global and local interception

Added:
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/PropertyValidationInterceptor.java
Modified:
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/CustomInformation.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java
    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/ValidationInterceptor.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/DefaultValidationParameterExtractor.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/crossval/CrossValidationPhaseListener.java

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/CustomInformation.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/CustomInformation.java?rev=782423&r1=782422&r2=782423&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/CustomInformation.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/CustomInformation.java
Sun Jun  7 18:43:45 2009
@@ -43,6 +43,7 @@
     STARTUP_LISTENER,
     COMPONENT_INITIALIZER,
     VALIDATION_EXCEPTION_INTERCEPTOR,
+    PROPERTY_VALIDATION_INTERCEPTOR,
     META_DATA_EXTRACTION_INTERCEPTOR,
 
     MESSAGE_RESOLVER_FACTORY,

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java?rev=782423&r1=782422&r2=782423&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
Sun Jun  7 18:43:45 2009
@@ -23,6 +23,7 @@
 import org.apache.myfaces.extensions.validator.core.interceptor.RendererInterceptor;
 import org.apache.myfaces.extensions.validator.core.interceptor.ValidationExceptionInterceptor;
 import org.apache.myfaces.extensions.validator.core.interceptor.MetaDataExtractionInterceptor;
+import org.apache.myfaces.extensions.validator.core.interceptor.PropertyValidationInterceptor;
 import org.apache.myfaces.extensions.validator.core.recorder.ProcessedInformationRecorder;
 import org.apache.myfaces.extensions.validator.core.factory.FactoryFinder;
 import org.apache.myfaces.extensions.validator.core.factory.DefaultFactoryFinder;
@@ -59,6 +60,7 @@
 
     private List<ComponentInitializer> componentInitializers;
     private List<ValidationExceptionInterceptor> validationExceptionInterceptors;
+    private List<PropertyValidationInterceptor> propertyValidationInterceptors;
     private List<MetaDataExtractionInterceptor> metaDataExtractionInterceptors;
 
     private Map<String, Object> globalProperties = new HashMap<String, Object>();
@@ -134,6 +136,41 @@
         }
     }
 
+    private void lazyInitPropertyValidationInterceptors()
+    {
+        if(this.propertyValidationInterceptors != null)
+        {
+            return;
+        }
+
+        this.propertyValidationInterceptors = new ArrayList<PropertyValidationInterceptor>();
+        List<String> validationInterceptorClassNames = new ArrayList<String>();
+
+        validationInterceptorClassNames
+            .add(WebXmlParameter.CUSTOM_PROPERTY_VALIDATION_INTERCEPTOR);
+        validationInterceptorClassNames
+            .add(ExtValContext.getContext().getInformationProviderBean().get(
+                    CustomInformation.PROPERTY_VALIDATION_INTERCEPTOR));
+
+        PropertyValidationInterceptor propertyValidationInterceptor;
+        for (String validationInterceptorName : validationInterceptorClassNames)
+        {
+            propertyValidationInterceptor =
+                (PropertyValidationInterceptor)
+                        ClassUtils.tryToInstantiateClassForName(validationInterceptorName);
+
+            if (propertyValidationInterceptor != null)
+            {
+                propertyValidationInterceptors.add(propertyValidationInterceptor);
+
+                if(logger.isTraceEnabled())
+                {
+                    logger.trace(propertyValidationInterceptor.getClass().getName() + " added");
+                }
+            }
+        }
+    }
+
     private void lazyInitMetaDataExtractionInterceptors()
     {
         if(this.metaDataExtractionInterceptors != null)
@@ -252,7 +289,19 @@
     public List<ValidationExceptionInterceptor> getValidationExceptionInterceptors()
     {
         lazyInitValidationExceptionInterceptors();
-        return validationExceptionInterceptors;
+        return this.validationExceptionInterceptors;
+    }
+
+    public void addPropertyValidationInterceptor(PropertyValidationInterceptor propertyValidationInterceptor)
+    {
+        lazyInitPropertyValidationInterceptors();
+        this.propertyValidationInterceptors.add(propertyValidationInterceptor);
+    }
+
+    public List<PropertyValidationInterceptor> getPropertyValidationInterceptors()
+    {
+        lazyInitPropertyValidationInterceptors();
+        return this.propertyValidationInterceptors;
     }
 
     public void addMetaDataExtractionInterceptor(MetaDataExtractionInterceptor metaDataExtractionInterceptor)
@@ -289,6 +338,7 @@
         return bean;
     }
 
+    @SuppressWarnings({"unchecked"})
     private InformationProviderBean initInformationProviderBean(Map applicationMap)
     {
         List<String> informationProviderBeanClassNames = new ArrayList<String>();
@@ -317,6 +367,7 @@
         return new InformationProviderBean();
     }
 
+    @SuppressWarnings({"unchecked"})
     private void tryToInitCustomConfiguredInformationProviderBeanClassName(Map applicationMap)
     {
         InformationProviderBean bean = (InformationProviderBean) ExtValUtils.getELHelper()
@@ -366,12 +417,10 @@
             {
                 return false;
             }
-            else
+
+            if(this.logger.isInfoEnabled())
             {
-                if(this.logger.isInfoEnabled())
-                {
-                    logger.info("override global property '" + name + "'");
-                }
+                logger.info("override global property '" + name + "'");
             }
         }
 

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java?rev=782423&r1=782422&r2=782423&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java
Sun Jun  7 18:43:45 2009
@@ -92,6 +92,8 @@
                 "ComponentInitializer");
         customizableInfos.put(CustomInformation.VALIDATION_EXCEPTION_INTERCEPTOR,
                 "ValidationExceptionInterceptor");
+        customizableInfos.put(CustomInformation.PROPERTY_VALIDATION_INTERCEPTOR,
+                "PropertyValidationInterceptor");
         customizableInfos.put(CustomInformation.META_DATA_EXTRACTION_INTERCEPTOR,
                 "MetaDataExtractionInterceptor");
 
@@ -126,6 +128,7 @@
                 "strategy_mappings");
     }
 
+    @SuppressWarnings({"UnusedDeclaration"})
     protected void applyCustomValues(Map<CustomInformation, String> map)
     {
         //override to customize information

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=782423&r1=782422&r2=782423&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
Sun Jun  7 18:43:45 2009
@@ -58,6 +58,9 @@
     static final String CUSTOM_VALIDATION_EXCEPTION_INTERCEPTOR = WebXmlUtils
         .getInitParameter("CUSTOM_VALIDATION_EXCEPTION_INTERCEPTOR");
 
+    static final String CUSTOM_PROPERTY_VALIDATION_INTERCEPTOR = WebXmlUtils
+        .getInitParameter("CUSTOM_PROPERTY_VALIDATION_INTERCEPTOR");
+
     static final String CUSTOM_META_DATA_EXTRACTION_INTERCEPTOR = WebXmlUtils
         .getInitParameter("CUSTOM_META_DATA_EXTRACTION_INTERCEPTOR");
 

Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/PropertyValidationInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/PropertyValidationInterceptor.java?rev=782423&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/PropertyValidationInterceptor.java
(added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/PropertyValidationInterceptor.java
Sun Jun  7 18:43:45 2009
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.interceptor;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.core.validation.parameter.ValidationParameter;
+
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.API)
+public interface PropertyValidationInterceptor extends ValidationParameter
+{
+    /**
+     * @return false if the validation process should be bypassed
+     */
+    boolean beforeValidation(FacesContext facesContext,
+                             UIComponent uiComponent,
+                             Object convertedObject,
+                             Map<String, Object> properties);
+
+    /**
+     * processed if validation was executed
+     * in contrast to ValidationExceptionInterceptor it gets executed in any case
+     */
+    void afterValidation(FacesContext facesContext,
+                         UIComponent uiComponent,
+                         Object convertedObject,
+                         Map<String, Object> properties);
+}

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ValidationInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ValidationInterceptor.java?rev=782423&r1=782422&r2=782423&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ValidationInterceptor.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ValidationInterceptor.java
Sun Jun  7 18:43:45 2009
@@ -26,6 +26,7 @@
 import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
 import org.apache.myfaces.extensions.validator.core.metadata.CommonMetaDataKeys;
 import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
 import org.apache.myfaces.extensions.validator.core.ExtValContext;
 import org.apache.myfaces.extensions.validator.core.renderkit.exception.SkipBeforeInterceptorsException;
 import org.apache.myfaces.extensions.validator.core.renderkit.exception.SkipRendererDelegationException;
@@ -41,6 +42,7 @@
 import java.io.IOException;
 import java.util.Map;
 import java.util.HashMap;
+import java.lang.annotation.Annotation;
 
 /**
  * @author Gerhard Petracek
@@ -159,16 +161,44 @@
             return;
         }
 
-        if(logger.isTraceEnabled())
+        MetaDataExtractor metaDataExtractor = ExtValUtils.getComponentMetaDataExtractor();
+
+        PropertyInformation propertyInformation = metaDataExtractor.extract(facesContext,
uiComponent);
+
+        if(!ExtValUtils.executeGlobalBeforeValidationInterceptors(facesContext, uiComponent,
convertedObject,
+                PropertyInformation.class.getName() ,propertyInformation))
         {
-            logger.trace("start validation");
+            return;
         }
 
-        ValidationStrategy validationStrategy;
+        try
+        {
+            if(logger.isTraceEnabled())
+            {
+                logger.trace("start validation");
+            }
 
-        MetaDataExtractor metaDataExtractor = ExtValUtils.getComponentMetaDataExtractor();
+            processFieldValidation(facesContext, uiComponent, convertedObject, propertyInformation);
+        }
+        finally
+        {
+            if(logger.isTraceEnabled())
+            {
+                logger.trace("validation finished");
+            }
 
-        for (MetaDataEntry entry : metaDataExtractor.extract(facesContext, uiComponent).getMetaDataEntries())
+            ExtValUtils.executeGlobalAfterValidationInterceptors(facesContext, uiComponent,
convertedObject,
+                    PropertyInformation.class.getName(), propertyInformation);
+        }
+    }
+
+    protected void processFieldValidation(FacesContext facesContext,
+                                          UIComponent uiComponent,
+                                          Object convertedObject,
+                                          PropertyInformation propertyInformation)
+    {
+        ValidationStrategy validationStrategy;
+        for (MetaDataEntry entry : propertyInformation.getMetaDataEntries())
         {
             validationStrategy = ExtValUtils.getValidationStrategyForMetaData(entry.getKey());
 
@@ -184,26 +214,46 @@
 
                 if(logger.isTraceEnabled())
                 {
-                    logger.trace("validate " + entry.getValue() + " with " +
-                            validationStrategy.getClass().getName());
+                    logger.trace("validate " + entry.getValue() + " with " + validationStrategy.getClass().getName());
                 }
 
-                validationStrategy.validate(facesContext, uiComponent, entry, convertedObject);
+                try
+                {
+                    if(entry.getValue() instanceof Annotation)
+                    {
+                        if(!ExtValUtils.executeLocalBeforeValidationInterceptors(
+                                facesContext, uiComponent, convertedObject,
+                                PropertyInformation.class.getName(), propertyInformation,
+                                entry.getValue(Annotation.class)))
+                        {
+                            continue;
+                        }
+                    }
+
+                    /*
+                     * validation
+                     */
+                    validationStrategy.validate(facesContext, uiComponent, entry, convertedObject);
+                }
+                finally
+                {
+                    if(entry.getValue() instanceof Annotation)
+                    {
+                        ExtValUtils.executeLocalAfterValidationInterceptors(
+                                facesContext, uiComponent, convertedObject,
+                                PropertyInformation.class.getName(), propertyInformation,
+                                entry.getValue(Annotation.class));
+                    }
+                }
             }
             else
             {
                 if(logger.isTraceEnabled())
                 {
-                    logger.trace("no validation strategy found for "
-                            + entry.getValue());
+                    logger.trace("no validation strategy found for " + entry.getValue());
                 }
             }
         }
-
-        if(logger.isTraceEnabled())
-        {
-            logger.trace("validation finished");
-        }
     }
 
     protected boolean skipValidation(FacesContext facesContext,

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/DefaultValidationParameterExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/DefaultValidationParameterExtractor.java?rev=782423&r1=782422&r2=782423&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/DefaultValidationParameterExtractor.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/DefaultValidationParameterExtractor.java
Sun Jun  7 18:43:45 2009
@@ -20,6 +20,8 @@
 
 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.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -99,6 +101,7 @@
         return new ArrayList<Object>();
     }
 
+    @ToDo(value = Priority.MEDIUM, description = "add web.xml parameter for performance tuning
to deactivate the scan")
     public Map<Object, List<Object>> extractById(Annotation annotation, Class
valueId)
     {
         Map<Object, List<Object>> result = new HashMap<Object, List<Object>>();
@@ -177,12 +180,32 @@
                     key = processFoundField(annotation, currentField, parameterValues, key,
valueId);
                 }
             }
+
+            //inspect the other methods of the implementing class
+            for(Method currentMethod : paramClass.getDeclaredMethods())
+            {
+                processFoundMethod(paramClass, currentMethod, parameterValues, key, valueId);
+            }
         }
 
+        key = createDefaultKey(key, paramClass);
+
+        if(result.containsKey(key))
+        {
+            result.get(key).addAll(parameterValues);
+        }
+        else
+        {
+            result.put(key, parameterValues);
+        }
+    }
+
+    private Object createDefaultKey(Object key, Class currentClass)
+    {
         if(key == null)
         {
             //check for super-interface (exclude ValidationParameter itself)
-            for(Class interfaceClass : paramClass.getInterfaces())
+            for(Class interfaceClass : currentClass.getInterfaces())
             {
                 if(ValidationParameter.class.isAssignableFrom(interfaceClass) &&
                         (!interfaceClass.getName().equals(ValidationParameter.class.getName())))
@@ -195,28 +218,21 @@
 
         if(key == null)
         {
-            key = paramClass;
+            key = currentClass;
         }
 
-        if(result.containsKey(key))
-        {
-            result.get(key).addAll(parameterValues);
-        }
-        else
-        {
-            result.put(key, parameterValues);
-        }
+        return key;
     }
 
     private Object processFoundField(
-            Annotation annotation, Field currentField, List<Object> paramValues, Object
key, Class valueId)
+            Object instance, Field currentField, List<Object> paramValues, Object key,
Class valueId)
     {
         Object newKey = null;
         if(key == null && currentField.isAnnotationPresent(ParameterKey.class))
         {
             try
             {
-                newKey = currentField.get(annotation);
+                newKey = currentField.get(instance);
             }
             catch (Throwable e)
             {
@@ -234,7 +250,7 @@
                 currentField.setAccessible(true);
                 try
                 {
-                    paramValues.add(currentField.get(annotation));
+                    paramValues.add(currentField.get(instance));
                 }
                 catch (Throwable e)
                 {

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=782423&r1=782422&r2=782423&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
Sun Jun  7 18:43:45 2009
@@ -29,6 +29,7 @@
 import org.apache.myfaces.extensions.validator.core.mapper.NameMapper;
 import org.apache.myfaces.extensions.validator.core.interceptor.ValidationExceptionInterceptor;
 import org.apache.myfaces.extensions.validator.core.interceptor.MetaDataExtractionInterceptor;
+import org.apache.myfaces.extensions.validator.core.interceptor.PropertyValidationInterceptor;
 import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
 import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
 import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
@@ -54,9 +55,11 @@
 import javax.faces.validator.ValidatorException;
 import javax.faces.application.FacesMessage;
 import java.util.Map;
+import java.util.HashMap;
 import java.util.MissingResourceException;
 import java.util.List;
 import java.util.ArrayList;
+import java.lang.annotation.Annotation;
 
 /**
  * @author Gerhard Petracek
@@ -402,6 +405,7 @@
         return markerList;
     }
 
+    @SuppressWarnings({"unchecked"})
     public static boolean isSkipValidationSupported(Class currentClass, Class targetClass)
     {
         if(currentClass.isAnnotation())
@@ -428,4 +432,104 @@
             .getFactory(FactoryNames.VALIDATION_PARAMETER_EXTRACTOR_FACTORY, ValidationParameterExtractorFactory.class)
             .create();
     }
+
+    public static boolean executeLocalBeforeValidationInterceptors(FacesContext facesContext,
+                                                                   UIComponent uiComponent,
+                                                                   Object convertedObject,
+                                                                   String propertyKey,
+                                                                   Object properties,
+                                                                   Annotation annotation)
+    {
+        Map<String, Object> propertyMap = new HashMap<String, Object>();
+        List<PropertyValidationInterceptor> propertyValidationInterceptors = getValidationParameterExtractor().extract(
+                annotation, PropertyValidationInterceptor.class, PropertyValidationInterceptor.class);
+        boolean result = true;
+
+        if(properties != null)
+        {
+            propertyMap.put(propertyKey, properties);
+        }
+
+        for(PropertyValidationInterceptor propertyValidationInterceptor : propertyValidationInterceptors)
+        {
+            if(!propertyValidationInterceptor.beforeValidation(facesContext, uiComponent,
convertedObject, propertyMap))
+            {
+                result = false;
+            }
+        }
+
+        return result;
+    }
+
+    public static void executeLocalAfterValidationInterceptors(FacesContext facesContext,
+                                                               UIComponent uiComponent,
+                                                               Object convertedObject,
+                                                               String propertyKey,
+                                                               Object properties,
+                                                               Annotation annotation)
+    {
+        Map<String, Object> propertyMap = new HashMap<String, Object>();
+        List<PropertyValidationInterceptor> propertyValidationInterceptors = getValidationParameterExtractor().extract(
+                annotation, PropertyValidationInterceptor.class, PropertyValidationInterceptor.class);
+
+        if(properties != null)
+        {
+            propertyMap.put(propertyKey, properties);
+        }
+
+        for(PropertyValidationInterceptor propertyValidationInterceptor : propertyValidationInterceptors)
+        {
+            propertyValidationInterceptor.afterValidation(facesContext, uiComponent, convertedObject,
propertyMap);
+        }
+    }
+
+    public static boolean executeGlobalBeforeValidationInterceptors(FacesContext facesContext,
+                                                                    UIComponent uiComponent,
+                                                                    Object convertedObject,
+                                                                    String propertyKey,
+                                                                    Object properties)
+    {
+        Map<String, Object> propertyMap = new HashMap<String, Object>();
+        boolean result = true;
+
+        if(properties != null)
+        {
+            propertyMap.put(propertyKey, properties);
+        }
+
+        List<PropertyValidationInterceptor> propertyValidationInterceptors =
+                ExtValContext.getContext().getPropertyValidationInterceptors();
+
+        for(PropertyValidationInterceptor propertyValidationInterceptor : propertyValidationInterceptors)
+        {
+            if(!propertyValidationInterceptor.beforeValidation(facesContext, uiComponent,
convertedObject, propertyMap))
+            {
+                result = false;
+            }
+        }
+
+        return result;
+    }
+
+    public static void executeGlobalAfterValidationInterceptors(FacesContext facesContext,
+                                                                UIComponent uiComponent,
+                                                                Object convertedObject,
+                                                                String propertyKey,
+                                                                Object properties)
+    {
+        Map<String, Object> propertyMap = new HashMap<String, Object>();
+
+        if(properties != null)
+        {
+            propertyMap.put(propertyKey, properties);
+        }
+
+        List<PropertyValidationInterceptor> propertyValidationInterceptors =
+                ExtValContext.getContext().getPropertyValidationInterceptors();
+
+        for(PropertyValidationInterceptor propertyValidationInterceptor : propertyValidationInterceptors)
+        {
+            propertyValidationInterceptor.afterValidation(facesContext, uiComponent, convertedObject,
propertyMap);
+        }
+    }
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/CrossValidationPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/CrossValidationPhaseListener.java?rev=782423&r1=782422&r2=782423&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/CrossValidationPhaseListener.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/CrossValidationPhaseListener.java
Sun Jun  7 18:43:45 2009
@@ -21,6 +21,7 @@
 import org.apache.myfaces.extensions.validator.util.CrossValidationUtils;
 import org.apache.myfaces.extensions.validator.util.JsfUtils;
 import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
 import org.apache.myfaces.extensions.validator.crossval.strategy.AbstractCrossValidationStrategy;
@@ -31,6 +32,7 @@
 import javax.faces.event.PhaseListener;
 import javax.faces.validator.ValidatorException;
 import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
 
 /**
  * This phase listener processes cross validation as soon as it finds a special request scoped
storage.<br/>
@@ -56,6 +58,17 @@
             {
                 try
                 {
+                    if(!ExtValUtils.executeGlobalBeforeValidationInterceptors(
+                            FacesContext.getCurrentInstance(),
+                            entry.getComponent(),
+                            entry.getConvertedObject(),
+                            CrossValidationStorageEntry.class.getName(),
+                            entry))
+                    {
+                        continue;
+                    }
+
+                    //call init-method
                     if(entry.getValidationStrategy() instanceof AbstractCrossValidationStrategy)
                     {
                         ReflectionUtils.tryToInvokeMethod(
@@ -67,6 +80,9 @@
                                 entry);
                     }
 
+                    /*
+                     * validation
+                     */
                     entry.getValidationStrategy().processCrossValidation(entry, crossValidationStorage);
                 }
                 catch (ValidatorException validatorException)
@@ -106,6 +122,15 @@
                         event.getFacesContext().renderResponse();
                     }
                 }
+                finally
+                {
+                    ExtValUtils.executeGlobalAfterValidationInterceptors(
+                            FacesContext.getCurrentInstance(),
+                            entry.getComponent(),
+                            entry.getConvertedObject(),
+                            CrossValidationStorageEntry.class.getName(),
+                            entry);
+                }
             }
         }
         finally



Mime
View raw message