incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romanst...@apache.org
Subject svn commit: r1043968 - in /incubator/bval/trunk: bval-core/src/main/java/org/apache/bval/ bval-jsr303/src/main/java/org/apache/bval/jsr303/ bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/
Date Thu, 09 Dec 2010 14:02:32 GMT
Author: romanstumm
Date: Thu Dec  9 14:02:32 2010
New Revision: 1043968

URL: http://svn.apache.org/viewvc?rev=1043968&view=rev
Log:
BVAL-83 Support groups on @Valid in method/return validation:
Validate annotation + groups
no behavior during validation implemented yet

Modified:
    incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/Validate.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303Features.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java

Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/Validate.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/Validate.java?rev=1043968&r1=1043967&r2=1043968&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/Validate.java (original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/Validate.java Thu Dec  9
14:02:32 2010
@@ -16,18 +16,26 @@
  */
 package org.apache.bval;
 
-import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
 /**
  * Description: Annotate an element (parameter) to be validated.
  * <br>
  */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.PARAMETER, ElementType.METHOD})
+@Target({METHOD, FIELD, CONSTRUCTOR, PARAMETER})
+@Retention(RUNTIME)
 public @interface Validate {
-    /** (optional) the MetaBean.id to use */
+    /**
+     * (optional) the MetaBean.id to use
+     */
     String value() default "";
+
+    /**
+     * to Support groups on @Valid(ate) in method/return validation
+     */
+    Class<?>[] groups() default {};
 }

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java?rev=1043968&r1=1043967&r2=1043968&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
Thu Dec  9 14:02:32 2010
@@ -18,15 +18,6 @@
  */
 package org.apache.bval.jsr303;
 
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import javax.validation.ConstraintViolation;
-import javax.validation.ValidationException;
-import javax.validation.Validator;
-import javax.validation.groups.Default;
-import javax.validation.metadata.BeanDescriptor;
 import org.apache.bval.MetaBeanFinder;
 import org.apache.bval.jsr303.groups.Group;
 import org.apache.bval.jsr303.groups.Groups;
@@ -42,6 +33,16 @@ import org.apache.bval.util.AccessStrate
 import org.apache.bval.util.ValidationHelper;
 import org.apache.commons.lang.ClassUtils;
 
+import javax.validation.ConstraintViolation;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.groups.Default;
+import javax.validation.metadata.BeanDescriptor;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
 // TODO: centralize treatMapsLikeBeans
 
 /**
@@ -514,6 +515,8 @@ public class ClassValidator implements V
             // save old values from context
             final Object bean = context.getBean();
             final MetaBean mbean = context.getMetaBean();
+            // TODO implement Validation.groups support on related bean
+//            Class[] groups = prop.getFeature(Jsr303Features.Property.REF_GROUPS);
             for (AccessStrategy each : access) {
                 if (isCascadable(context, prop, each)) {
                     // modify context state for relationship-target bean

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303Features.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303Features.java?rev=1043968&r1=1043967&r2=1043968&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303Features.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303Features.java
Thu Dec  9 14:02:32 2010
@@ -34,6 +34,10 @@ public interface Jsr303Features {
     interface Property extends Features.Property {
         /** INFO: cached PropertyDescriptorImpl of the property */
         String PropertyDescriptor = "PropertyDescriptor";
+        /**
+         * INFO: Class[] with the groups to validate a REF_CASCADE
+         */
+        String REF_GROUPS = "refGroups";
     }
 
     /**

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java?rev=1043968&r1=1043967&r2=1043968&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
Thu Dec  9 14:02:32 2010
@@ -20,6 +20,7 @@ package org.apache.bval.jsr303;
 
 
 import org.apache.bval.MetaBeanFactory;
+import org.apache.bval.Validate;
 import org.apache.bval.jsr303.groups.Group;
 import org.apache.bval.jsr303.util.ClassHelper;
 import org.apache.bval.jsr303.util.ConstraintDefinitionValidator;
@@ -289,6 +290,8 @@ public class Jsr303MetaBeanFactory imple
           throws IllegalAccessException, InvocationTargetException {
         if (annotation instanceof Valid) {
             return processValid(prop, access);
+        } else if (annotation instanceof Validate) {
+            return processValid(prop, access, ((Validate)annotation).groups());
         } else {
             /**
              * An annotation is considered a constraint definition if its retention
@@ -350,9 +353,10 @@ public class Jsr303MetaBeanFactory imple
         return validatorClasses;
     }
 
-    private boolean processValid(MetaProperty prop, AccessStrategy access) {
+    private boolean processValid(MetaProperty prop, AccessStrategy access, Class<?>...
groups) {
         if (prop != null/* && prop.getMetaBean() == null*/) {
             AccessStrategy[] strategies = prop.getFeature(Features.Property.REF_CASCADE);
+            prop.putFeature(Jsr303Features.Property.REF_GROUPS, groups);
             if (strategies == null) {
                 strategies = new AccessStrategy[]{access};
                 prop.putFeature(Features.Property.REF_CASCADE, strategies);

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java?rev=1043968&r1=1043967&r2=1043968&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
Thu Dec  9 14:02:32 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.bval.jsr303.extensions;
 
+import org.apache.bval.Validate;
 import org.apache.bval.jsr303.ApacheFactoryContext;
 import org.apache.bval.jsr303.AppendValidation;
 import org.apache.bval.jsr303.Jsr303MetaBeanFactory;
@@ -107,7 +108,7 @@ public class MethodValidatorMetaBeanFact
                 AppendValidationToList validations = new AppendValidationToList();
                 ReturnAccess returnAccess = new ReturnAccess(method.getReturnType());
                 for (Annotation anno : method.getAnnotations()) {
-                    if (anno instanceof Valid) {
+                    if (anno instanceof Valid || anno instanceof Validate) {
                         methodDesc.setCascaded(true);
                     } else {
                         processAnnotation(anno, methodDesc, returnAccess, validations);
@@ -132,7 +133,7 @@ public class MethodValidatorMetaBeanFact
         AppendValidationToList validations = new AppendValidationToList();
         boolean cascaded = false;
         for (Annotation anno : paramAnnos) {
-            if (anno instanceof Valid) {
+            if (anno instanceof Valid || anno instanceof Validate) {
                 cascaded = true;
             } else {
                 processAnnotation(anno, methodDesc, access, validations);
@@ -149,7 +150,7 @@ public class MethodValidatorMetaBeanFact
     private <A extends Annotation> void processAnnotation(A annotation, ProcedureDescriptor
desc,
         AccessStrategy access, AppendValidation validations) throws InvocationTargetException,
IllegalAccessException {
 
-        if (annotation instanceof Valid) {
+        if (annotation instanceof Valid || annotation instanceof Validate) {
             desc.setCascaded(true);
         } else {
             Constraint vcAnno = annotation.annotationType().getAnnotation(Constraint.class);



Mime
View raw message