bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1649679 - in /bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr: ./ groups/
Date Mon, 05 Jan 2015 22:13:36 GMT
Author: mbenson
Date: Mon Jan  5 22:13:35 2015
New Revision: 1649679

URL: http://svn.apache.org/r1649679
Log:
cleanup

Modified:
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AppendValidationToBuilder.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AppendValidationToList.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BaseAppendValidation.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/CascadingPropertyValidator.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Groups.java

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java?rev=1649679&r1=1649678&r2=1649679&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java Mon Jan  5 22:13:35 2015
@@ -176,10 +176,11 @@ public final class AnnotationProcessor {
             return false;
         }
         AccessStrategy[] strategies = prop.getFeature(Features.Property.REF_CASCADE);
+        if (ArrayUtils.contains(strategies, access)) {
+            return false;
+        }
         if (strategies == null) {
             strategies = new AccessStrategy[] { access };
-        } else if (ArrayUtils.contains(strategies, access)) {
-            return false;
         } else {
             strategies = ArrayUtils.add(strategies, access);
         }

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java?rev=1649679&r1=1649678&r2=1649679&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java Mon Jan  5 22:13:35 2015
@@ -142,12 +142,7 @@ public class ApacheFactoryContext implem
      * {@inheritDoc}
      */
     public Validator getValidator() {
-        ClassValidator validator = new ClassValidator(this);
-        if (Boolean.parseBoolean(factory.getProperties().get(
-            ApacheValidatorConfiguration.Properties.TREAT_MAPS_LIKE_BEANS))) {
-            validator.setTreatMapsLikeBeans(true);
-        }
-        return validator;
+        return new ClassValidator(this);
     }
 
     /**
@@ -172,6 +167,11 @@ public class ApacheFactoryContext implem
         return parameterNameProvider == null ? factory.getParameterNameProvider() : parameterNameProvider;
     }
 
+    boolean isTreatMapsLikeBeans() {
+        return Boolean.parseBoolean(factory.getProperties().get(
+            ApacheValidatorConfiguration.Properties.TREAT_MAPS_LIKE_BEANS));
+    }
+
     /**
      * Create MetaBeanManager that uses factories:
      * <ol>

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java?rev=1649679&r1=1649678&r2=1649679&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java Mon Jan  5 22:13:35 2015
@@ -27,8 +27,7 @@ import javax.validation.spi.Configuratio
  * Description: Uniquely identify Apache BVal in the Bean Validation bootstrap
  * strategy. Also contains Apache BVal specific configurations<br/>
  */
-public interface ApacheValidatorConfiguration
-      extends Configuration<ApacheValidatorConfiguration> {
+public interface ApacheValidatorConfiguration extends Configuration<ApacheValidatorConfiguration> {
 
     /**
      * Proprietary property keys for {@link ConfigurationImpl}  
@@ -62,7 +61,11 @@ public interface ApacheValidatorConfigur
         String ENABLE_METABEANS_XML = "apache.bval.enable-metabeans-xml";
 
         /**
-         * BeanValidator.treatMapsLikeBeans.
+         * - true (validate maps like beans, so that
+         *     you can use Maps to validate dynamic classes or
+         *     beans for which you have the MetaBean but no instances)
+         * - false (default), validate maps like collections
+         *     (validating the values only)
          * default: false
          */
         String TREAT_MAPS_LIKE_BEANS = "apache.bval.treat-maps-like-beans";

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java?rev=1649679&r1=1649678&r2=1649679&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java Mon Jan  5 22:13:35 2015
@@ -80,7 +80,6 @@ public class ApacheValidatorFactory impl
     private final ConcurrentMap<Class<?>, List<MetaConstraint<?, ? extends Annotation>>> constraintMap;
 
     private final Collection<Closeable> toClose = new ArrayList<Closeable>();
-    private volatile boolean init;
 
     /**
      * Convenience method to retrieve a default global ApacheValidatorFactory
@@ -272,7 +271,9 @@ public class ApacheValidatorFactory impl
      */
     public <T> T unwrap(final Class<T> type) {
         if (type.isInstance(this)) {
-            return (T) this;
+            @SuppressWarnings("unchecked")
+            final T result = (T) this;
+            return result;
         }
 
         // FIXME 2011-03-27 jw:
@@ -285,7 +286,7 @@ public class ApacheValidatorFactory impl
             return newInstance(type);
         }
         try {
-            Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
+            final Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
             if (type.isAssignableFrom(cls)) {
                 @SuppressWarnings("unchecked")
                 T result = (T) newInstance(cls);

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AppendValidationToBuilder.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AppendValidationToBuilder.java?rev=1649679&r1=1649678&r2=1649679&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AppendValidationToBuilder.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AppendValidationToBuilder.java Mon Jan  5 22:13:35 2015
@@ -43,23 +43,23 @@ public class AppendValidationToBuilder e
         // JSR-303 2.3:
         // Groups from the main constraint annotation are inherited by the composing annotations.
         // Any groups definition on a composing annotation is ignored.
-        Set<Class<?>> inheritedGroups = builder.getConstraintValidation().getGroups();
+        final Set<Class<?>> inheritedGroups = builder.getConstraintValidation().getGroups();
         validation.setGroups(inheritedGroups);
         
         // JSR-303 2.3 p:
         // Payloads are also inherited
-        Set<Class<? extends Payload>> inheritedPayload = builder.getConstraintValidation().getPayload();
+        final Set<Class<? extends Payload>> inheritedPayload = builder.getConstraintValidation().getPayload();
         validation.setPayload(inheritedPayload);
 
         // Inherited groups and payload values must also be replicated in the 
         // annotation, so it has to be substituted with a new proxy.
-        T originalAnnot = validation.getAnnotation();
-        AnnotationProxyBuilder<T> apb = new AnnotationProxyBuilder<T>(originalAnnot);
+        final T originalAnnot = validation.getAnnotation();
+        final AnnotationProxyBuilder<T> apb = new AnnotationProxyBuilder<T>(originalAnnot);
         apb.putValue(ConstraintAnnotationAttributes.GROUPS.getAttributeName(),
             inheritedGroups.toArray(new Class[inheritedGroups.size()]));
         apb.putValue(ConstraintAnnotationAttributes.PAYLOAD.getAttributeName(),
             inheritedPayload.toArray(new Class[inheritedPayload.size()]));
-        T newAnnot = apb.createAnnotation();
+        final T newAnnot = apb.createAnnotation();
         validation.setAnnotation(newAnnot);
     }
 

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AppendValidationToList.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AppendValidationToList.java?rev=1649679&r1=1649678&r2=1649679&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AppendValidationToList.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AppendValidationToList.java Mon Jan  5 22:13:35 2015
@@ -16,7 +16,6 @@
  */
 package org.apache.bval.jsr;
 
-
 import java.lang.annotation.Annotation;
 import java.util.ArrayList;
 import java.util.List;
@@ -29,12 +28,6 @@ public class AppendValidationToList exte
     private final List<ConstraintValidation<?>> validations = new ArrayList<ConstraintValidation<?>>();
 
     /**
-     * Create a new AppendValidationToList instance.
-     */
-    public AppendValidationToList() {
-    }
-
-    /**
      * {@inheritDoc}
      */
     public <T extends Annotation> void performAppend(ConstraintValidation<T> validation) {

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BaseAppendValidation.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BaseAppendValidation.java?rev=1649679&r1=1649678&r2=1649679&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BaseAppendValidation.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BaseAppendValidation.java Mon Jan  5 22:13:35 2015
@@ -63,7 +63,7 @@ public abstract class BaseAppendValidati
     public <T extends Annotation> void preProcessValidation(final ConstraintValidation<T> validation) {
         // No generic pre-processing
     }
-    
+
     /**
      * Post-process the validation once it postProcessValidationhas been appended.
      * 
@@ -73,8 +73,6 @@ public abstract class BaseAppendValidati
      *            The validation to be appended.
      */
     public <T extends Annotation> void postProcessValidation(final ConstraintValidation<T> validation) {
-        // done lazily to ensure CDI is available
-        // validation.initialize();
     }
-    
+
 }

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java?rev=1649679&r1=1649678&r2=1649679&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java Mon Jan  5 22:13:35 2015
@@ -130,22 +130,20 @@ public class BeanDescriptorImpl extends
                     fieldFound = true;
                 }
             }
-
             if (!methodFound) {
                 final String name = Character.toUpperCase(prop.getName().charAt(0)) + prop.getName().substring(1);
                 Method m = Reflection.getDeclaredMethod(current, "get" + name);
+                if (m == null) {
+                    final Method isAccessor = Reflection.getDeclaredMethod(current, "is" + name);
+                    if (isAccessor != null && boolean.class.equals(isAccessor.getReturnType())) {
+                        m = isAccessor;
+                    }
+                }
                 if (m != null) {
                     processConvertGroup(edesc, m);
                     methodFound = true;
-                } else {
-                    m = Reflection.getDeclaredMethod(current, "is" + name);
-                    if (m != null) {
-                        processConvertGroup(edesc, m);
-                        methodFound = true;
-                    }
                 }
             }
-
             current = current.getSuperclass();
         }
 
