myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r697054 - in /myfaces/extensions/validator/branches/jsf_1.1: core/src/main/java/org/apache/myfaces/extensions/validator/core/ core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/ core/src/main/java/org/apache...
Date Fri, 19 Sep 2008 11:12:30 GMT
Author: gpetracek
Date: Fri Sep 19 04:12:29 2008
New Revision: 697054

URL: http://svn.apache.org/viewvc?rev=697054&view=rev
Log:
meta data extraction, update of examples

Added:
    myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/MetaDataExtractor.java
Removed:
    myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/RequiredAttributeStrategy.java
Modified:
    myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ValidationUtils.java
    myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/custom/validation_messages.properties
    myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
    myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/custom/validation_messages.properties
    myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
    myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JoinValidationStrategy.java
    myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JpaValidationStrategy.java
    myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/LengthStrategy.java
    myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/RequiredStrategy.java

Added: myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/MetaDataExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/MetaDataExtractor.java?rev=697054&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/MetaDataExtractor.java
(added)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/core/MetaDataExtractor.java
Fri Sep 19 04:12:29 2008
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@UsageInformation(UsageCategory.API)
+public interface MetaDataExtractor
+{
+    Map<String, Object> extractMetaData(Annotation annotation);
+}

Modified: myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ValidationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ValidationUtils.java?rev=697054&r1=697053&r2=697054&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ValidationUtils.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ValidationUtils.java
Fri Sep 19 04:12:29 2008
@@ -23,13 +23,14 @@
 import org.apache.myfaces.extensions.validator.core.annotation.AnnotationEntry;
 import org.apache.myfaces.extensions.validator.core.annotation.extractor.AnnotationExtractor;
 import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
-import org.apache.myfaces.extensions.validator.core.validation.strategy.RequiredAttributeStrategy;
+import org.apache.myfaces.extensions.validator.core.MetaDataExtractor;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
 
 import javax.faces.component.EditableValueHolder;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
+import java.util.Map;
 
 /**
  * @author Gerhard Petracek
@@ -89,11 +90,13 @@
                 .getValidationStrategyFactory().create(
                 entry.getAnnotation());
 
-            if (validationStrategy != null && validationStrategy instanceof RequiredAttributeStrategy)
+            if (validationStrategy != null && validationStrategy instanceof MetaDataExtractor)
             {
-                if(((RequiredAttributeStrategy)validationStrategy).markedAsRequired(entry.getAnnotation()))
+                Map<String, Object> metaData = ((MetaDataExtractor)validationStrategy)
+                                                    .extractMetaData(entry.getAnnotation());
+                if(metaData.containsKey("required"))
                 {
-                    return true;
+                    return (Boolean)metaData.get("required");
                 }
             }
         }

Modified: myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/custom/validation_messages.properties
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/custom/validation_messages.properties?rev=697054&r1=697053&r2=697054&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/custom/validation_messages.properties
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/custom/validation_messages.properties
Fri Sep 19 04:12:29 2008
@@ -1,2 +1,2 @@
-repeated_password_requried=please retype the password
-repeated_password_requried_details=please retype the password
\ No newline at end of file
+repeated_password_required=please retype the password
+repeated_password_required_details=please retype the password
\ No newline at end of file

Modified: myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java?rev=697054&r1=697053&r2=697054&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
Fri Sep 19 04:12:29 2008
@@ -42,7 +42,7 @@
     @Equals("passwordRepeated")
     private String password;
 
-    @Required(validationErrorMsgKey = "repeated_password_requried")
+    @Required(validationErrorMsgKey = "repeated_password_required")
     private String passwordRepeated;
 
     //use #{registrationPage.person.nickName}, #{person.nickName}

Modified: myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/custom/validation_messages.properties
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/custom/validation_messages.properties?rev=697054&r1=697053&r2=697054&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/custom/validation_messages.properties
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/custom/validation_messages.properties
Fri Sep 19 04:12:29 2008
@@ -1,3 +1,3 @@
 # this message bundle is picked up via convention
-repeated_password_requried=please retype the password
-repeated_password_requried_details=please retype the password
\ No newline at end of file
+repeated_password_required=please retype the password
+repeated_password_required_details=please retype the password
\ No newline at end of file

Modified: myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java?rev=697054&r1=697053&r2=697054&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
Fri Sep 19 04:12:29 2008
@@ -42,7 +42,7 @@
     @Equals("passwordRepeated")
     private String password;
 
-    @Required(validationErrorMsgKey = "repeated_password_requried")
+    @Required(validationErrorMsgKey = "repeated_password_required")
     private String passwordRepeated;
 
     //use #{registrationPage.person.nickName}, #{person.nickName}

Modified: myfaces/extensions/validator/branches/jsf_1.1/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/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JoinValidationStrategy.java?rev=697054&r1=697053&r2=697054&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JoinValidationStrategy.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JoinValidationStrategy.java
Fri Sep 19 04:12:29 2008
@@ -24,18 +24,20 @@
 import org.apache.myfaces.extensions.validator.core.annotation.extractor.AnnotationExtractor;
 import org.apache.myfaces.extensions.validator.core.validation.strategy.AbstractValidatorAdapter;
 import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
-import org.apache.myfaces.extensions.validator.core.validation.strategy.RequiredAttributeStrategy;
+import org.apache.myfaces.extensions.validator.core.MetaDataExtractor;
 import org.apache.myfaces.extensions.validator.util.FactoryUtils;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.validator.ValidatorException;
 import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * @author Gerhard Petracek
  */
