myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r817044 - 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/factory/ core/src/main/java/org/apache/myfaces/extensions/val...
Date Sun, 20 Sep 2009 15:53:10 GMT
Author: gpetracek
Date: Sun Sep 20 15:53:08 2009
New Revision: 817044

URL: http://svn.apache.org/viewvc?rev=817044&view=rev
Log:
EXTVAL-59 and EXTVAL-60

Added:
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/MetaDataStorageFilter.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/JoinValidationMetaDataStorageFilter.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/factory/DefaultFactoryFinder.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultMetaDataStorage.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/MetaDataStorage.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleStartupListener.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/transformer/JoinMetaDataTransformer.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JoinValidationStrategy.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=817044&r1=817043&r2=817044&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 Sep 20 15:53:08 2009
@@ -54,7 +54,10 @@
     VALIDATION_PARAMETER_EXTRACTOR_FACTORY,
     META_DATA_TRANSFORMER_FACTORY,
     FACES_MESSAGE_FACTORY,
+    STORAGE_MANAGER_FACTORY,
 
     MESSAGE_BUNDLE_NAME,
-    STATIC_STRATEGY_MAPPING_SOURCE
+    STATIC_STRATEGY_MAPPING_SOURCE,
+
+    META_DATA_STORAGE_FILTER
 }

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=817044&r1=817043&r2=817044&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 Sep 20 15:53:08 2009
@@ -350,10 +350,9 @@
         return true;
     }
 
-    public void deregisterRendererInterceptor(Class rendererInterceptorClass)
+    public void deregisterRendererInterceptor(Class<? extends RendererInterceptor>
rendererInterceptorClass)
     {
-        RendererInterceptor rendererInterceptor =
-            (RendererInterceptor) ClassUtils.tryToInstantiateClass(rendererInterceptorClass);
+        RendererInterceptor rendererInterceptor = ClassUtils.tryToInstantiateClass(rendererInterceptorClass);
 
         synchronized (ExtValContext.class)
         {
@@ -362,14 +361,16 @@
     }
 
     //if an interceptor hasn't been registered so far, it should be denied at future registrations
-    public void denyRendererInterceptor(Class rendererInterceptorClass)
+    public void denyRendererInterceptor(Class<? extends RendererInterceptor> rendererInterceptorClass)
     {
-        RendererInterceptor rendererInterceptor =
-            (RendererInterceptor) ClassUtils.tryToInstantiateClass(rendererInterceptorClass);
+        RendererInterceptor rendererInterceptor = ClassUtils.tryToInstantiateClass(rendererInterceptorClass);
 
         synchronized (ExtValContext.class)
         {
-            deniedInterceptors.add(rendererInterceptor.getInterceptorId());
+            if(!deniedInterceptors.contains(rendererInterceptor.getInterceptorId()))
+            {
+                deniedInterceptors.add(rendererInterceptor.getInterceptorId());
+            }
         }
         deregisterRendererInterceptor(rendererInterceptorClass);
     }

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=817044&r1=817043&r2=817044&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 Sep 20 15:53:08 2009
@@ -80,7 +80,7 @@
         customizableInfos.put(CustomInformation.COMPONENT_META_DATA_EXTRACTOR,
                 "ComponentMetaDataExtractor");
         customizableInfos.put(CustomInformation.VALIDATION_PARAMETER_EXTRACTOR,
-                "VALIDATION_PARAMETER_EXTRACTOR");
+                "ValidationParameterExtractor");
 
         customizableInfos.put(CustomInformation.VALIDATION_STRATEGY_POSTFIX,
                 "ValidationStrategy");
@@ -99,11 +99,11 @@
                 "MetaDataExtractionInterceptor");
 
         customizableInfos.put(CustomInformation.VALIDATION_STRATEGY_TO_MSG_RESOLVER_NAME_MAPPER,
-            "ValidationStrategyToMsgResolverNameMapper");
+                "ValidationStrategyToMsgResolverNameMapper");
         customizableInfos.put(CustomInformation.META_DATA_TO_VALIDATION_STRATEGY_NAME_MAPPER,
-            "MetaDataToValidationStrategyNameMapper");
+                "MetaDataToValidationStrategyNameMapper");
         customizableInfos.put(CustomInformation.VALIDATION_STRATEGY_TO_META_DATA_TRANSFORMER_NAME_MAPPER,
-            "ValidationStrategyToMetaDataTransformerNameMapper");
+                "ValidationStrategyToMetaDataTransformerNameMapper");
 
         customizableInfos.put(CustomInformation.STARTUP_LISTENER,
                 "StartupListener");
