myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r831625 - in /myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval: storage/ util/ validation/
Date Sun, 01 Nov 2009 00:50:02 GMT
Author: gpetracek
Date: Sun Nov  1 00:50:02 2009
New Revision: 831625

URL: http://svn.apache.org/viewvc?rev=831625&view=rev
Log:
small refactorings

Modified:
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationEntry.java
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationEntry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationEntry.java?rev=831625&r1=831624&r2=831625&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationEntry.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/ModelValidationEntry.java
Sun Nov  1 00:50:02 2009
@@ -18,9 +18,9 @@
  */
 package org.apache.myfaces.extensions.validator.beanval.storage;
 
-import org.apache.myfaces.extensions.validator.beanval.annotation.ModelValidation;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import static org.apache.myfaces.extensions.validator.internal.UsageCategory.INTERNAL;
+import org.apache.myfaces.extensions.validator.beanval.annotation.ModelValidation;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -35,9 +35,11 @@
 public class ModelValidationEntry
 {
     private UIComponent component;
-    private ModelValidation metaData;
     private List<Class> groups = new ArrayList<Class>();
     private List<Object> validationTargets = new ArrayList<Object>();
+    private List<String> validationTargetExpressions = new ArrayList<String>();
+    private boolean displayInline = false;
+    private String message = ModelValidation.DEFAULT_MESSAGE;
     private Object metaDataSourceObject;
     private String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
 
@@ -84,6 +86,14 @@
         }
     }
 
+    public void addValidationTargetExpression(String targetExpression)
+    {
+        if(!this.validationTargetExpressions.contains(targetExpression))
+        {
+            this.validationTargetExpressions.add(targetExpression);
+        }
+    }
+
     /*
      * generated
      */
@@ -97,16 +107,6 @@
         this.component = component;
     }
 
-    public ModelValidation getMetaData()
-    {
-        return metaData;
-    }
-
-    public void setMetaData(ModelValidation metaData)
-    {
-        this.metaData = metaData;
-    }
-
     public Class[] getGroups()
     {
         return this.groups.toArray(new Class[this.groups.size()]);
@@ -127,6 +127,16 @@
         this.validationTargets = validationTargets;
     }
 
+    public List<String> getValidationTargetExpressions()
+    {
+        return validationTargetExpressions;
+    }
+
+    public void setValidationTargetExpressions(List<String> validationTargetExpressions)
+    {
+        this.validationTargetExpressions = validationTargetExpressions;
+    }
+
     public Object getMetaDataSourceObject()
     {
         return metaDataSourceObject;
@@ -168,6 +178,26 @@
         return true;
     }
 