@@ -157,7 +155,6 @@ public class BeanDescriptorImpl extends
                         edesc.addGroupConversion(new GroupConversionDescriptorImpl(new Group(convertGroup.from()), new Group(convertGroup.to())));
                     }
                 }
-
                 if (ConvertGroup.class.isInstance(a)) {
                     final ConvertGroup convertGroup = ConvertGroup.class.cast(a);
                     edesc.addGroupConversion(new GroupConversionDescriptorImpl(new Group(convertGroup.from()), new Group(convertGroup.to())));
@@ -165,7 +162,6 @@ public class BeanDescriptorImpl extends
             }
             annotations.clear();
         }
-
         if (!edesc.getGroupConversions().isEmpty() && !edesc.isCascaded()) {
             throw new ConstraintDeclarationException("@Valid is needed for group conversion");
         }
@@ -178,7 +174,6 @@ public class BeanDescriptorImpl extends
                 edesc.addGroupConversion(new GroupConversionDescriptorImpl(new Group(convertGroup.from()), new Group(convertGroup.to())));
             }
         }
-
         final ConvertGroup convertGroup = accessible.getAnnotation(ConvertGroup.class);
         if (convertGroup != null) {
             edesc.addGroupConversion(new GroupConversionDescriptorImpl(new Group(convertGroup.from()), new Group(convertGroup.to())));
@@ -211,9 +206,10 @@ public class BeanDescriptorImpl extends
         if (propertyName == null || propertyName.trim().length() == 0) {
             throw new IllegalArgumentException("propertyName cannot be null or empty");
         }
-        MetaProperty prop = metaBean.getProperty(propertyName);
-        if (prop == null)
+        final MetaProperty prop = metaBean.getProperty(propertyName);
+        if (prop == null) {
             return null;
+        }
         // If no constraints and not cascaded, return null
         if (prop.getValidations().length == 0 && prop.getFeature(Features.Property.REF_CASCADE) == null) {
             return null;
@@ -272,7 +268,10 @@ public class BeanDescriptorImpl extends
     private static Collection<MethodDescriptor> filter(final Set<MethodDescriptor> containedMethods, final MethodType type) {
         final Collection<MethodDescriptor> list = new ArrayList<MethodDescriptor>();
         for (final MethodDescriptor d : containedMethods) {
-            final boolean getter = d.getName().startsWith("get") && d.getParameterDescriptors().isEmpty();
+            final boolean getter =
+                d.getParameterDescriptors().isEmpty()
+                    && (d.getName().startsWith("get") || (d.getName().startsWith("is") && boolean.class.equals(d
+                        .getReturnValueDescriptor().getElementClass())));
 
             switch (type) {
                 case GETTER:
@@ -295,7 +294,6 @@ public class BeanDescriptorImpl extends
         if (descriptor != null && (descriptor.hasConstrainedParameters() || descriptor.hasConstrainedReturnValue())) {
             return descriptor;
         }
-
         return null;
     }
 
@@ -336,16 +334,16 @@ public class BeanDescriptorImpl extends
             buildExecutableDescriptors();
 
             boolean hasAnyContraints;
-            if (!constraintDescriptors.isEmpty()) {
-                hasAnyContraints = true;
-            } else {
+            if (constraintDescriptors.isEmpty()) {
                 hasAnyContraints = false;
                 for (final MetaProperty mprop : metaBean.getProperties()) {
-                    if (getConstraintDescriptors(mprop.getValidations()).size() > 0) {
+                    if (!getConstraintDescriptors(mprop.getValidations()).isEmpty()) {
                         hasAnyContraints = true;
                         break;
                     }
                 }
+            } else {
+                hasAnyContraints = true;
             }
 
             // cache isBeanConstrained
@@ -394,10 +392,10 @@ public class BeanDescriptorImpl extends
 
                     if (!annotationIgnores.isIgnoreAnnotations(cons)) {
                         for (final Annotation anno : cons.getAnnotations()) {
-                            if (!Valid.class.isInstance(anno)) {
-                                processAnnotations(null, consDesc, cons.getDeclaringClass(), anno);
-                            } else {
+                            if (Valid.class.isInstance(anno)) {
                                 consDesc.setCascaded(true);
+                            } else {
+                                processAnnotations(null, consDesc, cons.getDeclaringClass(), anno);
                             }
                         }
                     }
@@ -413,10 +411,10 @@ public class BeanDescriptorImpl extends
                 final MetaConstructor metaConstructor = metaBean.getConstructor(cons);
                 if (metaConstructor != null) {
                     for (final Annotation anno : metaConstructor.getAnnotations()) {
-                        if (!Valid.class.isInstance(anno)) {
-                            processAnnotations(null, consDesc, cons.getDeclaringClass(), anno);
-                        } else {
+                        if (Valid.class.isInstance(anno)) {
                             consDesc.setCascaded(true);
+                        } else {
+                            processAnnotations(null, consDesc, cons.getDeclaringClass(), anno);
                         }
                     }
 
@@ -429,11 +427,11 @@ public class BeanDescriptorImpl extends
                     }
                 }
 
-                if (!consDesc.getGroupConversions().isEmpty() && !consDesc.isCascaded()) {
+                if (consDesc.getGroupConversions().isEmpty() || consDesc.isCascaded()) {
+                    ensureNotNullDescriptors(cons.getDeclaringClass(), consDesc);
+                } else {
                     throw new ConstraintDeclarationException("@Valid is needed to define a group conversion");
                 }
-
-                ensureNotNullDescriptors(cons.getDeclaringClass(), consDesc);
             }
         }
 
@@ -454,7 +452,6 @@ public class BeanDescriptorImpl extends
                     returnValueDescriptor.addGroupConversion(c);
                 }
             }
-
         }
 
         private void processAnnotations(final Method mtd, final InvocableElementDescriptor consDesc, final Class<?> clazz, final Annotation anno) throws InvocationTargetException, IllegalAccessException {
@@ -466,11 +463,11 @@ public class BeanDescriptorImpl extends
                 consDesc.addValidations(list);
 
                 ReturnValueDescriptorImpl returnValueDescriptor = ReturnValueDescriptorImpl.class.cast(consDesc.getReturnValueDescriptor());
-                if (consDesc.getReturnValueDescriptor() != null) {
-                    returnValueDescriptor.getMutableConstraintDescriptors().addAll(list);
-                } else {
+                if (consDesc.getReturnValueDescriptor() == null) {
                     returnValueDescriptor = new ReturnValueDescriptorImpl(metaBean, clazz, list, consDesc.isCascaded());
                     consDesc.setReturnValueDescriptor(returnValueDescriptor);
+                } else {
+                    returnValueDescriptor.getMutableConstraintDescriptors().addAll(list);
                 }
             }
 
@@ -480,10 +477,10 @@ public class BeanDescriptorImpl extends
                 processAnnotation(anno, consDesc, parametersAccess, validations);
                 final List<ConstraintValidation<?>> list = removeFromListValidationAppliesTo(validations.getValidations(), ConstraintTarget.RETURN_VALUE);
                 consDesc.addValidations(list);
-                if (consDesc.getCrossParameterDescriptor() != null) {
-                    CrossParameterDescriptorImpl.class.cast(consDesc.getCrossParameterDescriptor()).getMutableConstraintDescriptors().addAll(list);
-                } else {
+                if (consDesc.getCrossParameterDescriptor() == null) {
                     consDesc.setCrossParameterDescriptor(new CrossParameterDescriptorImpl(metaBean, list));
+                } else {
+                    CrossParameterDescriptorImpl.class.cast(consDesc.getCrossParameterDescriptor()).getMutableConstraintDescriptors().addAll(list);
                 }
             }
         }
@@ -509,7 +506,10 @@ public class BeanDescriptorImpl extends
                     continue;
                 }
 
-                final boolean getter = (method.getName().startsWith("get") || method.getName().startsWith("is")) && method.getParameterTypes().length == 0 && method.getReturnType() != Void.TYPE;
+                final boolean propertyAccessor =
+                    method.getParameterTypes().length == 0
+                        && (method.getName().startsWith("get") && !Void.TYPE.equals(method.getReturnType()) || method
+                            .getName().startsWith("is") && Boolean.TYPE.equals(method.getReturnType()));
 
                 final String key = method.getName() + Arrays.toString(method.getParameterTypes());
                 MethodDescriptorImpl methodDesc = MethodDescriptorImpl.class.cast(methodConstraints.get(key));
@@ -544,12 +544,14 @@ public class BeanDescriptorImpl extends
                             }
                             ensureNoReturnValueAddedInChild(methodDesc.getReturnValueDescriptor(), parentDec, "Return value constraints should be the same for parent and children");
                         }
