bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r997090 - in /incubator/bval/trunk/bval-jsr303/src: main/java/org/apache/bval/jsr303/ main/java/org/apache/bval/jsr303/extensions/ test/java/org/apache/bval/jsr303/ test/java/org/apache/bval/jsr303/util/
Date Tue, 14 Sep 2010 20:53:24 GMT
Author: mbenson
Date: Tue Sep 14 20:53:24 2010
New Revision: 997090

URL: http://svn.apache.org/viewvc?rev=997090&view=rev
Log:
merge jsr303 metadata implementation changes primarily wrt enforcement of immutability

Modified:
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.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/ConstraintFinderImpl.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
    incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java
    incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java
    incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/TestUtils.java

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java?rev=997090&r1=997089&r2=997090&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
Tue Sep 14 20:53:24 2010
@@ -18,14 +18,14 @@
  */
 package org.apache.bval.jsr303;
 
-
 import org.apache.bval.model.Features;
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.model.MetaProperty;
-import org.apache.bval.model.Validation;
 
 import javax.validation.metadata.BeanDescriptor;
 import javax.validation.metadata.PropertyDescriptor;
+
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -34,81 +34,88 @@ import java.util.Set;
  */
 public class BeanDescriptorImpl extends ElementDescriptorImpl implements BeanDescriptor {
     /**
-     * The {@link ApacheFactoryContext} (not) used by this {@link BeanDescriptorImpl} 
+     * The {@link ApacheFactoryContext} (not) used by this
+     * {@link BeanDescriptorImpl}
      */
     protected final ApacheFactoryContext factoryContext;
 
     /**
      * Create a new BeanDescriptorImpl instance.
+     * 
      * @param factoryContext
      * @param metaBean
-     * @param validations
      */
-    protected BeanDescriptorImpl(ApacheFactoryContext factoryContext, MetaBean metaBean,
-                                 Validation[] validations) {
-        super(metaBean, metaBean.getBeanClass(), validations);
+    protected BeanDescriptorImpl(ApacheFactoryContext factoryContext, MetaBean metaBean)
{
+        super(metaBean, metaBean.getBeanClass(), metaBean.getValidations());
         this.factoryContext = factoryContext;
     }
 
     /**
      * Returns true if the bean involves validation:
-     * - a constraint is hosted on the bean itself
-     * - a constraint is hosted on one of the bean properties
-     * - or a bean property is marked for cascade (@Valid)
-     *
-     * @return true if the bean nvolves validation
+     * <ul>
+     * <li>a constraint is hosted on the bean itself</li>
+     * <li>a constraint is hosted on one of the bean properties, OR</li>
+     * <li>a bean property is marked for cascade (<code>@Valid</code>)</li>
+     * </ul>
+     * 
+     * @return true if the bean involves validation
      */
     public boolean isBeanConstrained() {
-        if (hasAnyConstraints()) return true;
+        if (hasAnyConstraints())
+            return true;
         for (MetaProperty mprop : metaBean.getProperties()) {
-            if (mprop.getMetaBean() != null ||
-                  mprop.getFeature(Features.Property.REF_CASCADE) != null) return true;
+            if (mprop.getMetaBean() != null || mprop.getFeature(Features.Property.REF_CASCADE)
!= null)
+                return true;
         }
         return false;
     }
 
     private boolean hasAnyConstraints() {
-        if (hasConstraints()) return true;
-        if (metaBean.getValidations().length > 0) return true;
+        if (hasConstraints())
+            return true;
         for (MetaProperty mprop : metaBean.getProperties()) {
-            if (mprop.getValidations().length > 0) return true;
+            if (getConstraintDescriptors(mprop.getValidations()).size() > 0)
+                return true;
         }
         return false;
     }
 
     /**
+<<<<<<< .working
      * Return the property level constraints for a given propertyName
      * or null if either the property does not exist or has no constraint
      * The returned object (and associated objects including ConstraintDescriptors)
      * are immutable.
      *
      * @param propertyName property evaludated
+=======
+     * Return the property level constraints for a given propertyName or null if
+     * either the property does not exist or has no constraint The returned
+     * object (and associated objects including ConstraintDescriptors) are
+     * immutable.
+     * 
+     * @param propertyName
+     *            property evaluated
+>>>>>>> .merge-right.r997084
      */
     public PropertyDescriptor getConstraintsForProperty(String propertyName) {
         if (propertyName == null || propertyName.trim().length() == 0) {
             throw new IllegalArgumentException("propertyName cannot be null or empty");
         }
         MetaProperty prop = metaBean.getProperty(propertyName);
-        if (prop == null) return null;
+        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 ) {
+        if (prop.getValidations().length == 0 && prop.getFeature(Features.Property.REF_CASCADE)
== null) {
             return null;
         }
         return getPropertyDescriptor(prop);
     }
 
     private PropertyDescriptor getPropertyDescriptor(MetaProperty prop) {
-        PropertyDescriptorImpl edesc =
-                prop.getFeature(Jsr303Features.Property.PropertyDescriptor);
+        PropertyDescriptorImpl edesc = prop.getFeature(Jsr303Features.Property.PropertyDescriptor);
         if (edesc == null) {
-            prop.getFeature(Features.Property.REF_BEAN_TYPE, prop.getTypeClass());
-            edesc = new PropertyDescriptorImpl(
-                      metaBean,
-                      prop.getName(),
-                      prop.getValidations());
-            edesc.setCascaded((prop.getMetaBean() != null ||
-                  prop.getFeature(Features.Property.REF_CASCADE) != null));
-            edesc.setPropertyPath(prop.getName());
+            edesc = new PropertyDescriptorImpl(prop);
             prop.putFeature(Jsr303Features.Property.PropertyDescriptor, edesc);
         }
         return edesc;
@@ -116,17 +123,18 @@ public class BeanDescriptorImpl extends 
 
     /**
      * {@inheritDoc}
+     * 
      * @return the property descriptors having at least a constraint defined
      */
     public Set<PropertyDescriptor> getConstrainedProperties() {
         Set<PropertyDescriptor> validatedProperties = new HashSet<PropertyDescriptor>();
         for (MetaProperty prop : metaBean.getProperties()) {
-            if (prop.getValidations().length > 0 || (prop.getMetaBean() != null ||
-                  prop.getFeature(Features.Property.REF_CASCADE) != null)) {
+            if (prop.getValidations().length > 0
+                || (prop.getMetaBean() != null || prop.getFeature(Features.Property.REF_CASCADE)
!= null)) {
                 validatedProperties.add(getPropertyDescriptor(prop));
             }
         }
-        return validatedProperties;
+        return Collections.unmodifiableSet(validatedProperties);
     }
 
     /**

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=997090&r1=997089&r2=997090&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
Tue Sep 14 20:53:24 2010
@@ -681,8 +681,7 @@ public class ClassValidator implements V
      * @return {@link BeanDescriptorImpl} instance
      */
     protected BeanDescriptorImpl createBeanDescriptor(MetaBean metaBean) {
-        return new BeanDescriptorImpl(factoryContext, metaBean, metaBean
-            .getValidations());
+        return new BeanDescriptorImpl(factoryContext, metaBean);
     }
 
     private boolean treatMapsLikeBeans = false;

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintFinderImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintFinderImpl.java?rev=997090&r1=997089&r2=997090&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintFinderImpl.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintFinderImpl.java
Tue Sep 14 20:53:24 2010
@@ -18,7 +18,6 @@
  */
 package org.apache.bval.jsr303;
 
-
 import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.ElementDescriptor;
 import javax.validation.metadata.Scope;
@@ -31,6 +30,7 @@ import org.apache.bval.model.MetaBean;
 
 import java.lang.annotation.ElementType;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -46,6 +46,7 @@ final class ConstraintFinderImpl impleme
 
     /**
      * Create a new ConstraintFinderImpl instance.
+     * 
      * @param metaBean
      * @param constraintDescriptors
      */
@@ -60,21 +61,20 @@ final class ConstraintFinderImpl impleme
      */
     public ElementDescriptor.ConstraintFinder unorderedAndMatchingGroups(Class<?>...
groups) {
         Set<ConstraintValidation<?>> matchingDescriptors =
-              new HashSet<ConstraintValidation<?>>(constraintDescriptors.size());
+            new HashSet<ConstraintValidation<?>>(constraintDescriptors.size());
         Groups groupChain = new GroupsComputer().computeGroups(groups);
         for (Group group : groupChain.getGroups()) {
-            if ( group.isDefault() ) {
+            if (group.isDefault()) {
                 // If group is default, check if it gets redefined
                 List<Group> expandedDefaultGroup = metaBean.getFeature(Jsr303Features.Bean.GROUP_SEQUENCE);
-                for ( Group defaultGroupMember : expandedDefaultGroup ) {
+                for (Group defaultGroupMember : expandedDefaultGroup) {
                     for (ConstraintValidation<?> descriptor : constraintDescriptors)
{
                         if (isInScope(descriptor) && isInGroup(descriptor, defaultGroupMember))
{
                             matchingDescriptors.add(descriptor);
                         }
                     }
                 }
-            }
-            else {
+            } else {
                 for (ConstraintValidation<?> descriptor : constraintDescriptors) {
                     if (isInScope(descriptor) && isInGroup(descriptor, group)) {
                         matchingDescriptors.add(descriptor);
@@ -91,9 +91,9 @@ final class ConstraintFinderImpl impleme
     public ElementDescriptor.ConstraintFinder lookingAt(Scope scope) {
         if (scope.equals(Scope.LOCAL_ELEMENT)) {
             findInScopes.remove(Scope.HIERARCHY);
-            for (Iterator<ConstraintValidation<?>> it = constraintDescriptors.iterator();
it.hasNext(); ) {
+            for (Iterator<ConstraintValidation<?>> it = constraintDescriptors.iterator();
it.hasNext();) {
                 ConstraintValidation<?> cv = it.next();
-                if ( cv.getOwner() != metaBean.getBeanClass() ) {
+                if (cv.getOwner() != metaBean.getBeanClass()) {
                     it.remove();
                 }
             }
@@ -106,7 +106,7 @@ final class ConstraintFinderImpl impleme
      */
     public ElementDescriptor.ConstraintFinder declaredOn(ElementType... elementTypes) {
         Set<ConstraintValidation<?>> matchingDescriptors =
-              new HashSet<ConstraintValidation<?>>(constraintDescriptors.size());
+            new HashSet<ConstraintValidation<?>>(constraintDescriptors.size());
         for (ElementType each : elementTypes) {
             for (ConstraintValidation<?> descriptor : constraintDescriptors) {
                 if (isInScope(descriptor) && isAtElement(descriptor, each)) {
@@ -122,17 +122,20 @@ final class ConstraintFinderImpl impleme
     }
 
     private boolean isInScope(ConstraintValidation<?> descriptor) {
-        if (findInScopes.size() == Scope.values().length) return true; // all scopes
+        if (findInScopes.size() == Scope.values().length)
+            return true; // all scopes
         if (metaBean != null) {
             Class<?> owner = descriptor.getOwner();
             for (Scope scope : findInScopes) {
                 switch (scope) {
-                    case LOCAL_ELEMENT:
-                        if (owner.equals(metaBean.getBeanClass())) return true;
-                        break;
-                    case HIERARCHY:
-                        if (!owner.equals(metaBean.getBeanClass())) return true;
-                        break;
+                case LOCAL_ELEMENT:
+                    if (owner.equals(metaBean.getBeanClass()))
+                        return true;
+                    break;
+                case HIERARCHY:
+                    if (!owner.equals(metaBean.getBeanClass()))
+                        return true;
+                    break;
                 }
             }
         }
@@ -143,8 +146,7 @@ final class ConstraintFinderImpl impleme
         return descriptor.getGroups().contains(group.getGroup());
     }
 
-    private ElementDescriptor.ConstraintFinder thisWith(
-          Set<ConstraintValidation<?>> matchingDescriptors) {
+    private ElementDescriptor.ConstraintFinder thisWith(Set<ConstraintValidation<?>>
matchingDescriptors) {
         constraintDescriptors = matchingDescriptors;
         return this;
     }
@@ -152,10 +154,9 @@ final class ConstraintFinderImpl impleme
     /**
      * {@inheritDoc}
      */
-    @SuppressWarnings("unchecked")
     public Set<ConstraintDescriptor<?>> getConstraintDescriptors() {
-        //noinspection RedundantCast
-        return (Set) constraintDescriptors;
+        return constraintDescriptors.isEmpty() ? Collections.<ConstraintDescriptor<?>>
emptySet() : Collections
+            .<ConstraintDescriptor<?>> unmodifiableSet(constraintDescriptors);
     }
 
     /**

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java?rev=997090&r1=997089&r2=997090&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ElementDescriptorImpl.java
Tue Sep 14 20:53:24 2010
@@ -16,13 +16,13 @@
  */
 package org.apache.bval.jsr303;
 
-
 import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.ElementDescriptor;
 
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.model.Validation;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -30,26 +30,59 @@ import java.util.Set;
  * Description: MetaData class<br/>
  */
 public abstract class ElementDescriptorImpl implements ElementDescriptor {
+
+    /**
+     * Get a set of {@link ConstraintDescriptor}s from the specified array of
+     * {@link Validation}s.
+     * 
+     * @param validations
+     * @return {@link ConstraintDescriptor} set
+     */
+    protected static Set<ConstraintDescriptor<?>> getConstraintDescriptors(Validation[]
validations) {
+        final Set<ConstraintDescriptor<?>> result = new HashSet<ConstraintDescriptor<?>>(validations.length);
+        for (Validation validation : validations) {
+            if (validation instanceof ConstraintValidation<?>) {
+                result.add((ConstraintValidation<?>) validation);
+            }
+        }
+        return result;
+    }
+
+    /** the MetaBean of this element */
     protected final MetaBean metaBean;
+
+    /** the raw type of this element */
     protected final Class<?> elementClass;
+
     private Set<ConstraintDescriptor<?>> constraintDescriptors;
 
-    protected ElementDescriptorImpl(MetaBean metaBean, Class<?> elementClass, 
-                                 Validation[] validations) {
+    /**
+     * Create a new ElementDescriptorImpl instance.
+     * 
+     * @param metaBean
+     * @param elementClass
+     * @param validations
+     */
+    protected ElementDescriptorImpl(MetaBean metaBean, Class<?> elementClass, Validation[]
validations) {
         this.metaBean = metaBean;
         this.elementClass = elementClass;
-        createConstraintDescriptors(validations);
+        setConstraintDescriptors(getConstraintDescriptors(validations));
     }
 
+    /**
+     * Create a new ElementDescriptorImpl instance.
+     * 
+     * @param elementClass
+     * @param validations
+     */
     protected ElementDescriptorImpl(Class<?> elementClass, Validation[] validations)
{
-        this.metaBean = null;
-        this.elementClass = elementClass;
-        createConstraintDescriptors(validations);
+        this(null, elementClass, validations);
     }
 
     /**
      * {@inheritDoc}
-     *  @return Statically defined returned type.
+     * 
+     * @return Statically defined returned type.
      */
     public Class<?> getElementClass() {
         return elementClass;
@@ -60,38 +93,39 @@ public abstract class ElementDescriptorI
      */
     @SuppressWarnings("unchecked")
     public ElementDescriptor.ConstraintFinder findConstraints() {
-        return new ConstraintFinderImpl(metaBean, (Set) constraintDescriptors);
+        return new ConstraintFinderImpl(metaBean, new HashSet((Set) constraintDescriptors));
     }
 
     /**
      * {@inheritDoc}
      */
     public Set<ConstraintDescriptor<?>> getConstraintDescriptors() {
-        return constraintDescriptors;
+        return constraintDescriptors.isEmpty() ? Collections.<ConstraintDescriptor<?>>
emptySet() : Collections
+            .unmodifiableSet(constraintDescriptors);
     }
 
     /**
-     * {@inheritDoc}
-     * return true if at least one constraint declaration is present on the element.
+     * Get the mutable {@link ConstraintDescriptor} {@link Set}.
+     * 
+     * @return Set of {@link ConstraintDescriptor}
      */
-    public boolean hasConstraints() {
-        return !constraintDescriptors.isEmpty();
+    protected Set<ConstraintDescriptor<?>> getMutableConstraintDescriptors()
{
+        return constraintDescriptors;
     }
 
-    private void createConstraintDescriptors(Validation[] validations) {
-        final Set<ConstraintDescriptor<?>> cds = new HashSet<ConstraintDescriptor<?>>(validations.length);
-        for (Validation validation : validations) {
-            if (validation instanceof ConstraintValidation<?>) {
-                ConstraintValidation<?> cval = (ConstraintValidation<?>) validation;
-                cds.add(cval);
-            }
-        }
-        setConstraintDescriptors(cds);
+    /**
+     * {@inheritDoc} return true if at least one constraint declaration is
+     * present on the element.
+     */
+    public boolean hasConstraints() {
+        return !getConstraintDescriptors().isEmpty();
     }
 
     /**
      * Set the constraintDescriptors for this element.
-     * @param constraintDescriptors to set
+     * 
+     * @param constraintDescriptors
+     *            to set
      */
     public void setConstraintDescriptors(Set<ConstraintDescriptor<?>> constraintDescriptors)
{
         this.constraintDescriptors = constraintDescriptors;
@@ -99,6 +133,7 @@ public abstract class ElementDescriptorI
 
     /**
      * Get the model {@link MetaBean} used.
+     * 
      * @return MetaBean
      */
     public MetaBean getMetaBean() {

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java?rev=997090&r1=997089&r2=997090&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java
Tue Sep 14 20:53:24 2010
@@ -18,12 +18,10 @@
  */
 package org.apache.bval.jsr303;
 
-
 import javax.validation.metadata.PropertyDescriptor;
 
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.Validation;
-
+import org.apache.bval.model.Features;
+import org.apache.bval.model.MetaProperty;
 
 /**
  * Description: {@link PropertyDescriptor} implementation.<br/>
@@ -34,25 +32,18 @@ class PropertyDescriptorImpl extends Ele
 
     /**
      * Create a new PropertyDescriptorImpl instance.
-     * @param metaBean
-     * @param propertyPath
-     * @param validations
-     */
-    PropertyDescriptorImpl(MetaBean metaBean, String propertyPath, Validation[] validations)
{
-        super(metaBean, metaBean.getProperty(propertyPath).getTypeClass(), validations);
-    }
-
-    /**
-     * Create a new PropertyDescriptorImpl instance.
-     * @param elementClass
-     * @param validations
+     * 
+     * @param property
      */
-    PropertyDescriptorImpl(Class<?> elementClass, Validation[] validations) {
-        super(elementClass, validations);
+    PropertyDescriptorImpl(MetaProperty property) {
+        super(property.getParentMetaBean(), property.getTypeClass(), property.getValidations());
+        setCascaded(property.getMetaBean() != null || property.getFeature(Features.Property.REF_CASCADE)
!= null);
+        setPropertyPath(property.getName());
     }
 
     /**
      * Set whether the referenced property is cascaded.
+     * 
      * @param cascaded
      */
     public void setCascaded(boolean cascaded) {
@@ -68,6 +59,7 @@ class PropertyDescriptorImpl extends Ele
 
     /**
      * Set the referenced property path.
+     * 
      * @param propertyPath
      */
     public void setPropertyPath(String propertyPath) {
@@ -85,7 +77,7 @@ class PropertyDescriptorImpl extends Ele
      * {@inheritDoc}
      */
     public String toString() {
-        return "PropertyDescriptorImpl{" + "returnType=" + elementClass + ", propertyPath='"
+
-              propertyPath + '\'' + '}';
+        return "PropertyDescriptorImpl{" + "returnType=" + elementClass + ", propertyPath='"
+ propertyPath + '\''
+            + '}';
     }
 }

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java?rev=997090&r1=997089&r2=997090&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java
Tue Sep 14 20:53:24 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.bval.jsr303.extensions;
 
-
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.util.HashSet;
@@ -26,29 +25,27 @@ import java.util.Set;
 import org.apache.bval.jsr303.ApacheFactoryContext;
 import org.apache.bval.jsr303.BeanDescriptorImpl;
 import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.Validation;
 
 /**
  * Description: {@link MethodBeanDescriptor} implementation.<br/>
  */
-class MethodBeanDescriptorImpl extends BeanDescriptorImpl
-      implements MethodBeanDescriptor {
+class MethodBeanDescriptorImpl extends BeanDescriptorImpl implements MethodBeanDescriptor
{
     private Map<Method, MethodDescriptor> methodConstraints;
     private Map<Constructor<?>, ConstructorDescriptor> constructorConstraints;
 
     /**
      * Create a new MethodBeanDescriptorImpl instance.
+     * 
      * @param factoryContext
      * @param metaBean
-     * @param validations
      */
-    protected MethodBeanDescriptorImpl(ApacheFactoryContext factoryContext,
-                                       MetaBean metaBean, Validation[] validations) {
-        super(factoryContext, metaBean, validations);
+    protected MethodBeanDescriptorImpl(ApacheFactoryContext factoryContext, MetaBean metaBean)
{
+        super(factoryContext, metaBean);
     }
 
     /**
      * Set the map of method constraints for this bean.
+     * 
      * @param methodConstraints
      */
     public void setMethodConstraints(Map<Method, MethodDescriptor> methodConstraints)
{
@@ -57,10 +54,10 @@ class MethodBeanDescriptorImpl extends B
 
     /**
      * Set the map of constructor constraints for this bean.
+     * 
      * @param constructorConstraints
      */
-    public void setConstructorConstraints(
-          Map<Constructor<?>, ConstructorDescriptor> constructorConstraints)
{
+    public void setConstructorConstraints(Map<Constructor<?>, ConstructorDescriptor>
constructorConstraints) {
         this.constructorConstraints = constructorConstraints;
     }
 
@@ -87,6 +84,7 @@ class MethodBeanDescriptorImpl extends B
 
     /**
      * Add a {@link MethodDescriptor} to this {@link MethodBeanDescriptorImpl}.
+     * 
      * @param method
      * @param desc
      */
@@ -102,7 +100,9 @@ class MethodBeanDescriptorImpl extends B
     }
 
     /**
-     * Add a {@link ConstructorDescriptor} to this {@link MethodBeanDescriptorImpl}.
+     * Add a {@link ConstructorDescriptor} to this
+     * {@link MethodBeanDescriptorImpl}.
+     * 
      * @param cons
      * @param desc
      */
@@ -112,6 +112,7 @@ class MethodBeanDescriptorImpl extends B
 
     /**
      * Get the configured method constraints.
+     * 
      * @return {@link Map} of {@link Method} : {@link MethodDescriptor}
      */
     public Map<Method, MethodDescriptor> getMethodConstraints() {
@@ -120,7 +121,9 @@ class MethodBeanDescriptorImpl extends B
 
     /**
      * Get the configured constructor constraints.
-     * @return {@link Map} of {@link Constructor} : {@link ConstructorDescriptor}
+     * 
+     * @return {@link Map} of {@link Constructor} :
+     *         {@link ConstructorDescriptor}
      */
     public Map<Constructor<?>, ConstructorDescriptor> getConstructorConstraints()
{
         return constructorConstraints;

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java?rev=997090&r1=997089&r2=997090&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java
Tue Sep 14 20:53:24 2010
@@ -16,10 +16,11 @@
  */
 package org.apache.bval.jsr303.extensions;
 
-
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
+import org.apache.bval.jsr303.ConstraintValidation;
 import org.apache.bval.jsr303.ElementDescriptorImpl;
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.model.Validation;
@@ -27,13 +28,13 @@ import org.apache.bval.model.Validation;
 /**
  * Description: {@link MethodDescriptor} implementation.<br/>
  */
-public class MethodDescriptorImpl extends ElementDescriptorImpl
-      implements MethodDescriptor, ProcedureDescriptor {
+public class MethodDescriptorImpl extends ElementDescriptorImpl implements MethodDescriptor,
ProcedureDescriptor {
     private final List<ParameterDescriptor> parameterDescriptors = new ArrayList<ParameterDescriptor>();
     private boolean cascaded;
 
     /**
      * Create a new MethodDescriptorImpl instance.
+     * 
      * @param metaBean
      * @param validations
      */
@@ -43,6 +44,7 @@ public class MethodDescriptorImpl extend
 
     /**
      * Create a new MethodDescriptorImpl instance.
+     * 
      * @param elementClass
      * @param validations
      */
@@ -53,8 +55,8 @@ public class MethodDescriptorImpl extend
     /**
      * {@inheritDoc}
      */
-    public List<ParameterDescriptor> getParameterDescriptors() //index aligned
-    {
+    public List<ParameterDescriptor> getParameterDescriptors() {
+        // index aligned
         return parameterDescriptors;
     }
 
@@ -72,4 +74,11 @@ public class MethodDescriptorImpl extend
         this.cascaded = cascaded;
     }
 
+    /**
+     * Add the specified validations to this {@link MethodDescriptorImpl}.
+     * @param validations
+     */
+    void addValidations(Collection<ConstraintValidation<?>> validations) {
+        getMutableConstraintDescriptors().addAll(validations);
+    }
 }

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java?rev=997090&r1=997089&r2=997090&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java
Tue Sep 14 20:53:24 2010
@@ -68,8 +68,7 @@ class MethodValidatorImpl extends ClassV
      */
     @Override
     protected BeanDescriptorImpl createBeanDescriptor(MetaBean metaBean) {
-        MethodBeanDescriptorImpl descriptor =
-            new MethodBeanDescriptorImpl(factoryContext, metaBean, metaBean.getValidations());
+        MethodBeanDescriptorImpl descriptor = new MethodBeanDescriptorImpl(factoryContext,
metaBean);
         MethodValidatorMetaBeanFactory factory = new MethodValidatorMetaBeanFactory(factoryContext);
         factory.buildMethodDescriptor(descriptor);
         return descriptor;

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=997090&r1=997089&r2=997090&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
Tue Sep 14 20:53:24 2010
@@ -113,7 +113,7 @@ public class MethodValidatorMetaBeanFact
                         processAnnotation(anno, methodDesc, returnAccess, validations);
                     }
                 }
-                methodDesc.getConstraintDescriptors().addAll(validations.getValidations());
+                methodDesc.addValidations(validations.getValidations());
 
                 // parameter validations
                 Annotation[][] paramsAnnos = method.getParameterAnnotations();

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java?rev=997090&r1=997089&r2=997090&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/BeanDescriptorTest.java
Tue Sep 14 20:53:24 2010
@@ -36,6 +36,7 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 import java.util.Locale;
 import java.util.Set;
+import org.apache.bval.jsr303.util.TestUtils;
 
 import static java.lang.annotation.ElementType.*;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
@@ -163,6 +164,10 @@ public class BeanDescriptorTest extends 
         
         constraints = nameDescriptor.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
         Assert.assertEquals("Incorrect number of descriptors", 0, constraints.size());
+        TestUtils.failOnModifiable(constraints, "constraintFinder constraintDescriptors");
+        //verify that changes to one ConstraintFinder don't affect the base:
+        constraints = nameDescriptor.getConstraintDescriptors();
+        Assert.assertEquals("Incorrect number of descriptors", 1, constraints.size());
     }
     
     public static class Form {

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java?rev=997090&r1=997089&r2=997090&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java
Tue Sep 14 20:53:24 2010
@@ -102,6 +102,7 @@ public class Jsr303Test extends TestCase
 //        assertEquals(false, bc.isCascaded());
 //        assertEquals("", bc.getPropertyPath());
         Assert.assertTrue(bc.getConstraintDescriptors() != null);
+        TestUtils.failOnModifiable(bc.getConstraintDescriptors(), "beanDescriptor constraintDescriptors");
     }
 
     public void testMetadataAPI_Engine() {
@@ -118,10 +119,11 @@ public class Jsr303Test extends TestCase
         Assert.assertFalse(validator.getConstraintsForClass(Address.class)
               .getConstraintDescriptors().isEmpty());
 
-        Set<PropertyDescriptor> props =
-              validator.getConstraintsForClass(Address.class).getConstrainedProperties();
-        Set<String> propNames = new HashSet(props.size());
+        Set<PropertyDescriptor> props = validator.getConstraintsForClass(Address.class).getConstrainedProperties();
+        TestUtils.failOnModifiable(props, "beanDescriptor constrainedProperties");
+        Set<String> propNames = new HashSet<String>(props.size());
         for (PropertyDescriptor each : props) {
+            TestUtils.failOnModifiable(each.getConstraintDescriptors(), "propertyDescriptor
constraintDescriptors");
             propNames.add(each.getPropertyName());
         }
         Assert.assertTrue(propNames.contains("addressline1")); // annotated at field level

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/TestUtils.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/TestUtils.java?rev=997090&r1=997089&r2=997090&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/TestUtils.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/util/TestUtils.java
Tue Sep 14 20:53:24 2010
@@ -18,9 +18,13 @@
  */
 package org.apache.bval.jsr303.util;
 
-import javax.validation.ConstraintViolation;
+import java.util.Collection;
 import java.util.Set;
 
+import javax.validation.ConstraintViolation;
+
+import org.junit.Assert;
+
 /**
  * Description: <br/>
  */
@@ -45,4 +49,23 @@ public class TestUtils {
         }
         return null;
     }
+
+    /**
+     * assume set addition either does nothing, returning false per collection
+     * contract, or throws an Exception; in either case size should remain
+     * unchanged
+     * 
+     * @param collection
+     */
+    public static void failOnModifiable(Collection<?> collection, String description)
{
+        int size = collection.size();
+        try {
+            Assert
+                .assertFalse(String.format("should not permit modification to %s", description),
collection.add(null));
+        } catch (Exception e) {
+            // okay
+        }
+        Assert.assertEquals("constraint descriptor set size changed", size, collection.size());
+    }
+
 }



Mime
View raw message