+    public boolean isDisplayInline()
+    {
+        return displayInline;
+    }
+
+    public void setDisplayInline(boolean displayInline)
+    {
+        this.displayInline = displayInline;
+    }
+
+    public String getMessage()
+    {
+        return message;
+    }
+
+    public void setMessage(String message)
+    {
+        this.message = message;
+    }
+
     @Override
     public int hashCode()
     {

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java?rev=831625&r1=831624&r2=831625&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
Sun Nov  1 00:50:02 2009
@@ -329,27 +329,38 @@
 
     private static void addTargetsForModelValidation(ModelValidationEntry modelValidationEntry,
Object defaultTarget)
     {
-        if (modelValidationEntry.getMetaData().validationTargets().length == 1 &&
-                modelValidationEntry.getMetaData().validationTargets()[0].equals(ModelValidation.DEFAULT_TARGET))
+        if (isDefaultTarget(modelValidationEntry))
         {
             modelValidationEntry.addValidationTarget(defaultTarget);
         }
         else
         {
-            Object target;
-            for (String modelValidationTarget : modelValidationEntry.getMetaData().validationTargets())
-            {
-                target = resolveTarget(modelValidationEntry.getMetaDataSourceObject(), modelValidationTarget);
+            addValidationTargets(modelValidationEntry);
+        }
+    }
 
-                if (target == null && LOG.isErrorEnabled())
-                {
-                    LOG.error("target unreachable - source class: " +
-                            modelValidationEntry.getMetaDataSourceObject().getClass().getName()
+
-                            " target to resolve: " + modelValidationTarget);
-                }
+    private static boolean isDefaultTarget(ModelValidationEntry modelValidationEntry)
+    {
+        return modelValidationEntry.getValidationTargetExpressions().size() == 1 &&
+                modelValidationEntry.getValidationTargetExpressions().iterator().next()
+                        .equals(ModelValidation.DEFAULT_TARGET);
+    }
 
-                modelValidationEntry.addValidationTarget(target);
+    private static void addValidationTargets(ModelValidationEntry modelValidationEntry)
+    {
+        Object target;
+        for (String modelValidationTarget : modelValidationEntry.getValidationTargetExpressions())
+        {
+            target = resolveTarget(modelValidationEntry.getMetaDataSourceObject(), modelValidationTarget);
+
+            if (target == null && LOG.isErrorEnabled())
+            {
+                LOG.error("target unreachable - source class: " +
+                        modelValidationEntry.getMetaDataSourceObject().getClass().getName()
+
+                        " target to resolve: " + modelValidationTarget);
             }
+
+            modelValidationEntry.addValidationTarget(target);
         }
     }
 
@@ -393,9 +404,15 @@
         ModelValidationEntry modelValidationEntry = new ModelValidationEntry();
 
         modelValidationEntry.setGroups(Arrays.asList(beanValidation.useGroups()));
-        modelValidationEntry.setMetaData(beanValidation.modelValidation());
+        modelValidationEntry.setDisplayInline(beanValidation.modelValidation().displayInline());
+        modelValidationEntry.setMessage(beanValidation.modelValidation().message());
         modelValidationEntry.setMetaDataSourceObject(metaDataSourceObject);
 
+        for(String validationTargetExpression : beanValidation.modelValidation().validationTargets())
+        {
+            modelValidationEntry.addValidationTargetExpression(validationTargetExpression);
+        }
+
         if (beanValidation.restrictGroups().length > 0)
         {
             restrictedGroupsForModelValidation.addAll(Arrays.asList(beanValidation.restrictGroups()));

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java?rev=831625&r1=831624&r2=831625&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java
Sun Nov  1 00:50:02 2009
@@ -107,7 +107,7 @@
             }
 
             if (processedValidationTargets.contains(validationTarget) &&
-                    !modelValidationEntry.getMetaData().displayInline())
+                    !modelValidationEntry.isDisplayInline())
             {
                 continue;
             }
@@ -189,7 +189,7 @@
                 result = results.get(modelValidationEntry.getComponent().getClientId(facesContext));
 
                 constraintViolation = (ConstraintViolation) violationsIterator.next();
-                if (modelValidationEntry.getMetaData().displayInline())
+                if (modelValidationEntry.isDisplayInline())
                 {
                     result.addFacesMessageHolder(createFacesMessageHolderForConstraintViolation(
                             constraintViolation, modelValidationEntry, validationTarget,
true));
@@ -279,14 +279,14 @@
         if (!isDefaultMessage(modelValidationEntry))
         {
             return interpolateValidationErrorMessage(
-                    modelValidationEntry.getMetaData().message(), validationTarget, violation);
+                    modelValidationEntry.getMessage(), validationTarget, violation);
         }
         return violation.getMessage();
     }
 
     private boolean isDefaultMessage(ModelValidationEntry modelValidationEntry)
     {
-        return ModelValidation.DEFAULT_MESSAGE.equals(modelValidationEntry.getMetaData().message());
+        return ModelValidation.DEFAULT_MESSAGE.equals(modelValidationEntry.getMessage());
     }
 
     private String interpolateValidationErrorMessage(String extValInlineMessage,



Mime
View raw message