-                    } else if (!parents.isEmpty()) {
+                    } else if (parents.size() == 1) {
                         final Method parent = parents.iterator().next();
                         final MethodDescriptor parentDesc = factoryContext.getValidator().getConstraintsForClass(parent.getDeclaringClass()).getConstraintsForMethod(parent.getName(), parent.getParameterTypes());
                         ensureNoReturnValueAddedInChild(methodDesc.getReturnValueDescriptor(), parentDesc, "Return value constraints should be at least the same for parent and children");
 
-                        if (parentDesc != null) {
+                        if (parentDesc == null) {
+                            ensureMethodDoesntDefineParameterConstraint(methodDesc);
+                        } else {
                             final Iterator<ParameterDescriptor> parentPd = parentDesc.getParameterDescriptors().iterator();
                             for (final ParameterDescriptor pd : methodDesc.getParameterDescriptors()) {
                                 final ParameterDescriptor next = parentPd.next();
@@ -560,8 +562,6 @@ public class BeanDescriptorImpl extends
                                     throw new ConstraintDeclarationException("child shouldn't get more constraint than parent");
                                 }
                             }
-                        } else {
-                            ensureMethodDoesntDefineParameterConstraint(methodDesc);
                         }
                     }
 
@@ -598,7 +598,7 @@ public class BeanDescriptorImpl extends
                     }
                 }
 