-public class JoinValidationStrategy extends AbstractValidatorAdapter implements RequiredAttributeStrategy
+public class JoinValidationStrategy extends AbstractValidatorAdapter implements MetaDataExtractor
 {
     public void processValidation(FacesContext facesContext,
             UIComponent uiComponent, AnnotationEntry annotationEntry,
@@ -71,7 +73,7 @@
         }
     }
 
-    public boolean markedAsRequired(Annotation annotation)
+    public Map<String, Object> extractMetaData(Annotation annotation)
     {
         AnnotationExtractor extractor = new DefaultPropertyScanningAnnotationExtractor();
 
@@ -79,6 +81,8 @@
 
         ValidationStrategy validationStrategy;
 
+        Map<String, Object> results = new HashMap<String, Object>();
+
         for (String targetExpression : targetExpressions)
         {
             for (AnnotationEntry entry : extractor.extractAnnotations(
@@ -88,15 +92,12 @@
                         .getValidationStrategyFactory().create(
                                 entry.getAnnotation());
 
-                if (validationStrategy != null && validationStrategy instanceof RequiredAttributeStrategy)
+                if (validationStrategy != null && validationStrategy instanceof MetaDataExtractor)
                 {
-                    if(((RequiredAttributeStrategy)validationStrategy).markedAsRequired(entry.getAnnotation()))
-                    {
-                        return true;
-                    }
+                    results.putAll(((MetaDataExtractor)validationStrategy).extractMetaData(entry.getAnnotation()));
                 }
             }
         }
-        return false;
+        return results;
     }
 }

Modified: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JpaValidationStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JpaValidationStrategy.java?rev=697054&r1=697053&r2=697054&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JpaValidationStrategy.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/JpaValidationStrategy.java
Fri Sep 19 04:12:29 2008
@@ -20,7 +20,7 @@
 
 import org.apache.myfaces.extensions.validator.core.annotation.AnnotationEntry;
 import org.apache.myfaces.extensions.validator.core.validation.strategy.AbstractValidationStrategy;
-import org.apache.myfaces.extensions.validator.core.validation.strategy.RequiredAttributeStrategy;
+import org.apache.myfaces.extensions.validator.core.MetaDataExtractor;
 import org.apache.myfaces.extensions.validator.internal.ToDo;
 import org.apache.myfaces.extensions.validator.internal.Priority;
 
@@ -32,11 +32,13 @@
 import javax.persistence.ManyToOne;
 import javax.persistence.OneToOne;
 import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * @author Gerhard Petracek
  */
-public class JpaValidationStrategy extends AbstractValidationStrategy implements RequiredAttributeStrategy
+public class JpaValidationStrategy extends AbstractValidationStrategy implements MetaDataExtractor
 {
 
     private static final String VALIDATE_REQUIRED = "required";
@@ -68,18 +70,27 @@
         }
     }
 
