myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r827008 - in /myfaces/extensions/validator/branches/branch_for_jsf_1_1: examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/ examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/vali...
Date Tue, 20 Oct 2009 09:02:19 GMT
Author: gpetracek
Date: Tue Oct 20 09:02:18 2009
New Revision: 827008

URL: http://svn.apache.org/viewvc?rev=827008&view=rev
Log:
basic composing constraint support

Added:
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/Birthday.java
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/Name.java
Modified:
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptorInternals.java

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/Birthday.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/Birthday.java?rev=827008&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/Birthday.java
(added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/Birthday.java
Tue Oct 20 09:02:18 2009
@@ -0,0 +1,45 @@
+/*
+ * 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.demo.constraints;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Past;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Past
+@NotNull
+
+@Constraint(validatedBy = {})
+@Retention(RUNTIME)
+@Target({METHOD, FIELD, ANNOTATION_TYPE})
+public @interface Birthday
+{
+    public abstract String message() default "no valid birthday";
+
+    public abstract Class<?>[] groups() default {};
+
+    public abstract Class<? extends Payload>[] payload() default {};
+}

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/Name.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/Name.java?rev=827008&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/Name.java
(added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/constraints/Name.java
Tue Oct 20 09:02:18 2009
@@ -0,0 +1,49 @@
+/*
+ * 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.demo.constraints;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import javax.validation.OverridesAttribute;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@NotNull
+@Size(min = 2)
+
+@Constraint(validatedBy = {})
+@Retention(RUNTIME)
+@Target({METHOD, FIELD, ANNOTATION_TYPE})
+public @interface Name
+{
+    String message() default "invalid name"; //not used
+
+    Class<?>[] groups() default {};
+
+    Class<? extends Payload>[] payload() default {};
+
+    @OverridesAttribute(constraint = Size.class, name = "max")
+    int maxLength() default 20;
+}

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java?rev=827008&r1=827007&r2=827008&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java
Tue Oct 20 09:02:18 2009
@@ -18,7 +18,8 @@
  */
 package org.apache.myfaces.extensions.validator.demo.domain;
 
-import org.apache.myfaces.extensions.validator.beanval.payload.DisableClientSideValidation;
+import org.apache.myfaces.extensions.validator.demo.constraints.Name;
+import org.apache.myfaces.extensions.validator.demo.constraints.Birthday;
 
 import javax.validation.constraints.Size;
 import javax.validation.constraints.NotNull;
@@ -27,18 +28,16 @@
 
 public class Person
 {
-    @Size(min = 2, max = 20)
+    @Name(maxLength = 30)
     private String firstName;
 
-    @NotNull(payload = DisableClientSideValidation.class)
-    @Size(min = 2, max = 20, payload = DisableClientSideValidation.class)
+    @Name(maxLength = 30)
     private String lastName;
 
     @Size(min = 2, max = 10)
     private String password;
 
-    @Past
-    @NotNull
+    @Birthday
     private Date birthday;
 
     @Past

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java?rev=827008&r1=827007&r2=827008&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
Tue Oct 20 09:02:18 2009
@@ -19,16 +19,17 @@
 package org.apache.myfaces.extensions.validator.demo.gui.beans;
 
 import org.apache.myfaces.extensions.validator.demo.domain.Person;
+import org.apache.myfaces.extensions.validator.beanval.payload.DisableClientSideValidation;
 
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
 
 public class RegistrationPage
 {
-    @NotNull
+    @NotNull(payload = DisableClientSideValidation.class)
     private String password;
 
-    @NotNull
+    @NotNull(payload = DisableClientSideValidation.class)
     private String passwordRepeated;
 
     private Person person;

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptorInternals.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/BeanValidationInterceptorInternals.java?rev=827008&r1=827007&r2=827008&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptorInternals.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptorInternals.java
Tue Oct 20 09:02:18 2009
@@ -27,6 +27,8 @@
 import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.ToDo;
+import org.apache.myfaces.extensions.validator.internal.Priority;
 import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 import org.apache.myfaces.extensions.validator.util.JsfUtils;
 
@@ -43,6 +45,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.HashMap;
 import java.util.Set;
 
 /**
@@ -113,29 +116,60 @@
         }
     }
 
+    @ToDo(value = Priority.MEDIUM, description = "ConstraintDescriptor#isReportAsSingleViolation")
     private Map<String, Object> transformConstraintDescriptorToMetaData(
             ConstraintDescriptor<?> constraintDescriptor, Class elementClass)
     {
-        Map<String, Object> result = null;
+        Map<String, Object> result = new HashMap<String, Object>();
         MetaDataTransformer metaDataTransformer;
-        MetaDataEntry entry;
 
         metaDataTransformer = ExtValUtils.getMetaDataTransformerForValidationStrategy(
                 new BeanValidationVirtualValidationStrategy(constraintDescriptor, elementClass));
 
         if (metaDataTransformer != null)
         {
-            if (this.logger.isDebugEnabled())
+            result.putAll(transformMetaData(metaDataTransformer, constraintDescriptor));
+        }
+
+        if(!constraintDescriptor.isReportAsSingleViolation())
+        {
+            Set<ConstraintDescriptor<?>> composingConstraints = constraintDescriptor.getComposingConstraints();
+            if(composingConstraints != null && !composingConstraints.isEmpty())
             {
-                this.logger.debug(metaDataTransformer.getClass().getName() + " instantiated");
+                result.putAll(transformComposingConstraints(composingConstraints, elementClass));
             }
+        }
 
-            entry = new MetaDataEntry();
-            entry.setKey(constraintDescriptor.getAnnotation().annotationType().getName());
-            entry.setValue(constraintDescriptor);
+        return result;
+    }
 
-            result = metaDataTransformer.convertMetaData(entry);
+    private Map<String, Object> transformComposingConstraints(
+            Set<ConstraintDescriptor<?>> composingConstraints, Class elementClass)
+    {
+        Map<String, Object> result = new HashMap<String, Object>();
+        for(ConstraintDescriptor constraintDescriptor : composingConstraints)
+        {
+            result.putAll(transformConstraintDescriptorToMetaData(constraintDescriptor, elementClass));
         }
+
+        return result;
+    }
+
+    private Map<String, Object> transformMetaData(
+            MetaDataTransformer metaDataTransformer, ConstraintDescriptor<?> constraintDescriptor)
+    {
+        MetaDataEntry entry;
+        Map<String, Object> result;
+        if (this.logger.isDebugEnabled())
+        {
+            this.logger.debug(metaDataTransformer.getClass().getName() + " instantiated");
+        }
+
+        entry = new MetaDataEntry();
+        entry.setKey(constraintDescriptor.getAnnotation().annotationType().getName());
+        entry.setValue(constraintDescriptor);
+
+        result = metaDataTransformer.convertMetaData(entry);
         return result;
     }
 



Mime
View raw message