-                if (getter) {
+                if (propertyAccessor) {
                     final MetaProperty prop = metaBean.getProperty(Introspector.decapitalize(method.getName().substring(3)));
                     if (prop != null && prop.getFeature(Features.Property.REF_CASCADE) != null) {
                         methodDesc.setCascaded(true);
@@ -635,7 +635,6 @@ public class BeanDescriptorImpl extends
             if (parentMtdDesc == null) {
                 return;
             }
-
             final ReturnValueDescriptor parentReturnDesc = parentMtdDesc.getReturnValueDescriptor();
             if (parentReturnDesc.isCascaded() && !returnValueDescriptor.isCascaded() || parentReturnDesc.getConstraintDescriptors().size() > returnValueDescriptor.getConstraintDescriptors().size()) {
                 throw new ConstraintDeclarationException(msg);
@@ -666,7 +665,6 @@ public class BeanDescriptorImpl extends
         private void processMethod(final Method method, final MethodDescriptorImpl methodDesc) throws InvocationTargetException, IllegalAccessException {
             final AnnotationIgnores annotationIgnores = factoryContext.getFactory().getAnnotationIgnores();
 
-
             { // reflection
                 if (!annotationIgnores.isIgnoreAnnotations(method)) {
                     // return value validations and/or cross-parameter validation
@@ -684,13 +682,13 @@ public class BeanDescriptorImpl extends
                 int idx = 0;
                 final List<String> names = factoryContext.getParameterNameProvider().getParameterNames(method);
                 for (final Annotation[] paramAnnos : paramsAnnos) {
-                    if (!annotationIgnores.isIgnoreAnnotationOnParameter(method, idx)) {
-                        final ParameterAccess access = new ParameterAccess(method.getParameterTypes()[idx], idx);
-                        processAnnotations(methodDesc, paramAnnos, access, idx, names.get(idx));
-                    } else {
+                    if (annotationIgnores.isIgnoreAnnotationOnParameter(method, idx)) {
                         final ParameterDescriptorImpl parameterDescriptor = new ParameterDescriptorImpl(metaBean, EMPTY_VALIDATION, names.get(idx));
                         parameterDescriptor.setIndex(idx);
                         methodDesc.getParameterDescriptors().add(parameterDescriptor);
+                    } else {
+                        final ParameterAccess access = new ParameterAccess(method.getParameterTypes()[idx], idx);
+                        processAnnotations(methodDesc, paramAnnos, access, idx, names.get(idx));
                     }
                     idx++;
                 }
@@ -722,9 +720,7 @@ public class BeanDescriptorImpl extends
                     final ParameterAccess access = new ParameterAccess(method.getParameterTypes()[idx], idx);
                     processAnnotations(methodDesc, paramAnnos.getAnnotations(), access, idx, names.get(idx));
                 }
-
             }
-
         }
 
         private AppendValidationToList processAnnotations(InvocableElementDescriptor methodDesc, Annotation[] paramAnnos, AccessStrategy access, int idx, String name)
@@ -786,19 +782,19 @@ public class BeanDescriptorImpl extends
                         paramDesc.getMutableConstraintDescriptors().add(validation);
                     }
                 }
-
                 if (cascaded) {
                     paramDesc.setCascaded(true);
                 } // else keep previous config
             }
-            if (paramDesc.isCascaded() && from != null) {
-                for (int i = 0; i < from.length; i++) {
-                    paramDesc.addGroupConversion(new GroupConversionDescriptorImpl(from[i], to[i]));
+            if (from != null) {
+                if (paramDesc.isCascaded()) {
+                    for (int i = 0; i < from.length; i++) {
+                        paramDesc.addGroupConversion(new GroupConversionDescriptorImpl(from[i], to[i]));
+                    }
+                } else {
+                    throw new ConstraintDeclarationException("Group conversion is only relevant for @Valid cases");
                 }
-            } else if (from != null) {
-                throw new ConstraintDeclarationException("Group conversion is only relevant for @Valid cases");
             }
-
             return validations;
         }
 
@@ -823,13 +819,12 @@ public class BeanDescriptorImpl extends
             }
         }
 
-        private <A extends Annotation> void processConstraint(final A annotation, final InvocableElementDescriptor desc,
-                                                              final AccessStrategy access, final AppendValidation validations) throws IllegalAccessException, InvocationTargetException {
-            Constraint vcAnno = annotation.annotationType().getAnnotation(Constraint.class);
-            if (vcAnno != null) {
-                annotationProcessor.processAnnotation(annotation, null, ClassUtils.primitiveToWrapper((Class<?>) access.getJavaType()), access, validations, true);
-            } else {
-                /**
+        private <A extends Annotation> void processConstraint(final A annotation,
+            final InvocableElementDescriptor desc, final AccessStrategy access, final AppendValidation validations)
+            throws IllegalAccessException, InvocationTargetException {
+            final Constraint vcAnno = annotation.annotationType().getAnnotation(Constraint.class);
+            if (vcAnno == null) {
+                /*
                  * Multi-valued constraints
                  */
                 final ConstraintAnnotationAttributes.Worker<? extends Annotation> worker = ConstraintAnnotationAttributes.VALUE.analyze(annotation.annotationType());
@@ -844,6 +839,8 @@ public class BeanDescriptorImpl extends
                         }
                     }
                 }
+            } else {
+                annotationProcessor.processAnnotation(annotation, null, ClassUtils.primitiveToWrapper((Class<?>) access.getJavaType()), access, validations, true);
             }
         }
 
@@ -855,7 +852,6 @@ public class BeanDescriptorImpl extends
                 if (RuntimeException.class.isInstance(ex)) {
                     throw RuntimeException.class.cast(ex);
                 }
-
                 throw new IllegalArgumentException(ex.getMessage(), ex);
             }
         }

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/CascadingPropertyValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/CascadingPropertyValidator.java?rev=1649679&r1=1649678&r2=1649679&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/CascadingPropertyValidator.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/CascadingPropertyValidator.java Mon Jan  5 22:13:35 2015
@@ -47,8 +47,8 @@ public interface CascadingPropertyValida
      * @param groups
      * @return the resulting {@link Set} of {@link ConstraintViolation}s.
      */
-    <T extends Object> java.util.Set<javax.validation.ConstraintViolation<T>> validateProperty(T object,
-        String propertyName, boolean cascade, java.lang.Class<?>... groups);
+    <T extends Object> Set<javax.validation.ConstraintViolation<T>> validateProperty(T object, String propertyName,
+        boolean cascade, Class<?>... groups);
 
     /**
      * Validates all constraints placed on <code>object</code>'s
@@ -63,6 +63,6 @@ public interface CascadingPropertyValida
      * @param groups
      * @return the resulting {@link Set} of {@link ConstraintViolation}s.
      */
-    <T extends Object> java.util.Set<javax.validation.ConstraintViolation<T>> validateValue(
-        java.lang.Class<T> beanType, String propertyName, Object value, boolean cascade, java.lang.Class<?>... groups);
+    <T extends Object> Set<javax.validation.ConstraintViolation<T>> validateValue(Class<T> beanType,
+        String propertyName, Object value, boolean cascade, Class<?>... groups);
 }

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java?rev=1649679&r1=1649678&r2=1649679&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java Mon Jan  5 22:13:35 2015
@@ -63,13 +63,13 @@ import org.apache.bval.model.MetaPropert
 import org.apache.bval.model.Validation;
 import org.apache.bval.util.AccessStrategy;
 import org.apache.bval.util.ValidationHelper;
+import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.ClassUtils;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.reflect.TypeUtils;
-import org.apache.commons.weaver.privilizer.Privileged;
-
-// TODO: centralize treatMapsLikeBeans
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
 
 /**
  * Objects of this class are able to validate bean instances (and the associated object graphs).
@@ -83,6 +83,7 @@ import org.apache.commons.weaver.privili
  * @author Roman Stumm
  * @author Carlos Vara
  */
