myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r740173 - in /myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator: crossval/strategy/ util/
Date Tue, 03 Feb 2009 00:56:41 GMT
Author: gpetracek
Date: Tue Feb  3 00:56:41 2009
New Revision: 740173

URL: http://svn.apache.org/viewvc?rev=740173&view=rev
Log:
EXTVAL-35 - intermediate result

Modified:
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/AbstractCompareStrategy.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/CrossValidationHelper.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/ELCompareStrategy.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalCompareStrategy.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalPropertyChainCompareStrategy.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/util/CrossValidationUtils.java

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/AbstractCompareStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/AbstractCompareStrategy.java?rev=740173&r1=740172&r2=740173&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/AbstractCompareStrategy.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/AbstractCompareStrategy.java
Tue Feb  3 00:56:41 2009
@@ -82,7 +82,8 @@
             CrossValidationStorageEntry crossValidationStorageEntry,
             CrossValidationStorage crossValidationStorage) throws ValidatorException
     {
-        initValidation(crossValidationStorageEntry);
+        //initCrossValidation is done in the CrossValidationPhaseListener
+
         String[] validationTargets = getValidationTargets(
             crossValidationStorageEntry.getMetaDataEntry().getValue(Annotation.class));
 
@@ -119,6 +120,13 @@
     {
         if (!handleTargetViolation(entryOfSource, entryOfTarget))
         {
+            //no target - because there is no target component - value was validated against
the model
+            if(entryOfTarget == null)
+            {
+                processTargetComponentAsSourceComponentAfterViolation(entryOfSource);
+                return;
+            }
+
             return;
         }
 
@@ -163,16 +171,11 @@
         }
     }
 
-    protected final void processSourceComponentAfterViolation(CrossValidationStorageEntry
entryOfSource)
+    private void processTargetComponentAsSourceComponentAfterViolation(CrossValidationStorageEntry
entryOfSource)
     {
-        if (!handleSourceViolation(entryOfSource))
-        {
-            return;
-        }
-
         //get validation error messages for the current component
-        String summary = getErrorMessageSummary(entryOfSource.getMetaDataEntry().getValue(Annotation.class),
false);
-        String details = getErrorMessageDetail(entryOfSource.getMetaDataEntry().getValue(Annotation.class),
false);
+        String summary = getReverseErrorMessageSummary(entryOfSource.getMetaDataEntry().getValue(Annotation.class));
+        String details = getReverseErrorMessageDetail(entryOfSource.getMetaDataEntry().getValue(Annotation.class));
 
         FacesMessage message = getSourceComponentErrorMessage(
             entryOfSource.getMetaDataEntry().getValue(Annotation.class), summary, details);
@@ -184,8 +187,30 @@
         }
         else
         {
-            throw new ValidatorException(new FacesMessage());
+            //TODO logging
+        }
+    }
+
+    protected final void processSourceComponentAfterViolation(CrossValidationStorageEntry
entryOfSource)
+    {
+        if (handleSourceViolation(entryOfSource))
+        {
+            //get validation error messages for the current component
+            String summary = getErrorMessageSummary(entryOfSource.getMetaDataEntry().getValue(Annotation.class),
false);
+            String details = getErrorMessageDetail(entryOfSource.getMetaDataEntry().getValue(Annotation.class),
false);
+
+            FacesMessage message = getSourceComponentErrorMessage(
+                entryOfSource.getMetaDataEntry().getValue(Annotation.class), summary, details);
+
+            if (message.getSummary() != null || message.getDetail() != null)
+            {
+                //TODO
+                throw new ValidatorException(message);
+            }
         }
+
+        //just throw a new message - the error message is at the target
+        throw new ValidatorException(new FacesMessage());
     }
 
     protected FacesMessage getSourceComponentErrorMessage(Annotation annotation, String summary,
String detail)
@@ -238,19 +263,11 @@
         return getValidationErrorMsgKey(annotation, false);
     }
 