@@ -115,11 +115,13 @@
         customizableInfos.put(CustomInformation.COMPONENT_META_DATA_EXTRACTOR_FACTORY,
                 "ComponentMetaDataExtractorFactory");
         customizableInfos.put(CustomInformation.VALIDATION_PARAMETER_EXTRACTOR_FACTORY,
-                "VALIDATION_PARAMETER_EXTRACTOR_FACTORY");
+                "ValidationParameterExtractorFactory");
         customizableInfos.put(CustomInformation.META_DATA_TRANSFORMER_FACTORY,
                 "MetaDataTransformerFactory");
         customizableInfos.put(CustomInformation.FACES_MESSAGE_FACTORY,
                 "FacesMessageFactory");
+        customizableInfos.put(CustomInformation.STORAGE_MANAGER_FACTORY,
+                "StorageManagerFactory");
 
         //conventions (the rest of the conventions are built with the help of name mappers,...
         customizableInfos.put(CustomInformation.MESSAGE_BUNDLE_NAME,
@@ -127,6 +129,9 @@
         //static strategy mappings (name of property files)
         customizableInfos.put(CustomInformation.STATIC_STRATEGY_MAPPING_SOURCE,
                 "strategy_mappings");
+
+        customizableInfos.put(CustomInformation.META_DATA_STORAGE_FILTER,
+                "MetaDataStorageFilter");
     }
 
     @SuppressWarnings({"UnusedDeclaration"})

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=817044&r1=817043&r2=817044&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 Sep 20 15:53:08 2009
@@ -77,6 +77,12 @@
         .getInitParameter("CUSTOM_VALIDATION_STRATEGY_TO_META_DATA_TRANSFORMER_NAME_MAPPER");
 
     /*
+     * filter
+     */
+    static final String CUSTOM_META_DATA_STORAGE_FILTER = WebXmlUtils
+        .getInitParameter("CUSTOM_META_DATA_STORAGE_FILTER");
+    
+    /*
      * factories
      */
     static final String CUSTOM_VALIDATION_STRATEGY_FACTORY = WebXmlUtils
@@ -94,6 +100,9 @@
     static final String CUSTOM_META_DATA_TRANSFORMER_FACTORY = WebXmlUtils
         .getInitParameter("CUSTOM_META_DATA_TRANSFORMER_FACTORY");
 
+    static final String CUSTOM_STORAGE_MANAGER_FACTORY = WebXmlUtils
+        .getInitParameter("CUSTOM_STORAGE_MANAGER_FACTORY");
+
     static final String CUSTOM_FACES_MESSAGE_FACTORY = WebXmlUtils
         .getInitParameter("CUSTOM_FACES_MESSAGE_FACTORY");
 

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/factory/DefaultFactoryFinder.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/factory/DefaultFactoryFinder.java?rev=817044&r1=817043&r2=817044&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/factory/DefaultFactoryFinder.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/factory/DefaultFactoryFinder.java
Sun Sep 20 15:53:08 2009
@@ -304,6 +304,26 @@
 
     protected Object createStorageManagerFactory()
     {
-        return new DefaultStorageManagerFactory();
+        Object factory = null;
+
+        List<String> storageManagerFactoryClassNames = new ArrayList<String>();
+
+        storageManagerFactoryClassNames
+                .add(WebXmlParameter.CUSTOM_STORAGE_MANAGER_FACTORY);
+        storageManagerFactoryClassNames
+            .add(ExtValContext.getContext().getInformationProviderBean()
+                .get(CustomInformation.STORAGE_MANAGER_FACTORY));
+        storageManagerFactoryClassNames.add(DefaultStorageManagerFactory.class.getName());
+
+        for (String className : storageManagerFactoryClassNames)
+        {
+            factory = ClassUtils.tryToInstantiateClassForName(className);
+
+            if (factory != null)
+            {
+                break;
+            }
+        }
+        return factory;
     }
 }

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultMetaDataStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultMetaDataStorage.java?rev=817044&r1=817043&r2=817044&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultMetaDataStorage.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultMetaDataStorage.java
Sun Sep 20 15:53:08 2009
@@ -25,9 +25,17 @@
 import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
 import org.apache.myfaces.extensions.validator.core.property.DefaultPropertyInformation;
 import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