+@Privilizing(@CallTo(Reflection.class))
 public class ClassValidator implements CascadingPropertyValidator, ExecutableValidator {
     private static final Object VALIDATE_PROPERTY = new Object() {
         public String toString() {
@@ -135,7 +136,6 @@ public class ClassValidator implements C
         checkGroups(groups);
 
         try {
-
             final Class<T> objectClass = (Class<T>) object.getClass();
             final MetaBean objectMetaBean = metaBeanFinder.findForClass(objectClass);
             final GroupValidationContext<T> context = createContext(objectMetaBean, object, objectClass, groups);
@@ -201,11 +201,12 @@ public class ClassValidator implements C
     public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyName, boolean cascade,
         Class<?>... groups) {
 
-        if (object == null)
+        if (object == null) {
             throw new IllegalArgumentException("cannot validate null");
+        }
 
         @SuppressWarnings("unchecked")
-        Set<ConstraintViolation<T>> result =
+        final Set<ConstraintViolation<T>> result =
             validateValueImpl((Class<T>) object.getClass(), object, propertyName, VALIDATE_PROPERTY, cascade, groups);
         return result;
     }
@@ -291,37 +292,43 @@ public class ClassValidator implements C
         // Can't fix this because don't know which classes this method should support.
 
         if (type.isAssignableFrom(getClass())) {
-            return (T) this;
-        } else if (!(type.isInterface() || Modifier.isAbstract(type.getModifiers()))) {
+            @SuppressWarnings("unchecked")
+            final T result = (T) this;
+            return result;
+        }
+        if (!(type.isInterface() || Modifier.isAbstract(type.getModifiers()))) {
             return newInstance(type);
-        } else {
-            try {
-                Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
-                if (type.isAssignableFrom(cls)) {
-                    @SuppressWarnings("unchecked")
-                    final Class<? extends T> implClass = (Class<? extends T>) cls;
-                    return newInstance(implClass);
-                }
-            } catch (ClassNotFoundException e) {
+        }
+        try {
+            final Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
+            if (type.isAssignableFrom(cls)) {
+                @SuppressWarnings("unchecked")
+                final Class<? extends T> implClass = (Class<? extends T>) cls;
+                return newInstance(implClass);
             }
-            throw new ValidationException("Type " + type + " not supported");
+        } catch (ClassNotFoundException e) {
         }
+        throw new ValidationException("Type " + type + " not supported");
     }
 
     public ExecutableValidator forExecutables() {
         return this;
     }
 
-    @Privileged
     private <T> T newInstance(final Class<T> cls) {
+        final Constructor<T> cons = Reflection.getDeclaredConstructor(cls, ApacheFactoryContext.class);
+        if (cons == null) {
+            throw new ValidationException("Cannot instantiate " + cls);
+        }
+        final boolean mustUnset = Reflection.setAccessible(cons, true);
         try {
-            Constructor<T> cons = cls.getConstructor(ApacheFactoryContext.class);
-            if (!cons.isAccessible()) {
-                cons.setAccessible(true);
-            }
             return cons.newInstance(factoryContext);
         } catch (final Exception ex) {
-            throw new ValidationException("Cannot instantiate : " + cls, ex);
+            throw new ValidationException("Cannot instantiate " + cls, ex);
+        } finally {
+            if (mustUnset) {
+                Reflection.setAccessible(cons, false);
+            }
         }
     }
 
@@ -405,13 +412,10 @@ public class ClassValidator implements C
                             break;
                         }
                     }
-
                 }
                 context.setCurrentOwner(initialOwner);
                 context.setCurrentGroup(Group.DEFAULT);
-
             }
-
         }
         // if not the default group, proceed as normal
         else {
@@ -424,23 +428,20 @@ public class ClassValidator implements C
             final Group mappedGroup;
 
             final Object feature = prop.getFeature(JsrFeatures.Property.PropertyDescriptor);
-            if (feature != null) {
-                mappedGroup = PropertyDescriptorImpl.class.cast(feature).mapGroup(group);
-            } else {
+            if (feature == null) {
                 mappedGroup = group;
+            } else {
+                mappedGroup = PropertyDescriptorImpl.class.cast(feature).mapGroup(group);
             }
 
-
-            if (group != mappedGroup) {
+            if (group == mappedGroup) {
+                validateCascadedBean(context, prop, null);
+            } else {
                 final Groups propertyGroup = groupsComputer.computeGroups(new Class<?>[]{ mappedGroup.getGroup() });
                 validateCascadedBean(context, prop, propertyGroup);
-            } else {
-                validateCascadedBean(context, prop, null);
             }
-
             context.setCurrentGroup(group);
         }
-
     }
 
     // TODO: maybe add a GroupMapper to bval-core to ease this kind of thing and void to fork this method from ValidationHelper
@@ -466,7 +467,7 @@ public class ClassValidator implements C
         context.setMetaProperty(null);
         for (final Validation validation : context.getMetaBean().getValidations()) {
             if (ConstraintValidation.class.isInstance(validation)) {
-                final ConstraintValidation constraintValidation = ConstraintValidation.class.cast(validation);
+                final ConstraintValidation<?> constraintValidation = ConstraintValidation.class.cast(validation);
                 if (!constraintValidation.isValidated()) {
                     checkValidationAppliesTo(constraintValidation.getValidationAppliesTo(), ConstraintTarget.PARAMETERS);
                     checkValidationAppliesTo(constraintValidation.getValidationAppliesTo(), ConstraintTarget.RETURN_VALUE);
@@ -484,7 +485,7 @@ public class ClassValidator implements C
      * @param prop    The property to cascade from (in case it is possible).
      */
     private void validateCascadedBean(final GroupValidationContext<?> context, final MetaProperty prop, final Groups groups) {
-        AccessStrategy[] access = prop.getFeature(Features.Property.REF_CASCADE);
+        final AccessStrategy[] access = prop.getFeature(Features.Property.REF_CASCADE);
         if (access != null) { // different accesses to relation
             // save old values from context
             final Object bean = context.getBean();
@@ -497,13 +498,13 @@ public class ClassValidator implements C
                     context.moveDown(prop, each);
                     // validate
                     if (groups == null) {
-                        ValidationHelper.validateContext(context, new JsrValidationCallback(context), treatMapsLikeBeans);
+                        ValidationHelper.validateContext(context, new JsrValidationCallback(context), factoryContext.isTreatMapsLikeBeans());
                     } else {
                         ValidationHelper.validateContext(context, new ValidationHelper.ValidateCallback() {
                             public void validate() {
                                 validateBeanWithGroups(context, groups);
                             }
-                        }, treatMapsLikeBeans);
+                        }, factoryContext.isTreatMapsLikeBeans());
                     }
                     // restore old values in context
                     context.moveUp(bean, mbean);
@@ -539,12 +540,12 @@ public class ClassValidator implements C
 
         try {
             if (!context.getTraversableResolver().isCascadable(context.getBean(), node,
-                context.getRootMetaBean().getBeanClass(), beanPath, access.getElementType()))
+                context.getRootMetaBean().getBeanClass(), beanPath, access.getElementType())) {
                 return false;
+            }
         } catch (RuntimeException e) {
             throw new ValidationException("Error TraversableResolver.isCascadable() for " + context.getBean(), e);
         }
-
         return true;
     }
 
@@ -556,14 +557,13 @@ public class ClassValidator implements C
     private List<Group> expandDefaultGroup(GroupValidationContext<?> context) {
         if (context.getCurrentGroup().isDefault()) {
             // mention if metaBean redefines the default group
-            List<Group> groupSeq = context.getMetaBean().getFeature(JsrFeatures.Bean.GROUP_SEQUENCE);
+            final List<Group> groupSeq = context.getMetaBean().getFeature(JsrFeatures.Bean.GROUP_SEQUENCE);
             if (groupSeq != null) {
                 context.getGroups().assertDefaultGroupSequenceIsExpandable(groupSeq);
             }
             return groupSeq;
-        } else {
-            return null;
         }
+        return null;
     }
 
     /**
@@ -573,29 +573,25 @@ public class ClassValidator implements C
      * @param object
      * @return a {@link RuntimeException} of the appropriate type
      */
-    @SuppressWarnings("finally")
     protected static RuntimeException unrecoverableValidationError(RuntimeException ex, Object object) {
         if (ex instanceof UnknownPropertyException || ex instanceof IncompatiblePropertyValueException) {
             // Convert to IllegalArgumentException
             return new IllegalArgumentException(ex.getMessage(), ex);
-        } else if (ex instanceof ValidationException) {
-            return ex; // do not wrap specific ValidationExceptions (or
-            // instances from subclasses)
+        }
+        if (ex instanceof ValidationException) {
+            return ex; // do not wrap specific ValidationExceptions (or instances from subclasses)
+        }
+        String objectId;
+        if (object == null) {
+            objectId = "<null>";
         } else {
-            String objectId = "";
             try {
-                if (object != null) {
-                    objectId = object.toString();
-                } else {
-                    objectId = "<null>";
-                }
+                objectId = object.toString();
             } catch (Exception e) {
                 objectId = "<unknown>";
-            } finally {
-                return new ValidationException("error during validation of "
-                        + objectId, ex);
             }
         }
+        return new ValidationException("error during validation of " + objectId, ex);
     }
 
     private void validatePropertyInGroup(final GroupValidationContext<?> context) {
@@ -615,17 +611,17 @@ public class ClassValidator implements C
                 }
             };
         }