-    /**
-     * the usage of this method requires a new instance
-     * -> in case of validation strategy beans application/singleton isn't allowed
-     */
-    protected void initValidation(CrossValidationStorageEntry crossValidationStorageEntry)
-    {
-    }
-
     protected boolean handleTargetViolation(
             CrossValidationStorageEntry entryOfSource,
             CrossValidationStorageEntry entryOfTarget)
     {
-        return true;
+        return entryOfTarget != null && entryOfTarget.getComponent() != null;
     }
 
     protected boolean handleSourceViolation(CrossValidationStorageEntry entryOfSource)
@@ -264,6 +281,24 @@
     }
 
     /*
+     * no target component (validation against the model) -> get reverse message for source
component
+     */
+    protected String getReverseErrorMessageSummary(Annotation annotation)
+    {
+        //if the message is neutral
+        return getErrorMessageSummary(annotation, true);
+    }
+
+    /*
+     * no target component (validation against the model) -> get reverse message for source
component
+     */
+    protected String getReverseErrorMessageDetail(Annotation annotation)
+    {
+        //if the message is neutral
+        return getErrorMessageDetail(annotation, true);
+    }
+
+    /*
      * abstract methods
      */
 

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/CrossValidationHelper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/CrossValidationHelper.java?rev=740173&r1=740172&r2=740173&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/CrossValidationHelper.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/CrossValidationHelper.java
Tue Feb  3 00:56:41 2009
@@ -34,39 +34,63 @@
 {
     public static void crossValidateCompareStrategy(AbstractCompareStrategy compareStrategy,
             CrossValidationStorageEntry crossValidationStorageEntry,
-            ProcessedInformationEntry validationTargetEntry)
+            ProcessedInformationEntry validationTargetEntry,
+            boolean isModelAwareValidation)
     {
-        boolean violationFound = false;
-
         if (compareStrategy.isViolation(
                 crossValidationStorageEntry.getConvertedObject(),
                 validationTargetEntry.getConvertedValue(),
                 crossValidationStorageEntry.getMetaDataEntry().getValue(Annotation.class)))
         {
-
-            CrossValidationStorageEntry tmpCrossValidationStorageEntry = new CrossValidationStorageEntry();
-            if (compareStrategy.useTargetComponentToDisplayErrorMsg(crossValidationStorageEntry))
+            //process after violation
+            //just add messages
+            if(!isModelAwareValidation)
             {
-                tmpCrossValidationStorageEntry.setComponent(validationTargetEntry.getComponent());
-                tmpCrossValidationStorageEntry.setClientId(validationTargetEntry.getClientId());
+                processTargetAfterCrossComponentValidation(
+                        compareStrategy, crossValidationStorageEntry, validationTargetEntry);
             }
             else
             {
-                tmpCrossValidationStorageEntry.setComponent(crossValidationStorageEntry.getComponent());
-                tmpCrossValidationStorageEntry.setClientId(crossValidationStorageEntry.getClientId());
+                processTargetAfterModelAwareCrossValidation(
+                        compareStrategy, crossValidationStorageEntry);
             }
-            tmpCrossValidationStorageEntry.setConvertedObject(validationTargetEntry.getConvertedValue());
-            tmpCrossValidationStorageEntry.setValidationStrategy(compareStrategy);
 
-            compareStrategy
-                    .processTargetComponentAfterViolation(crossValidationStorageEntry, tmpCrossValidationStorageEntry);
-
-            violationFound = true;
+            //thow exception
+            compareStrategy.processSourceComponentAfterViolation(crossValidationStorageEntry);
         }
+    }
+
+    private static void processTargetAfterCrossComponentValidation(
+            AbstractCompareStrategy compareStrategy,
+            CrossValidationStorageEntry sourceCrossValidationStorageEntry,
+            ProcessedInformationEntry validationTargetEntry)
+    {
+        CrossValidationStorageEntry targetCrossValidationStorageEntry = new CrossValidationStorageEntry();
 
-        if (violationFound)
+        if (compareStrategy.useTargetComponentToDisplayErrorMsg(sourceCrossValidationStorageEntry))
         {
-            compareStrategy.processSourceComponentAfterViolation(crossValidationStorageEntry);
+            targetCrossValidationStorageEntry.setComponent(validationTargetEntry.getComponent());
+            targetCrossValidationStorageEntry.setClientId(validationTargetEntry.getClientId());
+        }
+        else
+        {
+            targetCrossValidationStorageEntry.setComponent(sourceCrossValidationStorageEntry.getComponent());
+            targetCrossValidationStorageEntry.setClientId(sourceCrossValidationStorageEntry.getClientId());
         }
+
+        targetCrossValidationStorageEntry.setConvertedObject(validationTargetEntry.getConvertedValue());
+        targetCrossValidationStorageEntry.setValidationStrategy(compareStrategy);
+
+        //add message
+        compareStrategy.processTargetComponentAfterViolation(
+                sourceCrossValidationStorageEntry, targetCrossValidationStorageEntry);
+    }
+
+    private static void processTargetAfterModelAwareCrossValidation(
+            AbstractCompareStrategy compareStrategy,
+            CrossValidationStorageEntry crossValidationStorageEntry)
+    {
+        //no target - because there is no target component - value was validated against
the model
+        compareStrategy.processTargetComponentAfterViolation(crossValidationStorageEntry,
null);
     }