+import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
+import org.apache.myfaces.extensions.validator.core.CustomInformation;
+import org.apache.myfaces.extensions.validator.core.ExtValContext;
+import org.apache.myfaces.extensions.validator.util.ClassUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import java.util.Map;
 import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * @author Gerhard Petracek
@@ -36,10 +44,48 @@
 @UsageInformation(INTERNAL)
 public class DefaultMetaDataStorage implements MetaDataStorage
 {
+    protected final Log logger = LogFactory.getLog(getClass());
+
     private Map<String, PropertyInformation> cachedPropertyInformation = new HashMap<String,
PropertyInformation>();
 
+    private List<MetaDataStorageFilter> metaDataStorageFilters = new ArrayList<MetaDataStorageFilter>();
+    private List<Class<? extends MetaDataStorageFilter>> deniedMetaDataFilters
=
+            new ArrayList<Class<? extends MetaDataStorageFilter>>();
+
+    public DefaultMetaDataStorage()
+    {
+        initFilters();
+    }
+
+    private void initFilters()
+    {
+        List<String> metaDataStorageFilterClassNames = new ArrayList<String>();
+
+        metaDataStorageFilterClassNames
+            .add(WebXmlParameter.CUSTOM_META_DATA_STORAGE_FILTER);
+        metaDataStorageFilterClassNames
+            .add(ExtValContext.getContext().getInformationProviderBean().get(
+                    CustomInformation.META_DATA_STORAGE_FILTER));
+
+        MetaDataStorageFilter metaDataStorageFilter;
+        for (String validationExceptionInterceptorName : metaDataStorageFilterClassNames)
+        {
+            metaDataStorageFilter =
+                (MetaDataStorageFilter)ClassUtils.tryToInstantiateClassForName(validationExceptionInterceptorName);
+
+            if (metaDataStorageFilter != null)
+            {
+                this.metaDataStorageFilters.add(metaDataStorageFilter);
+
+                logAddedFilter(metaDataStorageFilter.getClass());
+            }
+        }
+    }
+
     public void storeMetaDataOf(PropertyInformation propertyInformation)
     {
+        invokeFilters(propertyInformation);
+
         PropertyInformation propertyInformationToStore = new DefaultPropertyInformation();
 
         PropertyDetails propertyDetails = propertyInformation
@@ -52,6 +98,14 @@
                 propertyInformationToStore);
     }
 
+    private void invokeFilters(PropertyInformation propertyInformation)
+    {
+        for(MetaDataStorageFilter filter : this.metaDataStorageFilters)
+        {
+            filter.filter(propertyInformation);
+        }
+    }
+
     public MetaDataEntry[] getMetaData(Class targetClass, String targetProperty)
     {
         PropertyInformation propertyInformation = this.cachedPropertyInformation
@@ -68,6 +122,64 @@
         return this.cachedPropertyInformation.containsKey(createKey(targetClass, targetProperty));
     }
 
+    public void registerFilter(MetaDataStorageFilter storageFilter)
+    {
+        synchronized (this)
+        {
+            if(!isFilterDenied(storageFilter) && !isFilterAlreadyRegistered(storageFilter))
+            {
+                this.metaDataStorageFilters.add(storageFilter);
+                logAddedFilter(storageFilter.getClass());
+            }
+        }
+    }
+
+    private boolean isFilterDenied(MetaDataStorageFilter storageFilter)
+    {
+        return this.deniedMetaDataFilters.contains(storageFilter.getClass());
+    }
+
+    private boolean isFilterAlreadyRegistered(MetaDataStorageFilter storageFilter)
+    {
+        for(MetaDataStorageFilter filter : this.metaDataStorageFilters)
+        {
+            if(filter.getClass().equals(storageFilter.getClass()))
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public void deregisterFilter(Class<? extends MetaDataStorageFilter> filterClass)
+    {
+        MetaDataStorageFilter storageFilter = ClassUtils.tryToInstantiateClass(filterClass);
+
+        synchronized (this)
+        {
+            this.metaDataStorageFilters.remove(storageFilter);
+        }
+
+        logRemovedFilter(storageFilter.getClass());
+    }
+
+    public void denyFilter(Class<? extends MetaDataStorageFilter> filterClass)
+    {
+        synchronized (this)
+        {
+            for(Class<? extends MetaDataStorageFilter> filterId : this.deniedMetaDataFilters)
+            {
+                if(filterId.equals(filterClass))
+                {
+                    return;
+                }
+            }
+            this.deniedMetaDataFilters.add(filterClass);
+        }
+
+        deregisterFilter(filterClass);
+    }
+
     private String createKey(Class targetClass, String targetProperty)
     {
         return targetClass.getName() + "#" + targetProperty;
@@ -85,4 +197,20 @@
             target.addMetaDataEntry(newMetaDataEntry);
         }
     }
+
+    private void logAddedFilter(Class<? extends MetaDataStorageFilter> filterClass)
+    {
+        if(this.logger.isInfoEnabled())
+        {
+            this.logger.info(filterClass.getName() + " added");
+        }
+    }
+
+    private void logRemovedFilter(Class<? extends MetaDataStorageFilter> filterClass)
+    {
+        if(this.logger.isInfoEnabled())
+        {
+            this.logger.info(filterClass.getName() + " removed");
+        }
+    }
 }

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/MetaDataStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/MetaDataStorage.java?rev=817044&r1=817043&r2=817044&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/MetaDataStorage.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/MetaDataStorage.java
Sun Sep 20 15:53:08 2009
@@ -35,4 +35,10 @@
     MetaDataEntry[] getMetaData(Class targetClass, String targetProperty);
 
     boolean containsMetaDataFor(Class targetClass, String targetProperty);