-        Group currentGroup = context.getCurrentGroup();
-        List<Group> defaultGroups = expandDefaultGroup(context);
-        if (defaultGroups != null) {
+        final List<Group> defaultGroups = expandDefaultGroup(context);
+        if (defaultGroups == null) {
+            helper.run();
+        } else {
+            final Group currentGroup = context.getCurrentGroup();
             for (Group each : defaultGroups) {
                 context.setCurrentGroup(each);
                 helper.run();
                 // continue validation, even if errors already found
             }
             context.setCurrentGroup(currentGroup); // restore
-        } else {
-            helper.run();
         }
     }
 
@@ -656,9 +652,11 @@ public class ClassValidator implements C
                         this.factoryContext.getTraversableResolver(), factoryContext.getParameterNameProvider(), metaBean);
         context.setBean(object, metaBean);
         final Groups computedGroup = groupsComputer.computeGroups(groups);
-        if (computedGroup.getGroups().size() == 1 && Group.DEFAULT.equals(computedGroup.getGroups().iterator().next()) && metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE) != null) {
+        if (Collections.singletonList(Group.DEFAULT).equals(computedGroup.getGroups()) && metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE) != null) {
             final Groups sequence = new Groups();
-            sequence.getGroups().addAll(List.class.cast(metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE)));
+            @SuppressWarnings("unchecked")
+            final List<? extends Group> sequenceGroups = List.class.cast(metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE));
+            sequence.getGroups().addAll(sequenceGroups);
             context.setGroups(sequence);
         } else {
             context.setGroups(computedGroup);
@@ -672,49 +670,10 @@ public class ClassValidator implements C
      * @param metaBean
      * @return {@link BeanDescriptorImpl} instance
      */
-    /*
-    protected BeanDescriptorImpl createBeanDescriptor(MetaBean metaBean) {
-        return new BeanDescriptorImpl(factoryContext, metaBean);
-    }
-    */
     protected BeanDescriptorImpl createBeanDescriptor(MetaBean metaBean) {
         return new BeanDescriptorImpl(factoryContext, metaBean);
     }
 
-    private boolean treatMapsLikeBeans = false;
-
-    /**
-     * Behavior configuration -
-     * <p/>
-     * <pre>
-     * @return treatMapsLikeBeans - true (validate maps like beans, so that
-     *                              you can use Maps to validate dynamic classes or
-     *                              beans for which you have the MetaBean but no instances)
-     *                            - false (default), validate maps like collections
-     *                              (validating the values only)
-     * </pre>
-     * <p/>
-     * (is still configuration to better in BeanValidationContext?)
-     */
-    public boolean isTreatMapsLikeBeans() {
-        return treatMapsLikeBeans;
-    }
-
-    /**
-     * Set whether maps are to be treated like beans.
-     * 
-     * <pre>
-     * @param treatMapsLikeBeans - true (validate maps like beans, so that
-     *                             you can use Maps to validate dynamic classes or
-     *                             beans for which you have the MetaBean but no instances)
-     *                           - false (default), validate maps like collections
-     *                             (validating the values only)
-     * </pre>
-     */
-    public void setTreatMapsLikeBeans(boolean treatMapsLikeBeans) {
-        this.treatMapsLikeBeans = treatMapsLikeBeans;
-    }
-
     /**
      * Checks that beanType is valid according to spec Section 4.1.1 i. Throws an {@link IllegalArgumentException} if it
      * is not.
@@ -735,7 +694,7 @@ public class ClassValidator implements C
      * @param propertyName Property name to check.
      */
     private void checkPropertyName(String propertyName) {
-        if (propertyName == null || propertyName.trim().length() == 0) {
+        if (propertyName == null || propertyName.trim().isEmpty()) {
             throw new IllegalArgumentException("Property path cannot be null or empty.");
         }
     }
@@ -770,12 +729,12 @@ public class ClassValidator implements C
 
         // sanity checks
         if (!constructorDescriptor.isValidated(constructor)) {
-            if (parameterValues.length > 0) {
-                checkValidationAppliesTo(Collections.singleton(constructorDescriptor.getCrossParameterDescriptor()), ConstraintTarget.IMPLICIT);
-                checkValidationAppliesTo(constructorDescriptor.getParameterDescriptors(), ConstraintTarget.IMPLICIT);
-            } else {
+            if (parameterValues.length == 0) {
                 checkValidationAppliesTo(Collections.singleton(constructorDescriptor.getCrossParameterDescriptor()), ConstraintTarget.PARAMETERS);
                 checkValidationAppliesTo(constructorDescriptor.getParameterDescriptors(), ConstraintTarget.PARAMETERS);
+            } else {
+                checkValidationAppliesTo(Collections.singleton(constructorDescriptor.getCrossParameterDescriptor()), ConstraintTarget.IMPLICIT);
+                checkValidationAppliesTo(constructorDescriptor.getParameterDescriptors(), ConstraintTarget.IMPLICIT);
             }
             constructorDescriptor.setValidated(constructor);
         }
@@ -788,17 +747,24 @@ public class ClassValidator implements C
                                                                          final Class<?>[] gps, final NodeImpl rootNode, final Object rootBean) {
         final Set<ConstraintViolation<T>> violations = new HashSet<ConstraintViolation<T>>();
 
+        @SuppressWarnings("unchecked")
+        final GroupValidationContext<ConstraintValidationListener<?>> parametersContext =
+            createInvocableContext(constructorDescriptor.getMetaBean(), rootBean,
+                Class.class.cast(invocable.getDeclaringClass()), gps);
 
-        final GroupValidationContext<ConstraintValidationListener<?>> parametersContext = createInvocableContext(constructorDescriptor.getMetaBean(), rootBean, Class.class.cast(invocable.getDeclaringClass()), gps);
-        final GroupValidationContext<Object> crossParameterContext = createContext(constructorDescriptor.getMetaBean(), rootBean, Class.class.cast(invocable.getDeclaringClass()), gps);
-        if (rootBean != null) { // could be more sexy but that's ok for now
-            final Method m = Method.class.cast(invocable);
-            parametersContext.setMethod(m);
-            crossParameterContext.setMethod(m);
-        } else {
+        @SuppressWarnings("unchecked")
+        final GroupValidationContext<Object> crossParameterContext =
+            createContext(constructorDescriptor.getMetaBean(), rootBean,
+                Class.class.cast(invocable.getDeclaringClass()), gps);
+
+        if (rootBean == null) {
             final Constructor<?> m = Constructor.class.cast(invocable);
             parametersContext.setConstructor(m);
             crossParameterContext.setConstructor(m);
+        } else { // could be more sexy but that's ok for now
+            final Method m = Method.class.cast(invocable);
+            parametersContext.setMethod(m);
+            crossParameterContext.setMethod(m);
         }
 
         final Groups groups = parametersContext.getGroups();
@@ -847,7 +813,7 @@ public class ClassValidator implements C
                     parametersContext.moveDown(new NodeImpl.ParameterNodeImpl(paramDesc.getName(), i));
                     initMetaBean(parametersContext, factoryContext.getMetaBeanFinder(), parameterValues[i].getClass());
                     parametersContext.setCurrentGroup(paramDesc.mapGroup(current));
-                    ValidationHelper.validateContext(parametersContext, new JsrValidationCallback(parametersContext), isTreatMapsLikeBeans());
+                    ValidationHelper.validateContext(parametersContext, new JsrValidationCallback(parametersContext), factoryContext.isTreatMapsLikeBeans());
                     parametersContext.moveUp(null, null);
                 }
             }
@@ -886,7 +852,7 @@ public class ClassValidator implements C
                         parametersContext.moveDown(new NodeImpl.ParameterNodeImpl(paramDesc.getName(), i));
                         initMetaBean(parametersContext, factoryContext.getMetaBeanFinder(), parameterValues[i].getClass());
                         parametersContext.setCurrentGroup(paramDesc.mapGroup(current));
-                        ValidationHelper.validateContext(parametersContext, new JsrValidationCallback(parametersContext), isTreatMapsLikeBeans());
+                        ValidationHelper.validateContext(parametersContext, new JsrValidationCallback(parametersContext), factoryContext.isTreatMapsLikeBeans());
                         parametersContext.moveUp(null, null);
                     }
                 }