-    @ToDo(value = Priority.MEDIUM, description = "check")
-    public boolean markedAsRequired(Annotation annotation)
+    @ToDo(value = Priority.HIGH, description = "impl. the rest")
+    public Map<String, Object> extractMetaData(Annotation annotation)
     {
-        if(annotation instanceof Column && !((Column) annotation).nullable())
+        Map<String, Object> results = new HashMap<String, Object>();
+
+        if(annotation instanceof Column)
         {
-            return true;
+            if(!((Column) annotation).nullable())
+            {
+                results.put("required", true);
+            }
         }
-        else if(annotation instanceof Basic && !((Basic)annotation).optional())
+        else if(annotation instanceof Basic)
         {
-            return true;
+            if(!((Basic)annotation).optional())
+            {
+                results.put("required", true);
+            }
         }
-        return false;
+        //TODO impl. the rest!!!
+        return results;
     }
 
     private void validateColumnAnnotation(Column column, Object convertedObject)

Modified: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/LengthStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/LengthStrategy.java?rev=697054&r1=697053&r2=697054&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/LengthStrategy.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/LengthStrategy.java
Fri Sep 19 04:12:29 2008
@@ -21,18 +21,20 @@
 import org.apache.myfaces.extensions.validator.baseval.annotation.Length;
 import org.apache.myfaces.extensions.validator.core.annotation.AnnotationEntry;
 import org.apache.myfaces.extensions.validator.core.validation.strategy.AbstractValidatorAdapter;
-import org.apache.myfaces.extensions.validator.core.validation.strategy.RequiredAttributeStrategy;
+import org.apache.myfaces.extensions.validator.core.MetaDataExtractor;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.validator.LengthValidator;
 import javax.faces.validator.ValidatorException;
 import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * @author Gerhard Petracek
  */
-public class LengthStrategy extends AbstractValidatorAdapter implements RequiredAttributeStrategy
+public class LengthStrategy extends AbstractValidatorAdapter implements MetaDataExtractor
 {
     protected void processValidation(FacesContext facesContext,
             UIComponent uiComponent, AnnotationEntry annotationEntry,
@@ -48,8 +50,17 @@
         lengthValidator.validate(facesContext, uiComponent, convertedObject);
     }
 
-    public boolean markedAsRequired(Annotation annotation)
+    public Map<String, Object> extractMetaData(Annotation annotation)
     {
-        return ((Length)annotation).minimum() > 0;
+        Map<String, Object> results = new HashMap<String, Object>();
+        int minimum = ((Length)annotation).minimum();
+        results.put("length", minimum);
+
+        if(minimum > 0)
+        {
+            results.put("required", true);
+        }
+
+        return results;
     }
 }
\ No newline at end of file

Modified: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/RequiredStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/RequiredStrategy.java?rev=697054&r1=697053&r2=697054&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/RequiredStrategy.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/RequiredStrategy.java
Fri Sep 19 04:12:29 2008
@@ -21,17 +21,19 @@
 import org.apache.myfaces.extensions.validator.baseval.annotation.Required;
 import org.apache.myfaces.extensions.validator.core.annotation.AnnotationEntry;
 import org.apache.myfaces.extensions.validator.core.validation.strategy.AbstractValidationStrategy;
-import org.apache.myfaces.extensions.validator.core.validation.strategy.RequiredAttributeStrategy;
+import org.apache.myfaces.extensions.validator.core.MetaDataExtractor;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.validator.ValidatorException;
 import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * @author Gerhard Petracek
  */
-public class RequiredStrategy extends AbstractValidationStrategy implements RequiredAttributeStrategy
+public class RequiredStrategy extends AbstractValidationStrategy implements MetaDataExtractor
 {
     public void processValidation(FacesContext facesContext,
             UIComponent uiComponent, AnnotationEntry annotationEntry,
@@ -45,9 +47,11 @@
         }
     }
 
-    public boolean markedAsRequired(Annotation annotation)
+    public Map<String, Object> extractMetaData(Annotation annotation)
     {
-        return true;
+        Map<String, Object> results = new HashMap<String, Object>();
+        results.put("required", true);
+        return results;
     }
 
     protected String getValidationErrorMsgKey(Annotation annotation)



Mime
View raw message