+
+    void registerFilter(MetaDataStorageFilter storageFilter);
+
+    void deregisterFilter(Class<? extends MetaDataStorageFilter> filterClass);
+
+    void denyFilter(Class<? extends MetaDataStorageFilter> filterClass);
 }

Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/MetaDataStorageFilter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/MetaDataStorageFilter.java?rev=817044&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/MetaDataStorageFilter.java
(added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/MetaDataStorageFilter.java
Sun Sep 20 15:53:08 2009
@@ -0,0 +1,33 @@
+/*
+ * 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.storage;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.API)
+public interface MetaDataStorageFilter
+{
+    void filter(PropertyInformation propertyInformation);
+}
\ No newline at end of file

Added: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/JoinValidationMetaDataStorageFilter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/JoinValidationMetaDataStorageFilter.java?rev=817044&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/JoinValidationMetaDataStorageFilter.java
(added)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/JoinValidationMetaDataStorageFilter.java
Sun Sep 20 15:53:08 2009
@@ -0,0 +1,208 @@
+/*
+ * 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;
+
+import org.apache.myfaces.extensions.validator.baseval.annotation.JoinValidation;
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
+import org.apache.myfaces.extensions.validator.core.metadata.extractor.DefaultComponentMetaDataExtractor;
+import org.apache.myfaces.extensions.validator.core.property.DefaultPropertyInformation;
+import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
+import org.apache.myfaces.extensions.validator.core.storage.MetaDataStorageFilter;
+import org.apache.myfaces.extensions.validator.util.ClassUtils;
+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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * EXTVAL-59
+ *
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class JoinValidationMetaDataStorageFilter implements MetaDataStorageFilter
+{
+    private static final String STATIC_SEPARATOR = ":";
+
+    public void filter(PropertyInformation propertyInformation)
+    {
+        if (propertyInformation != null)
+        {
+            List<MetaDataEntry> result = new ArrayList<MetaDataEntry>();
+
+            resolveJoinValidationMetaData(propertyInformation, result);
+
+            propertyInformation.resetMetaDataEntries();
+
+            setDefaultPropertyDetails(propertyInformation, result);
+
+            if (containsJoinValidationConstraint(result))
+            {
+                filter(propertyInformation);
+            }
+        }
+    }
+
+    private void resolveJoinValidationMetaData(PropertyInformation propertyInformation, List<MetaDataEntry>
result)
+    {
+        for (MetaDataEntry metaDataEntry : propertyInformation.getMetaDataEntries())
+        {
+            result.addAll(tryToTransformEntry(metaDataEntry));
+        }
+    }
+
+    private void setDefaultPropertyDetails(PropertyInformation propertyInformation, List<MetaDataEntry>
result)
+    {
+        for (MetaDataEntry metaDataEntry : result)
+        {
+            metaDataEntry.setProperty(PropertyInformationKeys.PROPERTY_DETAILS,
+                    propertyInformation.getInformation(PropertyInformationKeys.PROPERTY_DETAILS));
+            propertyInformation.addMetaDataEntry(metaDataEntry);
+        }
+    }
+
+    private boolean containsJoinValidationConstraint(List<MetaDataEntry> result)
+    {
+        for (MetaDataEntry entry : result)
+        {
+            if (entry.getValue() instanceof JoinValidation)
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    private List<MetaDataEntry> tryToTransformEntry(MetaDataEntry metaDataEntry)
+    {
+        List<MetaDataEntry> result = new ArrayList<MetaDataEntry>();
+
+        if (metaDataEntry.getValue() instanceof JoinValidation)
+        {
+            JoinValidation annotation = metaDataEntry.getValue(JoinValidation.class);
+
+            replaceMetaData(annotation, metaDataEntry, result);
+        }
+        else
+        {
+            result.add(metaDataEntry);
+        }
+
+        return result;
+    }
+
+    private void replaceMetaData(JoinValidation annotation, MetaDataEntry metaDataEntry,
List<MetaDataEntry> result)
+    {
+        for (String target : annotation.value())
+        {
+            tryToReplaceMetaDataOfTarget(target, metaDataEntry, result);
+        }
+    }
+
+    private void tryToReplaceMetaDataOfTarget(String target, MetaDataEntry metaDataEntry,
List<MetaDataEntry> result)
+    {
+        try
+        {
+            if (isStaticSyntax(target))
+            {
+                addMetaData(result, extractStaticMetaData(target));
+            }
+            else
+            {
+                addMetaData(result, extractDynamicMetaData(metaDataEntry, target));
+            }
+        }
+        catch (Throwable t)
+        {
+            //do nothing a different filter might introduce a new syntax which causes the
exception
+        }
+    }
+
+    private void addMetaData(List<MetaDataEntry> result, MetaDataEntry[] metaDataEntries)
+    {
+        Collections.addAll(result, metaDataEntries);
+    }
+
+    private boolean isStaticSyntax(String target)
+    {
+        return target.contains(STATIC_SEPARATOR);
+    }
+
+    private MetaDataEntry[] extractStaticMetaData(String target)
+    {
+        int separatorIndex = target.lastIndexOf(STATIC_SEPARATOR);
+
+        Class targetClass = loadClass(target.substring(0, separatorIndex));
+        String propertyName = target.substring(separatorIndex + 1);
+
+        return new StaticSyntaxMetaDataExtractor().extract(targetClass, propertyName).getMetaDataEntries();
+    }
+
+    private Class loadClass(String className)
+    {
+        try
+        {
+            return ClassUtils.loadClassForName(className);
+        }
+        catch (ClassNotFoundException e)
+        {
+            throw new IllegalArgumentException(e);
+        }
+    }
+
+    private MetaDataEntry[] extractDynamicMetaData(MetaDataEntry metaDataEntry, String target)
+    {
+        PropertyDetails propertyDetails = ExtValUtils.createPropertyDetailsForNewTarget(metaDataEntry,
target);
+
+        return new StaticSyntaxMetaDataExtractor().extract(
+                propertyDetails.getBaseObject().getClass(), propertyDetails.getProperty()).getMetaDataEntries();
+    }
+
+    private class StaticSyntaxMetaDataExtractor extends DefaultComponentMetaDataExtractor
+    {
+        public PropertyInformation extract(Class targetClass, String targetProperty)
+        {
+            PropertyInformation propertyInformation = new DefaultPropertyInformation();
+
+            addPropertyAccessAnnotations(targetClass, targetProperty, propertyInformation);
+            addFieldAccessAnnotations(targetClass, targetProperty, propertyInformation);
+
+            return propertyInformation;
+        }
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        return obj != null && getClass().equals(obj.getClass());
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return super.hashCode();
+    }
+}

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleStartupListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleStartupListener.java?rev=817044&r1=817043&r2=817044&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleStartupListener.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleStartupListener.java
Sun Sep 20 15:53:08 2009
@@ -27,6 +27,7 @@
 import org.apache.myfaces.extensions.validator.core.storage.StorageManagerHolder;
 import org.apache.myfaces.extensions.validator.core.storage.StorageManager;
 import org.apache.myfaces.extensions.validator.core.storage.GroupStorage;
+import org.apache.myfaces.extensions.validator.core.storage.MetaDataStorage;
 import org.apache.myfaces.extensions.validator.core.metadata.CommonMetaDataKeys;
 import org.apache.myfaces.extensions.validator.core.interceptor.ValidationInterceptor;
 import org.apache.myfaces.extensions.validator.core.initializer.configuration.StaticResourceBundleConfiguration;
@@ -44,6 +45,7 @@
 import org.apache.myfaces.extensions.validator.crossval.storage.ProcessedInformationStorage;
 import org.apache.myfaces.extensions.validator.crossval.storage.mapper.CrossValidationStorageNameMapper;
 import org.apache.myfaces.extensions.validator.crossval.storage.mapper.ProcessedInformationStorageNameMapper;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 
 /**
  * @author Gerhard Petracek
@@ -64,6 +66,7 @@
         addSkipValidationSupport();
         initStorageManagerAndNameMappers();
         initSkipValidationEvaluator();
+        initMetaDataStorageFilters();
     }
 
     private void initStaticStrategyMappings()
@@ -148,4 +151,12 @@
     {
         ExtValContext.getContext().setSkipValidationEvaluator(new PropertyValidationSkipValidationEvaluator(),
false);
     }
+
+    private void initMetaDataStorageFilters()
+    {
+         MetaDataStorage metaDataStorage = ExtValUtils.getStorage(
+                 MetaDataStorage.class, MetaDataStorage.class.getName());
+
+        metaDataStorage.registerFilter(new JoinValidationMetaDataStorageFilter());
+    }
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/transformer/JoinMetaDataTransformer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/transformer/JoinMetaDataTransformer.java?rev=817044&r1=817043&r2=817044&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/transformer/JoinMetaDataTransformer.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/transformer/JoinMetaDataTransformer.java
Sun Sep 20 15:53:08 2009
@@ -30,6 +30,8 @@
 import org.apache.myfaces.extensions.validator.util.PropertyValidationUtils;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.faces.context.FacesContext;
 import java.util.HashMap;
@@ -41,10 +43,31 @@
  * @since 1.x.1
  */
 @UsageInformation(UsageCategory.INTERNAL)
+@Deprecated
 public class JoinMetaDataTransformer implements MetaDataTransformer
 {
+    protected final Log logger = LogFactory.getLog(getClass());
+
     public Map<String, Object> convertMetaData(MetaDataEntry metaDataEntry)
     {
+        try
+        {
+            return convert(metaDataEntry);
+        }
+        catch (Throwable t)
+        {
+            if(this.logger.isWarnEnabled())
+            {
+                this.logger.warn("this class is replaced by a meta-data storage filter. "
+
+                        "if it gets invoked and an exception occurs, a custom syntax is used."
+
+                        "this class might be used by an old add-on. please check for a newer
version.");
+            }
+            return new HashMap<String, Object>();
+        }
+    }
+
+    private Map<String, Object> convert(MetaDataEntry metaDataEntry)
+    {
         MetaDataExtractor extractor = DefaultPropertyScanningMetaDataExtractor.getInstance();
 
         String[] targetExpressions = metaDataEntry.getValue(JoinValidation.class).value();

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JoinValidationStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JoinValidationStrategy.java?rev=817044&r1=817043&r2=817044&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JoinValidationStrategy.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JoinValidationStrategy.java
Sun Sep 20 15:53:08 2009
@@ -32,17 +32,43 @@
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.validator.ValidatorException;
+import javax.faces.FacesException;
 
 /**
  * @author Gerhard Petracek
  * @since 1.x.1
  */
 @UsageInformation(UsageCategory.INTERNAL)
+@Deprecated
 public class JoinValidationStrategy extends AbstractValidationStrategy
 {
     public void processValidation(FacesContext facesContext,
-            UIComponent uiComponent, MetaDataEntry metaDataEntry,
-            Object convertedObject) throws ValidatorException
+                                  UIComponent uiComponent, MetaDataEntry metaDataEntry,
+                                  Object convertedObject) throws ValidatorException
+    {
+        try
+        {
+            validateJoinValidation(facesContext, uiComponent, metaDataEntry, convertedObject);
+        }
+        catch (FacesException t)
+        {
+            throw t;
+        }
+        catch (Throwable t)
+        {
+            if(this.logger.isWarnEnabled())
+            {
+                this.logger.warn("this class is replaced by a meta-data storage filter. "
+
+                        "if it gets invoked and an exception occurs, a custom syntax is used."
+
+                        "this class might be used by an old add-on. please check for a newer
version.");
+            }
+        }
+    }
+
+    private void validateJoinValidation(FacesContext facesContext,
+                                        UIComponent uiComponent,
+                                        MetaDataEntry metaDataEntry,
+                                        Object convertedObject)
     {
         MetaDataExtractor extractor = DefaultPropertyScanningMetaDataExtractor.getInstance();
 



Mime
View raw message