@@ -898,12 +864,12 @@ public class ClassValidator implements C
 
                 for (final Group current : groups.getGroups()) {
                     parametersContext.setCurrentGroup(constructorDescriptor.mapGroup(current));
-                    ValidationHelper.validateContext(parametersContext, new JsrValidationCallback(parametersContext), isTreatMapsLikeBeans());
+                    ValidationHelper.validateContext(parametersContext, new JsrValidationCallback(parametersContext), factoryContext.isTreatMapsLikeBeans());
                 }
                 for (final List<Group> eachSeq : groups.getSequences()) {
                     for (final Group current : eachSeq) {
                         parametersContext.setCurrentGroup(constructorDescriptor.mapGroup(current));
-                        ValidationHelper.validateContext(parametersContext, new JsrValidationCallback(parametersContext), isTreatMapsLikeBeans());
+                        ValidationHelper.validateContext(parametersContext, new JsrValidationCallback(parametersContext), factoryContext.isTreatMapsLikeBeans());
                         if (!parametersContext.getListener().isEmpty()) {
                             break;
                         }
@@ -915,12 +881,12 @@ public class ClassValidator implements C
 
                 for (final Group current : groups.getGroups()) {
                     crossParameterContext.setCurrentGroup(constructorDescriptor.mapGroup(current));
-                    ValidationHelper.validateContext(crossParameterContext, new JsrValidationCallback(crossParameterContext), isTreatMapsLikeBeans());
+                    ValidationHelper.validateContext(crossParameterContext, new JsrValidationCallback(crossParameterContext), factoryContext.isTreatMapsLikeBeans());
                 }
                 for (final List<Group> eachSeq : groups.getSequences()) {
                     for (final Group current : eachSeq) {
                         crossParameterContext.setCurrentGroup(constructorDescriptor.mapGroup(current));
-                        ValidationHelper.validateContext(crossParameterContext, new JsrValidationCallback(crossParameterContext), isTreatMapsLikeBeans());
+                        ValidationHelper.validateContext(crossParameterContext, new JsrValidationCallback(crossParameterContext), factoryContext.isTreatMapsLikeBeans());
                         if (!crossParameterContext.getListener().isEmpty()) {
                             break;
                         }
@@ -929,8 +895,12 @@ public class ClassValidator implements C
             }
         }
 
-        violations.addAll(Set.class.cast(parametersContext.getListener().getConstraintViolations()));
-        violations.addAll(Set.class.cast(crossParameterContext.getListener().getConstraintViolations()));
+        @SuppressWarnings("unchecked")
+        final Set<ConstraintViolation<T>> parameterViolations = Set.class.cast(parametersContext.getListener().getConstraintViolations());
+        violations.addAll(parameterViolations);
+        @SuppressWarnings("unchecked")
+        final Set<ConstraintViolation<T>> crossParameterViolations = Set.class.cast(crossParameterContext.getListener().getConstraintViolations());
+        violations.addAll(crossParameterViolations);
 
         return violations;
     }
@@ -976,7 +946,10 @@ public class ClassValidator implements C
         final ElementDescriptorImpl returnedValueDescriptor = ElementDescriptorImpl.class.cast(methodDescriptor.getReturnValueDescriptor());
         final Set<ConstraintDescriptor<?>> returnedValueConstraints = returnedValueDescriptor.getConstraintDescriptors();
 
-        final GroupValidationContext<T> context = createInvocableContext(methodDescriptor.getMetaBean(), createdObject, Class.class.cast(Proxies.classFor(clazz)), gps);
+        @SuppressWarnings("unchecked")
+        final GroupValidationContext<T> context =
+            createInvocableContext(methodDescriptor.getMetaBean(), createdObject,
+                Class.class.cast(Proxies.classFor(clazz)), gps);
         context.moveDown(rootNode);
         context.moveDown(new NodeImpl.ReturnValueNodeImpl());
         context.setReturnValue(rootBean);
@@ -1002,7 +975,7 @@ public class ClassValidator implements C
                 initMetaBean(context, factoryContext.getMetaBeanFinder(), context.getValidatedValue().getClass());
 
                 context.setCurrentGroup(methodDescriptor.mapGroup(current));
-                ValidationHelper.validateContext(context, new JsrValidationCallback(context), isTreatMapsLikeBeans());
+                ValidationHelper.validateContext(context, new JsrValidationCallback(context), factoryContext.isTreatMapsLikeBeans());
 
                 if (currentViolationNumber < context.getListener().getConstraintViolations().size()) {
                     break;
@@ -1031,7 +1004,7 @@ public class ClassValidator implements C
                     initMetaBean(context, factoryContext.getMetaBeanFinder(), context.getValidatedValue().getClass());
 
                     context.setCurrentGroup(methodDescriptor.mapGroup(current));
-                    ValidationHelper.validateContext(context, new JsrValidationCallback(context), isTreatMapsLikeBeans());
+                    ValidationHelper.validateContext(context, new JsrValidationCallback(context), factoryContext.isTreatMapsLikeBeans());
 
                     if (currentViolationNumber < context.getListener().getConstraintViolations().size()) {
                         break;
@@ -1070,7 +1043,8 @@ public class ClassValidator implements C
             methodDescriptor.setValidated(method);
         }
 
-        return validateInvocationParameters(method, parameterValues, methodDescriptor, groups, new NodeImpl.MethodNodeImpl(method.getName(), Arrays.asList(method.getParameterTypes())), object);
+        return validateInvocationParameters(method, parameterValues, methodDescriptor, groups,
+            new NodeImpl.MethodNodeImpl(method.getName(), Arrays.asList(method.getParameterTypes())), object);
     }
 
     private static void notNull(final String entity, final Object shouldntBeNull) {
@@ -1087,7 +1061,7 @@ public class ClassValidator implements C
         notNull("method", method);
         notNull("groups", groups);
 
-        MethodDescriptorImpl methodDescriptor = findMethodDescriptor(object, method);
+        final MethodDescriptorImpl methodDescriptor = findMethodDescriptor(object, method);
         if (methodDescriptor == null) {
             throw new ValidationException("Method " + method + " doesn't belong to class " + object.getClass());
         }
@@ -1096,11 +1070,15 @@ public class ClassValidator implements C
             checkValidationAppliesTo(methodDescriptor.getReturnValueDescriptor().getConstraintDescriptors(), ConstraintTarget.RETURN_VALUE);
         }
 
-        return Set.class.cast(validaReturnedValue(new NodeImpl.MethodNodeImpl(method.getName(), Arrays.asList(method.getParameterTypes())), returnValue, object.getClass(), methodDescriptor, groups, object));
+        @SuppressWarnings("unchecked")
+        final Set<ConstraintViolation<T>> result =
+            Set.class.cast(validaReturnedValue(
+                new NodeImpl.MethodNodeImpl(method.getName(), Arrays.asList(method.getParameterTypes())), returnValue,
+                object.getClass(), methodDescriptor, groups, object));
+        return result;
     }
 
     private <T> MethodDescriptorImpl findMethodDescriptor(final T object, final Method method) {
-        // return MethodDescriptorImpl.class.cast(getConstraintsForClass(Proxies.classFor(object.getClass())).getConstraintsForMethod(method.getName(), method.getParameterTypes()));
         return MethodDescriptorImpl.class.cast(
             BeanDescriptorImpl.class.cast(getConstraintsForClass(Proxies.classFor(method.getDeclaringClass())))
                 .getInternalConstraintsForMethod(method.getName(), method.getParameterTypes()));
@@ -1122,68 +1100,6 @@ public class ClassValidator implements C
         }
     }
 