-}
\ No newline at end of file
+}

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java?rev=740173&r1=740172&r2=740173&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java
Tue Feb  3 00:56:41 2009
@@ -44,6 +44,7 @@
     protected static final String NOT_EQUAL_DATE_TIME = "not equal";
     protected static final String RESULT_KEY = "result";
     protected static final String COMPARED_VALUE_KEY = "target value";
+    protected static final String REVERSE_COMPARED_VALUE_KEY = "reverse target value";
 
     public boolean useTargetComponentToDisplayErrorMsg(
             CrossValidationStorageEntry crossValidationStorageEntry)
@@ -51,6 +52,13 @@
         return true;
     }
 
+    //TODO test & remove
+    @Override
+    protected boolean handleSourceViolation(CrossValidationStorageEntry entryOfSource)
+    {
+        return false;
+    }
+
     public boolean isViolation(Object object1, Object object2, Annotation annotation)
     {
         boolean violationFound;
@@ -88,6 +96,7 @@
         if (violationFound)
         {
             this.violationResultStorage.put(COMPARED_VALUE_KEY, object1);
+            this.violationResultStorage.put(REVERSE_COMPARED_VALUE_KEY, object2);
         }
 
         return violationFound;
@@ -103,12 +112,13 @@
      */
     protected String getValidationErrorMsgKey(Annotation annotation, boolean isTargetComponent)
     {
+        String result = (String) this.violationResultStorage.get(RESULT_KEY);
+
         if (!isTargetComponent)
         {
-            return null;
+            result = reverseResult(result);
         }
 
-        String result = (String) this.violationResultStorage.get(RESULT_KEY);
         if (TOO_EARLY.equals(result))
         {
             return getNotAfterErrorMsgKey((DateIs) annotation);
@@ -123,6 +133,18 @@
         }
     }
 
+    private String reverseResult(String result)
+    {
+        if (TOO_EARLY.equals(result))
+        {
+            return TOO_LATE;
+        }
+        else
+        {
+            return TOO_EARLY;
+        }
+    }
+
     @Override
     protected String getErrorMessageSummary(Annotation annotation, boolean isTargetComponent)
     {
@@ -158,6 +180,31 @@
         return null;
     }
 
+    @Override
+    protected String getReverseErrorMessageSummary(Annotation annotation)
+    {
+        return getErrorMessage(getValidationErrorMsgKey(annotation, false), annotation, false);
+    }
+
+    @Override
+    protected String getReverseErrorMessageDetail(Annotation annotation)
+    {
+        try
+        {
+            return getErrorMessage(getValidationErrorMsgKey(annotation, false)
+                    + DETAIL_MESSAGE_KEY_POSTFIX, annotation, false);
+        }
+        catch (MissingResourceException e)
+        {
+            if(logger.isWarnEnabled())
+            {
+                logger.warn("couldn't find key " + getValidationErrorMsgKey(annotation)
+                    + DETAIL_MESSAGE_KEY_POSTFIX, e);
+            }
+        }
+        return null;
+    }
+
     protected String getErrorMessage(String key, Annotation annotation, boolean isTargetComponent)
     {
         String message = resolveMessage(key);
@@ -165,8 +212,21 @@
         DateFormat dateFormat = DateFormat.getDateInstance(((DateIs) annotation).errorMessageDateStyle(),
             FacesContext.getCurrentInstance().getViewRoot().getLocale());
 
+        String result;
+
+        if(isTargetComponent)
+        {
+            result = message.replace("{0}",
+                        dateFormat.format((Date) this.violationResultStorage.get(COMPARED_VALUE_KEY)));
+        }
+        else
+        {
+            result = message.replace("{0}",
+                        dateFormat.format((Date) this.violationResultStorage.get(REVERSE_COMPARED_VALUE_KEY)));
+        }
+
         //replace placeholder with the value of the other component
-        return message.replace("{0}", dateFormat.format((Date) this.violationResultStorage.get(COMPARED_VALUE_KEY)));
+        return result;
     }
 
     /*
@@ -198,4 +258,4 @@
         }
         return annotation.validationErrorMsgKey();
     }
-}
\ No newline at end of file
+}

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/ELCompareStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/ELCompareStrategy.java?rev=740173&r1=740172&r2=740173&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/ELCompareStrategy.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/ELCompareStrategy.java
Tue Feb  3 00:56:41 2009
@@ -56,8 +56,10 @@
         if (ExtValUtils.getELHelper().isELTermWellFormed(validationTarget) &&
             ExtValUtils.getELHelper().isELTermValid(FacesContext.getCurrentInstance(), validationTarget))
         {
-            tryToValidateValueBinding(crossValidationStorageEntry,
-                new ValueBindingExpression(validationTarget), crossValidationStorage, compareStrategy);
+            tryToValidateValueBinding(
+                    crossValidationStorageEntry,
+                    new ValueBindingExpression(validationTarget), crossValidationStorage,
compareStrategy);
+
             return true;
         }
         return false;
@@ -70,29 +72,54 @@
             CrossValidationStorage crossValidationStorage,
             AbstractCompareStrategy compareStrategy)
     {
-        Map<String, ProcessedInformationEntry> keyConvertedValueMapping = CrossValidationUtils
-                .getOrInitKeyToConvertedValueMapping();
-
-        ProcessedInformationEntry validationTargetEntry = CrossValidationUtils.resolveValidationTargetEntry(
-                keyConvertedValueMapping,
-                CrossValidationUtils.convertValueBindingExpressionToProcessedInformationKey(validationTarget),
-                crossValidationStorageEntry);
+        ProcessedInformationEntry validationTargetEntry =
+                resolveTargetForCrossComponentValidation(crossValidationStorageEntry, validationTarget);
 
         if(validationTargetEntry != null)
         {
-            CrossValidationHelper
-                    .crossValidateCompareStrategy(compareStrategy, crossValidationStorageEntry,
validationTargetEntry);
+            processCrossComponentValidation(compareStrategy, crossValidationStorageEntry,
validationTargetEntry);
         }
         else
         {
-            if(logger.isWarnEnabled())
-            {
-                PropertyDetails propertyDetails = crossValidationStorageEntry.getMetaDataEntry()
-                        .getProperty(PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class);
-                logger.warn("couldn't find converted object for " + propertyDetails.getKey());
-            }
+            processModelAwareCrossValidation(compareStrategy, crossValidationStorageEntry,
validationTarget);
         }
 
         return true;
     }
+
+    private ProcessedInformationEntry resolveTargetForCrossComponentValidation(
+            CrossValidationStorageEntry crossValidationStorageEntry,
+            ValueBindingExpression validationTarget)
+    {
+        Map<String, ProcessedInformationEntry> keyConvertedValueMapping =
+                CrossValidationUtils.getOrInitKeyToConvertedValueMapping();
+
+        return CrossValidationUtils.resolveValidationTargetEntry(
+                keyConvertedValueMapping,
+                CrossValidationUtils.convertValueBindingExpressionToProcessedInformationKey(validationTarget),
+                crossValidationStorageEntry);
+    }
+
+    private void processCrossComponentValidation(
+            AbstractCompareStrategy compareStrategy,
+            CrossValidationStorageEntry crossValidationStorageEntry,
+            ProcessedInformationEntry validationTargetEntry)
+    {
+        CrossValidationHelper
+                .crossValidateCompareStrategy(
+                        compareStrategy, crossValidationStorageEntry, validationTargetEntry,
false);
+    }
+
+    private void processModelAwareCrossValidation(
+            AbstractCompareStrategy compareStrategy,
+            CrossValidationStorageEntry crossValidationStorageEntry,
+            ValueBindingExpression validationTarget)
+    {
+        if(logger.isWarnEnabled())
+        {
+            PropertyDetails propertyDetails = crossValidationStorageEntry.getMetaDataEntry()
+                    .getProperty(PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class);
+            logger.warn("couldn't find converted object for " + propertyDetails.getKey());
+        }
+    }
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalCompareStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalCompareStrategy.java?rev=740173&r1=740172&r2=740173&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalCompareStrategy.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalCompareStrategy.java
Tue Feb  3 00:56:41 2009
@@ -27,10 +27,12 @@
 import org.apache.myfaces.extensions.validator.core.el.ValueBindingExpression;
 import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
 import org.apache.myfaces.extensions.validator.util.CrossValidationUtils;
+import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import java.util.Map;
+import java.lang.reflect.Method;
 
 /**
  * "[property_name]" ... local validation -> cross-component, but no cross-entity validation
@@ -48,6 +50,12 @@
             CrossValidationStorage crossValidationStorage,
             String validationTarget, AbstractCompareStrategy compareStrategy)
     {
+        if(validationTarget.contains("."))
+        {
+            //LocalPropertyChainCompareStrategy will continue
+            return false;
+        }
+
         return tryToValidateLocally(
             crossValidationStorageEntry,
             crossValidationStorage,
@@ -61,41 +69,33 @@
             String targetKey,
             AbstractCompareStrategy compareStrategy)
     {
-        Map<String, ProcessedInformationEntry> keyConvertedValueMapping = CrossValidationUtils
-                .getOrInitKeyToConvertedValueMapping();
-
-        String newKey = createTargetKey(crossValidationStorageEntry, targetKey);
-        if (!keyConvertedValueMapping.containsKey(newKey))
-        {
-            return false;
-        }
+        Map<String, ProcessedInformationEntry> keyConvertedValueMapping =
+                CrossValidationUtils.getOrInitKeyToConvertedValueMapping();
 
-        PropertyDetails propertyDetails = crossValidationStorageEntry.getMetaDataEntry()
-                .getProperty(PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class);
+        boolean isModelAwareValidation =
+                isModelAwareCrossValidation(crossValidationStorageEntry, keyConvertedValueMapping,
targetKey);
 
-        String sourceKey = propertyDetails.getKey();
-
-        if(!sourceKey.contains("."))
-        {
-            throw new IllegalStateException("source path: " + sourceKey + " invalid");
-        }
+        String targetProperty = targetKey;
 
+        String sourceKey = resolveSourceKey(crossValidationStorageEntry);
         targetKey = sourceKey.substring(0, sourceKey.lastIndexOf(".") + 1) + targetKey;
 
         ProcessedInformationEntry validationTargetEntry = CrossValidationUtils.resolveValidationTargetEntry(
                 keyConvertedValueMapping, targetKey, crossValidationStorageEntry);
 
-        if (validationTargetEntry != null)
+        if (validationTargetEntry != null && validationTargetEntry.getComponent()
!= null && !isModelAwareValidation)
+        {
+            processCrossComponentValidation(compareStrategy, crossValidationStorageEntry,
validationTargetEntry);
+        }
+        //no target - because there is no target component - value was validated against
the model
+        else if(validationTargetEntry != null && isModelAwareValidation)
         {
-            CrossValidationHelper
-                    .crossValidateCompareStrategy(compareStrategy, crossValidationStorageEntry,
validationTargetEntry);
+            processModelAwareCrossValidation(
+                    compareStrategy, crossValidationStorageEntry, validationTargetEntry,
targetProperty);
         }
         else
         {
-            if(logger.isWarnEnabled())
-            {
-                logger.warn("couldn't find converted object for " + propertyDetails.getKey());
-            }
+            unsupportedCase(crossValidationStorageEntry);
         }
 
         return true;
@@ -115,4 +115,81 @@
             .getExpressionString();
         return result.substring(2, result.length() -1);
     }
+
+    protected 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 boolean isModelAwareCrossValidation(
+            CrossValidationStorageEntry crossValidationStorageEntry,
+            Map<String, ProcessedInformationEntry> keyConvertedValueMapping,
+            String targetKey)
+    {
+        String newKey = createTargetKey(crossValidationStorageEntry, targetKey);
+
+        return !keyConvertedValueMapping.containsKey(newKey);
+
+    }
+
+    private String resolveSourceKey(CrossValidationStorageEntry crossValidationStorageEntry)
+    {
+        PropertyDetails propertyDetails = crossValidationStorageEntry.getMetaDataEntry()
+                .getProperty(PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class);
+
+        String sourceKey = propertyDetails.getKey();
+
+        if(!sourceKey.contains("."))
+        {
+            throw new IllegalStateException("source path: " + sourceKey + " invalid");
+        }
+
+        return sourceKey;
+    }
+
+    private void unsupportedCase(CrossValidationStorageEntry crossValidationStorageEntry)
+    {
+        if(logger.isWarnEnabled())
+        {
+            logger.warn("couldn't find converted object for " +  crossValidationStorageEntry.getMetaDataEntry()
+            .getProperty(PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class).getKey());
+        }
+    }
+
+    private void processCrossComponentValidation(
+            AbstractCompareStrategy compareStrategy,
+            CrossValidationStorageEntry crossValidationStorageEntry,
+            ProcessedInformationEntry validationTargetEntry)
+    {
+        CrossValidationHelper
+                .crossValidateCompareStrategy(
+                        compareStrategy, crossValidationStorageEntry, validationTargetEntry,
false);
+    }
+
+    private void processModelAwareCrossValidation(
+            AbstractCompareStrategy compareStrategy,
+            CrossValidationStorageEntry crossValidationStorageEntry,
+            ProcessedInformationEntry validationTargetEntry,
+            String targetProperty)
+    {
+        validationTargetEntry
+                .setConvertedValue(getValueOfProperty(validationTargetEntry.getBean(), targetProperty));
+
+        CrossValidationHelper
+                .crossValidateCompareStrategy(
+                        compareStrategy, crossValidationStorageEntry, validationTargetEntry,
true);
+    }
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalPropertyChainCompareStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalPropertyChainCompareStrategy.java?rev=740173&r1=740172&r2=740173&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalPropertyChainCompareStrategy.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalPropertyChainCompareStrategy.java
Tue Feb  3 00:56:41 2009
@@ -20,14 +20,16 @@
 
 import org.apache.myfaces.extensions.validator.crossval.CrossValidationStorage;
 import org.apache.myfaces.extensions.validator.crossval.CrossValidationStorageEntry;
+import org.apache.myfaces.extensions.validator.crossval.ProcessedInformationEntry;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.util.CrossValidationUtils;
+import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
 import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
 import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
-import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
+import java.util.Map;
 
 /**
  * "[local_property.property1.property2]"
@@ -39,66 +41,107 @@
 class LocalPropertyChainCompareStrategy extends LocalCompareStrategy
 {
     @Override
+    public boolean evaluateReferenceAndValidate(
+            CrossValidationStorageEntry crossValidationStorageEntry,
+            CrossValidationStorage crossValidationStorage,
+            String validationTarget, AbstractCompareStrategy compareStrategy)
+    {
+        if(!validationTarget.contains("."))
+        {
+            //not supported - TODO add logging
+            return false;
+        }
+
+        return tryToValidateLocally(
+            crossValidationStorageEntry,
+            crossValidationStorage,
+            validationTarget,
+            compareStrategy);
+    }
+
+    @Override
     protected boolean tryToValidateLocally(CrossValidationStorageEntry crossValidationStorageEntry,
                                            CrossValidationStorage crossValidationStorage,
                                            String targetKey,
                                            AbstractCompareStrategy compareStrategy)
     {
-        PropertyDetails propertyDetails = crossValidationStorageEntry.getMetaDataEntry()
-            .getProperty(PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class);
+        Map<String, ProcessedInformationEntry> keyConvertedValueMapping =
+                CrossValidationUtils.getOrInitKeyToConvertedValueMapping();
 
-        Object newBase = ReflectionUtils
-            .getBaseOfPropertyChain(propertyDetails.getBaseObject(), targetKey);
+        String newKey = createTargetKey(crossValidationStorageEntry, targetKey);
 
-        if(targetKey.contains("."))
+        if (keyConvertedValueMapping.containsKey(newKey))
         {
-            //find the last property
-            targetKey = targetKey.substring(targetKey.lastIndexOf(".") + 1, targetKey.length());
-        }
+            ProcessedInformationEntry validationTargetEntry = keyConvertedValueMapping.get(newKey);
+            Object targetValue = validationTargetEntry.getConvertedValue();
 
-        Object targetValue = getValueOfProperty(newBase, targetKey);
+            processCrossComponentValidation(compareStrategy, crossValidationStorageEntry,
targetValue);
+        }
+        //no target - because there is no target component - value was validated against
the model
+        else
+        {
+            processModelAwareCrossValidation(compareStrategy, crossValidationStorageEntry,
targetKey);
+        }
 
-        boolean violationFound = false;
+        return true;
+    }
 
+    private void processCrossComponentValidation(
+            AbstractCompareStrategy compareStrategy,
+            CrossValidationStorageEntry crossValidationStorageEntry,
+            Object targetValue)
+    {
+        //no target - because there is no target component - value was validated against
the model
         if (compareStrategy.isViolation(crossValidationStorageEntry.getConvertedObject(),
                                 targetValue, crossValidationStorageEntry.getMetaDataEntry().getValue(Annotation.class)))
         {
-
             CrossValidationStorageEntry tmpCrossValidationStorageEntry = new CrossValidationStorageEntry();
             tmpCrossValidationStorageEntry.setComponent(crossValidationStorageEntry.getComponent());
             tmpCrossValidationStorageEntry.setClientId(crossValidationStorageEntry.getClientId());
             tmpCrossValidationStorageEntry.setConvertedObject(targetValue);
             tmpCrossValidationStorageEntry.setValidationStrategy(compareStrategy);
 
-            compareStrategy
-                    .processTargetComponentAfterViolation(crossValidationStorageEntry, tmpCrossValidationStorageEntry);
-
-            violationFound = true;
-        }
+            //process after violation
+            //just add messages
+            if(crossValidationStorageEntry.getComponent() != null)
+            {
+                compareStrategy.processTargetComponentAfterViolation(
+                        crossValidationStorageEntry, tmpCrossValidationStorageEntry);
+            }
+            else
+            {
+                compareStrategy.processTargetComponentAfterViolation(crossValidationStorageEntry,
null);
+            }
 
-        if (violationFound)
-        {
+            //thow exception
             compareStrategy.processSourceComponentAfterViolation(crossValidationStorageEntry);
         }
-
-        return true;
     }
 
-    private Object getValueOfProperty(Object base, String property)
+    private void processModelAwareCrossValidation(
+            AbstractCompareStrategy compareStrategy,
+            CrossValidationStorageEntry crossValidationStorageEntry, String targetKey)
     {
-        property = property.substring(0,1).toUpperCase() + property.substring(1, property.length());
-        Method targetMethod = ReflectionUtils.tryToGetMethod(base.getClass(), "get" + property);
+        PropertyDetails propertyDetails = crossValidationStorageEntry.getMetaDataEntry()
+            .getProperty(PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class);
 
-        if(targetMethod == null)
-        {
-            targetMethod = ReflectionUtils.tryToGetMethod(base.getClass(), "is" + property);
-        }
+        Object newBase = ReflectionUtils
+            .getBaseOfPropertyChain(propertyDetails.getBaseObject(), targetKey);
 
-        if(targetMethod == null)
+        if(targetKey.contains("."))
         {
-            throw new IllegalStateException(
-                "class " + base.getClass() + " has no public get/is " + property.toLowerCase());
+            //find the last property
+            targetKey = targetKey.substring(targetKey.lastIndexOf(".") + 1, targetKey.length());
         }
-        return ReflectionUtils.tryToInvokeMethod(base, targetMethod);
+
+        Object targetValue = getValueOfProperty(newBase, targetKey);
+
+        ProcessedInformationEntry targetEntry = new ProcessedInformationEntry();
+        targetEntry.setBean(newBase);
+        targetEntry.setConvertedValue(targetValue);
+
+        CrossValidationHelper
+                .crossValidateCompareStrategy(
+                        compareStrategy, crossValidationStorageEntry, targetEntry, true);
     }
 }
\ No newline at end of file

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/util/CrossValidationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/util/CrossValidationUtils.java?rev=740173&r1=740172&r2=740173&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/util/CrossValidationUtils.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/util/CrossValidationUtils.java
Tue Feb  3 00:56:41 2009
@@ -90,6 +90,29 @@
         ProcessedInformationEntry processedInformationEntry =
             keyToConvertedValueMapping.get(targetKey);
 
+        //value not submitted at this request - use model value (validation against the model)
+        if(processedInformationEntry == null)
+        {
+            FacesContext facesContext = FacesContext.getCurrentInstance();
+            ProcessedInformationEntry newProcessedInformationEntry = new ProcessedInformationEntry();
+            ValueBindingExpression valueBindingExpression = new ValueBindingExpression("#{"
+ targetKey + "}");
+
+            Object baseObject = ExtValUtils.getELHelper()
+                    .getValueOfExpression(facesContext, valueBindingExpression.getBaseExpression());
+
+            if(baseObject != null)
+            {
+                newProcessedInformationEntry.setBean(baseObject);
+                newProcessedInformationEntry.setConvertedValue(
+                        ExtValUtils.getELHelper().getValueOfExpression(facesContext, valueBindingExpression));
+
+                return  newProcessedInformationEntry;
+            }
+
+            //TODO logging
+            return null;
+        }
+
         //simple case
         if (processedInformationEntry.getFurtherEntries() == null)
         {



Mime
View raw message