-    private <T> Group validateElementInContext(final GroupValidationContext<T> context,
-                                              final ElementDescriptor eltDescriptor) {
-
-        final ElementDescriptorImpl impl = ElementDescriptorImpl.class.cast(eltDescriptor);
-
-        final Groups groups = context.getGroups();
-
-        Group breakOnGroup = null;
-
-        for (final ConstraintDescriptor<?> consDesc : eltDescriptor.getConstraintDescriptors()) {
-            final ConstraintValidation<?> validation = (ConstraintValidation<?>) consDesc;
-
-            // 1. process groups
-            for (final Group current : groups.getGroups()) {
-                context.setCurrentGroup(current);
-                validation.validateGroupContext(context);
-            }
-            // 2. process sequences
-            for (final List<Group> eachSeq : groups.getSequences()) {
-                for (final Group current : eachSeq) {
-                    context.setCurrentGroup(current);
-                    validation.validateGroupContext(context);
-                    /**
-                     * if one of the group process in the sequence leads to one
-                     * or more validation failure, the groups following in the
-                     * sequence must not be processed
-                     */
-                    if (!context.getListener().isEmpty()) {
-                        breakOnGroup = current;
-                        break;
-                    }
-                }
-            }
-        }
-        if (impl.isCascaded() && context.getValidatedValue() != null) {
-            initMetaBean(context, factoryContext.getMetaBeanFinder(), context.getValidatedValue().getClass());
-
-            // 1. process groups
-            for (final Group current : groups.getGroups()) {
-                context.setCurrentGroup(impl.mapGroup(current));
-                ValidationHelper.validateContext(context, new JsrValidationCallback(context), isTreatMapsLikeBeans());
-            }
-            // 2. process sequences
-            for (final List<Group> eachSeq : groups.getSequences()) {
-                for (final Group current : eachSeq) {
-                    context.setCurrentGroup(impl.mapGroup(current));
-                    ValidationHelper.validateContext(context, new JsrValidationCallback(context), isTreatMapsLikeBeans());
-                    /**
-                     * if one of the group process in the sequence leads to one
-                     * or more validation failure, the groups following in the
-                     * sequence must not be processed
-                     */
-                    if (!context.getListener().isEmpty()) {
-                        breakOnGroup = current;
-                        break;
-                    }
-                }
-            }
-        }
-        return breakOnGroup;
-    }
-
     /**
      * Dispatches a call from {@link #validate()} to {@link ClassValidator#validateBeanNet(GroupValidationContext)} with
      * the current context set.

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Groups.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Groups.java?rev=1649679&r1=1649678&r2=1649679&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Groups.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Groups.java Mon Jan  5 22:13:35 2015
@@ -31,10 +31,10 @@ import java.util.List;
  */
 public class Groups {
     /** The list of single groups. */
-    protected List<Group> groups = new LinkedList<Group>();
+    final List<Group> groups = new LinkedList<Group>();
 
     /** The list of sequences. */
-    protected List<List<Group>> sequences = new LinkedList<List<Group>>();
+    final List<List<Group>> sequences = new LinkedList<List<Group>>();
 
     /**
      * Get the Groups.



Mime
View raw message