bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r992420 [2/3] - in /incubator/bval/trunk: bval-core/src/main/java/org/apache/bval/ bval-core/src/main/java/org/apache/bval/routines/ bval-core/src/main/java/org/apache/bval/util/ bval-core/src/test/java/org/apache/bval/model/ bval-json/src/...
Date Fri, 03 Sep 2010 19:02:19 GMT
Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java?rev=992420&r1=992419&r2=992420&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java Fri Sep  3 19:02:18 2010
@@ -18,7 +18,6 @@
  */
 package org.apache.bval.jsr303;
 
-
 import org.apache.bval.jsr303.util.NodeImpl;
 import org.apache.bval.jsr303.util.PathImpl;
 import org.apache.bval.model.Validation;
@@ -40,327 +39,348 @@ import java.util.*;
  * Description: Adapter between Constraint (JSR303) and Validation (Core)<br/>
  * this instance is immutable!<br/>
  */
-public class ConstraintValidation<T extends Annotation>
-    implements Validation, ConstraintDescriptor<T> {
-  private static final String ANNOTATION_MESSAGE = "message";
-
-  private final ConstraintValidator<T, ?> validator;
-  private T annotation; // for metadata request API
-  private final AccessStrategy access;
-  private final boolean reportFromComposite;
-  private final Map<String, Object> attributes;
-
-  private Set<ConstraintValidation<?>> composedConstraints;
-
-  /**
-   * the owner is the type where the validation comes from.
-   * it is used to support implicit grouping.
-   */
-  private final Class<?> owner;
-  private Set<Class<?>> groups;
-  private Set<Class<? extends Payload>> payload;
-  private Class<? extends ConstraintValidator<T, ?>>[] validatorClasses;
-
-  /**
-   * Create a new ConstraintValidation instance.
-   * @param validatorClasses
-   * @param validator  - the constraint validator
-   * @param annotation - the annotation of the constraint
-   * @param owner      - the type where the annotated element is placed
-   *                   (class, interface, annotation type)
-   * @param access     - how to access the value
-   * @param reportFromComposite
-   */
-  public ConstraintValidation(
-      Class<? extends ConstraintValidator<T, ?>>[] validatorClasses,
-      ConstraintValidator<T, ?> validator, T annotation, Class<?> owner,
-      AccessStrategy access, boolean reportFromComposite) {
-    this.attributes = new HashMap<String, Object>();
-    this.validatorClasses = validatorClasses;
-    this.validator = validator;
-    this.annotation = annotation;
-    this.owner = owner;
-    this.access = access;
-    this.reportFromComposite = reportFromComposite;
-  }
-
-  /**
-   * Return a {@link Serializable} {@link ConstraintDescriptor} capturing a snapshot of current state.
-   * @return {@link ConstraintDescriptor}
-   */
-  public ConstraintDescriptor<T> asSerializableDescriptor() {
-    return new ConstraintDescriptorImpl<T>(this);
-  }
-
-  /**
-   * Set the applicable validation groups.
-   * @param groups
-   */
-  void setGroups(Set<Class<?>> groups) {
-    this.groups = groups;
-    this.attributes.put("groups", groups.toArray(new Class[groups.size()]));
-  }
-
-  /**
-   * Set the payload.
-   * @param payload
-   */
-  void setPayload(Set<Class<? extends Payload>> payload) {
-    this.payload = payload;
-    this.attributes.put("payload", payload.toArray(new Class[payload.size()]));
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public boolean isReportAsSingleViolation() {
-    return reportFromComposite;
-  }
-
-  /**
-   * Add a composing constraint.
-   * @param aConstraintValidation to add
-   */
-  public void addComposed(ConstraintValidation<?> aConstraintValidation) {
-    if (composedConstraints == null) {
-      composedConstraints = new HashSet<ConstraintValidation<?>>();
-    }
-    composedConstraints.add(aConstraintValidation);
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public <L extends ValidationListener> void validate(ValidationContext<L> context) {
-    validate((GroupValidationContext<?>) context);
-  }
-
-  /**
-   * Validate a {@link GroupValidationContext}.
-   * @param context root
-   */
-  public void validate(GroupValidationContext<?> context) {
-    context.setConstraintValidation(this);
-    /**
-     * execute unless the given validation constraint has already been processed
-     * during this validation routine (as part of a previous group match)
-     */
-    if (!isMemberOf(context.getCurrentGroup().getGroup())) {
-      return; // do not validate in the current group
-    }
-    if (context.getCurrentOwner() != null && this.owner != context.getCurrentOwner()) {
-      return;
-    }
-    if (validator != null && !context.collectValidated(validator))
-      return; // already done
-
-    if (context.getMetaProperty() != null && !isReachable(context)) {
-      return;
-    }
-
-    // process composed constraints
-    if (isReportAsSingleViolation()) {
-      ConstraintValidationListener<?> listener = context.getListener();
-      listener.beginReportAsSingle();
-
-      boolean failed = false;
-      try {
-          // stop validating when already failed and ReportAsSingleInvalidConstraint = true ?
-          for (Iterator<ConstraintValidation<?>> composed = getComposingValidations().iterator(); !failed && composed.hasNext();) {
-              composed.next().validate(context);
-              failed = listener.hasViolations();
-          }
-      } finally {
-          listener.endReportAsSingle();
-          // Restore current constraint validation
-          context.setConstraintValidation(this);
-      }
-
-      if (failed) {
-        // TODO RSt - how should the composed constraint error report look like?
-        ConstraintValidatorContextImpl jsrContext =
-            new ConstraintValidatorContextImpl(context, this);
-        addErrors(context, jsrContext); // add defaultErrorMessage only*/
-        return;
-      }
-    } else {
-      for (ConstraintValidation<?> composed : getComposingValidations()) {
-        composed.validate(context);
-      }
-
-      // Restore current constraint validation
-      context.setConstraintValidation(this);
-    }
-
-    if (validator != null) {
-      ConstraintValidatorContextImpl jsrContext =
-          new ConstraintValidatorContextImpl(context, this);
-      @SuppressWarnings("unchecked")
-      final ConstraintValidator<T, Object> objectValidator = (ConstraintValidator<T, Object>) validator;
-      if (!objectValidator.isValid(context.getValidatedValue(), jsrContext)) {
-        addErrors(context, jsrContext);
-      }
-    }
-  }
-
-  /**
-   * Initialize the validator (if not <code>null</code>) with the stored
-   * annotation.
-   */
-  public void initialize() {
-    if (null != validator) {
-      try {
-        validator.initialize(annotation);
-      } catch (RuntimeException e) {
-        // Either a "legit" problem initializing the validator or a
-        // ClassCastException if the validator associated annotation is
-        // not a supertype of the validated annotation.
-        throw new ConstraintDefinitionException(
-            "Incorrect validator [" + validator.getClass().getCanonicalName() + "] for annotation " +
-                annotation.annotationType().getCanonicalName(), e);
-      }
-    }
-  }
-
-  private boolean isReachable(GroupValidationContext<?> context) {
-    PathImpl path = context.getPropertyPath();
-    NodeImpl node = path.getLeafNode();
-    PathImpl beanPath = path.getPathWithoutLeafNode();
-    if (beanPath == null) {
-      beanPath = PathImpl.create(null);
-    }
-    try {
-      if (!context.getTraversableResolver()
-          .isReachable(context.getBean(), node,
-              context.getRootMetaBean().getBeanClass(), beanPath,
-              access.getElementType())) return false;
-    } catch (RuntimeException e) {
-      throw new ValidationException(
-          "Error in TraversableResolver.isReachable() for " + context.getBean(), e);
-    }
-
-    return true;
-  }
-
-  private void addErrors(GroupValidationContext<?> context,
-                         ConstraintValidatorContextImpl jsrContext) {
-    for (ValidationListener.Error each : jsrContext.getErrorMessages()) {
-      context.getListener().addError(each, context);
-    }
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public String toString() {
-    return "ConstraintValidation{" + validator + '}';
-  }
-
-  /**
-   * Get the message template used by this constraint.
-   * @return String
-   */
-  public String getMessageTemplate() {
-    return (String) attributes.get(ANNOTATION_MESSAGE);
-  }
-
-  /**
-   * Get the {@link ConstraintValidator} invoked by this {@link ConstraintValidation}.
-   * @return
-   */
-  public ConstraintValidator<T, ?> getValidator() {
-    return validator;
-  }
-
-  /**
-   * Learn whether this {@link ConstraintValidation} belongs to the specified group.
-   * @param reqGroup
-   * @return boolean
-   */
-  protected boolean isMemberOf(Class<?> reqGroup) {
-    return groups.contains(reqGroup);
-  }
-
-  /**
-   * Get the owning class of this {@link ConstraintValidation}.
-   * @return Class
-   */
-  public Class<?> getOwner() {
-    return owner;
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public T getAnnotation() {
-    return annotation;
-  }
-
-  /**
-   * Get the {@link AccessStrategy} used by this {@link ConstraintValidation}.
-   * @return {@link AccessStrategy}
-   */
-  public AccessStrategy getAccess() {
-    return access;
-  }
-
-  /**
-   * Override the Annotation set at construction.
-   * @param annotation
-   */
-  public void setAnnotation(T annotation) {
-    this.annotation = annotation;
-  }
-
-  /////////////////////////// ConstraintDescriptor implementation
-
-  /**
-   * {@inheritDoc}
-   */
-  public Map<String, Object> getAttributes() {
-    return attributes;
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  @SuppressWarnings("unchecked")
-  public Set<ConstraintDescriptor<?>> getComposingConstraints() {
-    return composedConstraints == null ? Collections.EMPTY_SET : composedConstraints;
-  }
-
-  /**
-   * Get the composing {@link ConstraintValidation} objects.  This is effectively
-   * an implementation-specific analogue to {@link #getComposingConstraints()}.
-   * @return {@link Set} of {@link ConstraintValidation}
-   */
-  @SuppressWarnings("unchecked")
-  Set<ConstraintValidation<?>> getComposingValidations() {
-    return composedConstraints == null ? Collections.EMPTY_SET : composedConstraints;
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public Set<Class<?>> getGroups() {
-    return groups;
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public Set<Class<? extends Payload>> getPayload() {
-    return payload;
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public List<Class<? extends ConstraintValidator<T, ?>>> getConstraintValidatorClasses() {
-    if (validatorClasses == null) {
-      return Collections.emptyList();
+public class ConstraintValidation<T extends Annotation> implements Validation, ConstraintDescriptor<T> {
+    private static final String ANNOTATION_MESSAGE = "message";
+
+    private final ConstraintValidator<T, ?> validator;
+    private T annotation; // for metadata request API
+    private final AccessStrategy access;
+    private final boolean reportFromComposite;
+    private final Map<String, Object> attributes;
+
+    private Set<ConstraintValidation<?>> composedConstraints;
+
+    /**
+     * the owner is the type where the validation comes from. it is used to
+     * support implicit grouping.
+     */
+    private final Class<?> owner;
+    private Set<Class<?>> groups;
+    private Set<Class<? extends Payload>> payload;
+    private Class<? extends ConstraintValidator<T, ?>>[] validatorClasses;
+
+    /**
+     * Create a new ConstraintValidation instance.
+     * 
+     * @param validatorClasses
+     * @param validator
+     *            - the constraint validator
+     * @param annotation
+     *            - the annotation of the constraint
+     * @param owner
+     *            - the type where the annotated element is placed (class,
+     *            interface, annotation type)
+     * @param access
+     *            - how to access the value
+     * @param reportFromComposite
+     */
+    public ConstraintValidation(Class<? extends ConstraintValidator<T, ?>>[] validatorClasses,
+        ConstraintValidator<T, ?> validator, T annotation, Class<?> owner, AccessStrategy access,
+        boolean reportFromComposite) {
+        this.attributes = new HashMap<String, Object>();
+        this.validatorClasses = validatorClasses;
+        this.validator = validator;
+        this.annotation = annotation;
+        this.owner = owner;
+        this.access = access;
+        this.reportFromComposite = reportFromComposite;
+    }
+
+    /**
+     * Return a {@link Serializable} {@link ConstraintDescriptor} capturing a
+     * snapshot of current state.
+     * 
+     * @return {@link ConstraintDescriptor}
+     */
+    public ConstraintDescriptor<T> asSerializableDescriptor() {
+        return new ConstraintDescriptorImpl<T>(this);
+    }
+
+    /**
+     * Set the applicable validation groups.
+     * 
+     * @param groups
+     */
+    void setGroups(Set<Class<?>> groups) {
+        this.groups = groups;
+        this.attributes.put("groups", groups.toArray(new Class[groups.size()]));
+    }
+
+    /**
+     * Set the payload.
+     * 
+     * @param payload
+     */
+    void setPayload(Set<Class<? extends Payload>> payload) {
+        this.payload = payload;
+        this.attributes.put("payload", payload.toArray(new Class[payload.size()]));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isReportAsSingleViolation() {
+        return reportFromComposite;
+    }
+
+    /**
+     * Add a composing constraint.
+     * 
+     * @param aConstraintValidation
+     *            to add
+     */
+    public void addComposed(ConstraintValidation<?> aConstraintValidation) {
+        if (composedConstraints == null) {
+            composedConstraints = new HashSet<ConstraintValidation<?>>();
+        }
+        composedConstraints.add(aConstraintValidation);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public <L extends ValidationListener> void validate(ValidationContext<L> context) {
+        validate((GroupValidationContext<?>) context);
+    }
+
+    /**
+     * Validate a {@link GroupValidationContext}.
+     * 
+     * @param context
+     *            root
+     */
+    public void validate(GroupValidationContext<?> context) {
+        context.setConstraintValidation(this);
+        /**
+         * execute unless the given validation constraint has already been
+         * processed during this validation routine (as part of a previous group
+         * match)
+         */
+        if (!isMemberOf(context.getCurrentGroup().getGroup())) {
+            return; // do not validate in the current group
+        }
+        if (context.getCurrentOwner() != null && this.owner != context.getCurrentOwner()) {
+            return;
+        }
+        if (validator != null && !context.collectValidated(validator))
+            return; // already done
+
+        if (context.getMetaProperty() != null && !isReachable(context)) {
+            return;
+        }
+
+        // process composed constraints
+        if (isReportAsSingleViolation()) {
+            ConstraintValidationListener<?> listener = context.getListener();
+            listener.beginReportAsSingle();
+
+            boolean failed = false;
+            try {
+                // stop validating when already failed and
+                // ReportAsSingleInvalidConstraint = true ?
+                for (Iterator<ConstraintValidation<?>> composed = getComposingValidations().iterator(); !failed
+                    && composed.hasNext();) {
+                    composed.next().validate(context);
+                    failed = listener.hasViolations();
+                }
+            } finally {
+                listener.endReportAsSingle();
+                // Restore current constraint validation
+                context.setConstraintValidation(this);
+            }
+
+            if (failed) {
+                // TODO RSt - how should the composed constraint error report
+                // look like?
+                ConstraintValidatorContextImpl jsrContext = new ConstraintValidatorContextImpl(context, this);
+                addErrors(context, jsrContext); // add defaultErrorMessage
+                                                // only*/
+                return;
+            }
+        } else {
+            for (ConstraintValidation<?> composed : getComposingValidations()) {
+                composed.validate(context);
+            }
+
+            // Restore current constraint validation
+            context.setConstraintValidation(this);
+        }
+
+        if (validator != null) {
+            ConstraintValidatorContextImpl jsrContext = new ConstraintValidatorContextImpl(context, this);
+            @SuppressWarnings("unchecked")
+            final ConstraintValidator<T, Object> objectValidator = (ConstraintValidator<T, Object>) validator;
+            if (!objectValidator.isValid(context.getValidatedValue(), jsrContext)) {
+                addErrors(context, jsrContext);
+            }
+        }
+    }
+
+    /**
+     * Initialize the validator (if not <code>null</code>) with the stored
+     * annotation.
+     */
+    public void initialize() {
+        if (null != validator) {
+            try {
+                validator.initialize(annotation);
+            } catch (RuntimeException e) {
+                // Either a "legit" problem initializing the validator or a
+                // ClassCastException if the validator associated annotation is
+                // not a supertype of the validated annotation.
+                throw new ConstraintDefinitionException("Incorrect validator ["
+                    + validator.getClass().getCanonicalName() + "] for annotation "
+                    + annotation.annotationType().getCanonicalName(), e);
+            }
+        }
+    }
+
+    private boolean isReachable(GroupValidationContext<?> context) {
+        PathImpl path = context.getPropertyPath();
+        NodeImpl node = path.getLeafNode();
+        PathImpl beanPath = path.getPathWithoutLeafNode();
+        if (beanPath == null) {
+            beanPath = PathImpl.create(null);
+        }
+        try {
+            if (!context.getTraversableResolver().isReachable(context.getBean(), node,
+                context.getRootMetaBean().getBeanClass(), beanPath, access.getElementType()))
+                return false;
+        } catch (RuntimeException e) {
+            throw new ValidationException("Error in TraversableResolver.isReachable() for " + context.getBean(), e);
+        }
+
+        return true;
+    }
+
+    private void addErrors(GroupValidationContext<?> context, ConstraintValidatorContextImpl jsrContext) {
+        for (ValidationListener.Error each : jsrContext.getErrorMessages()) {
+            context.getListener().addError(each, context);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() {
+        return "ConstraintValidation{" + validator + '}';
+    }
+
+    /**
+     * Get the message template used by this constraint.
+     * 
+     * @return String
+     */
+    public String getMessageTemplate() {
+        return (String) attributes.get(ANNOTATION_MESSAGE);
+    }
+
+    /**
+     * Get the {@link ConstraintValidator} invoked by this
+     * {@link ConstraintValidation}.
+     * 
+     * @return
+     */
+    public ConstraintValidator<T, ?> getValidator() {
+        return validator;
+    }
+
+    /**
+     * Learn whether this {@link ConstraintValidation} belongs to the specified
+     * group.
+     * 
+     * @param reqGroup
+     * @return boolean
+     */
+    protected boolean isMemberOf(Class<?> reqGroup) {
+        return groups.contains(reqGroup);
+    }
+
+    /**
+     * Get the owning class of this {@link ConstraintValidation}.
+     * 
+     * @return Class
+     */
+    public Class<?> getOwner() {
+        return owner;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public T getAnnotation() {
+        return annotation;
+    }
+
+    /**
+     * Get the {@link AccessStrategy} used by this {@link ConstraintValidation}.
+     * 
+     * @return {@link AccessStrategy}
+     */
+    public AccessStrategy getAccess() {
+        return access;
+    }
+
+    /**
+     * Override the Annotation set at construction.
+     * 
+     * @param annotation
+     */
+    public void setAnnotation(T annotation) {
+        this.annotation = annotation;
+    }
+
+    // ///////////////////////// ConstraintDescriptor implementation
+
+    /**
+     * {@inheritDoc}
+     */
+    public Map<String, Object> getAttributes() {
+        return attributes;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @SuppressWarnings("unchecked")
+    public Set<ConstraintDescriptor<?>> getComposingConstraints() {
+        return composedConstraints == null ? Collections.EMPTY_SET : composedConstraints;
+    }
+
+    /**
+     * Get the composing {@link ConstraintValidation} objects. This is
+     * effectively an implementation-specific analogue to
+     * {@link #getComposingConstraints()}.
+     * 
+     * @return {@link Set} of {@link ConstraintValidation}
+     */
+    @SuppressWarnings("unchecked")
+    Set<ConstraintValidation<?>> getComposingValidations() {
+        return composedConstraints == null ? Collections.EMPTY_SET : composedConstraints;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Set<Class<?>> getGroups() {
+        return groups;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Set<Class<? extends Payload>> getPayload() {
+        return payload;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Class<? extends ConstraintValidator<T, ?>>> getConstraintValidatorClasses() {
+        if (validatorClasses == null) {
+            return Collections.emptyList();
+        }
+        return Arrays.asList(validatorClasses);
     }
-    return Arrays.asList(validatorClasses);
-  }
 
 }

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=992420&r1=992419&r2=992420&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 Fri Sep  3 19:02:18 2010
@@ -37,291 +37,287 @@ import java.util.Set;
  * Description: experimental implementation of method-level-validation <br/>
  */
 class MethodValidatorImpl extends ClassValidator implements MethodValidator {
-  /**
-   * Create a new MethodValidatorImpl instance.
-   * @param factoryContext
-   */
-  public MethodValidatorImpl(ApacheFactoryContext factoryContext) {
-    super(factoryContext);
-    patchFactoryContextForMethodValidation(factoryContext);
-  }
-
-  /**
-   * experimental: replace the Jsr303MetaBeanFactory with a MethodValidatorMetaBeanFactory in the factoryContext.
-   * @param factoryContext
-   */
-  private void patchFactoryContextForMethodValidation(ApacheFactoryContext factoryContext) {
-    MetaBeanFactory[] factories = ((MetaBeanManager) getMetaBeanFinder()).getBuilder().getFactories();
-    for (int i = 0; i < factories.length; i++) {
-      if (factories[i] instanceof Jsr303MetaBeanFactory && !(factories[i] instanceof MethodValidatorMetaBeanFactory)) {
-        factories[i] = new MethodValidatorMetaBeanFactory(factoryContext);
-      }
-    }
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override
-  protected BeanDescriptorImpl createBeanDescriptor(MetaBean metaBean) {
-    MethodBeanDescriptorImpl descriptor = new MethodBeanDescriptorImpl(factoryContext,
-        metaBean, metaBean.getValidations());
-    MethodValidatorMetaBeanFactory factory =
-        new MethodValidatorMetaBeanFactory(factoryContext);
-    factory.buildMethodDescriptor(descriptor);
-    return descriptor;
-  }
-
-  /**
-   * {@inheritDoc}
-   * enhancement: method-level-validation not yet completly implemented
-   * <pre>example:
-   * <code>
-   * public @NotNull String saveItem(@Valid @NotNull Item item, @Max(23) BigDecimal
-   * </code></pre>
-   * spec:
-   * The constraints declarations evaluated are the constraints hosted on the
-   * parameters of the method or constructor. If @Valid is placed on a parameter,
-   * constraints declared on the object itself are considered.
-   *
-   * @throws IllegalArgumentException enhancement: if the method does not belong to <code>T</code>
-   *                                  or if the Object[] does not match the method signature
-   */
-  public <T> Set<ConstraintViolation<T>> validateParameters(Class<T> clazz, Method method,
-                                                            Object[] parameters,
-                                                            Class<?>... groupArray) {
-    MethodBeanDescriptorImpl beanDesc =
-        (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
-    MethodDescriptorImpl methodDescriptor =
-        (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
-    if ( methodDescriptor == null ) {
-        throw new ValidationException("Method " + method + " doesn't belong to class " + clazz);
-    }
-    return validateParameters(methodDescriptor.getMetaBean(),
-        methodDescriptor.getParameterDescriptors(), parameters, groupArray);
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz, Method method,
-                                                           Object parameter,
-                                                           int parameterIndex,
-                                                           Class<?>... groupArray) {
-    MethodBeanDescriptorImpl beanDesc =
-        (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
-    MethodDescriptorImpl methodDescriptor =
-        (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
-    if ( methodDescriptor == null ) {
-        throw new ValidationException("Method " + method + " doesn't belong to class " + clazz);
-    }
-    ParameterDescriptorImpl paramDesc = (ParameterDescriptorImpl) methodDescriptor
-        .getParameterDescriptors().get(parameterIndex);
-    return validateParameter(paramDesc, parameter, groupArray);
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public <T> Set<ConstraintViolation<T>> validateParameters(Class<T> clazz,
-                                                            Constructor<T> constructor,
-                                                            Object[] parameters,
-                                                            Class<?>... groupArray) {
-    MethodBeanDescriptorImpl beanDesc =
-        (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
-    ConstructorDescriptorImpl constructorDescriptor =
-        (ConstructorDescriptorImpl) beanDesc.getConstraintsForConstructor(constructor);
-    if ( constructorDescriptor == null ) {
-        throw new ValidationException("Constructor " + constructor + " doesn't belong to class " + clazz);
-    }
-    return validateParameters(constructorDescriptor.getMetaBean(),
-        constructorDescriptor.getParameterDescriptors(), parameters, groupArray);
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  public <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz,
-                                                           Constructor<T> constructor,
-                                                           Object parameter,
-                                                           int parameterIndex,
-                                                           Class<?>... groupArray) {
-    MethodBeanDescriptorImpl beanDesc =
-        (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
-    ConstructorDescriptorImpl constructorDescriptor =
-        (ConstructorDescriptorImpl) beanDesc.getConstraintsForConstructor(constructor);
-    if ( constructorDescriptor == null ) {
-        throw new ValidationException("Constructor " + constructor + " doesn't belong to class " + clazz);
-    }
-    ParameterDescriptorImpl paramDesc = (ParameterDescriptorImpl) constructorDescriptor
-        .getParameterDescriptors().get(parameterIndex);
-    return validateParameter(paramDesc, parameter, groupArray);
-  }
-
-  /**
-   * {@inheritDoc}
-   * If @Valid  is placed on the method, the constraints declared on the object
-   * itself are considered.
-   */
-  @SuppressWarnings("unchecked")
-  public <T> Set<ConstraintViolation<T>> validateReturnedValue(Class<T> clazz, Method method,
-                                                               Object returnedValue,
-                                                               Class<?>... groupArray) {
-    MethodBeanDescriptorImpl beanDesc =
-        (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
-    MethodDescriptorImpl methodDescriptor =
-        (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
-    if ( methodDescriptor == null ) {
-        throw new ValidationException("Method " + method + " doesn't belong to class " + clazz);
-    }
-    final GroupValidationContext<Object> context =
-        createContext(methodDescriptor.getMetaBean(), returnedValue, null, groupArray);
-    validateReturnedValueInContext(context, methodDescriptor);
-    ConstraintValidationListener<T> result = (ConstraintValidationListener<T>) context.getListener();
-    return result.getConstraintViolations();
-  }
-
-  @SuppressWarnings("unchecked")
-  private <T> Set<ConstraintViolation<T>> validateParameters(MetaBean metaBean,
-                                                             List<ParameterDescriptor> paramDescriptors,
-                                                             Object[] parameters,
-                                                             Class<?>... groupArray) {
-    if (parameters == null) throw new IllegalArgumentException("cannot validate null");
-    if (parameters.length > 0) {
-      try {
-        GroupValidationContext<ConstraintValidationListener<Object[]>> context =
-            createContext(metaBean, null, null, groupArray);
-        for (int i = 0; i < parameters.length; i++) {
-          ParameterDescriptorImpl paramDesc =
-              (ParameterDescriptorImpl) paramDescriptors.get(i);
-          context.setBean(parameters[i]);
-          validateParameterInContext(context, paramDesc);
+    /**
+     * Create a new MethodValidatorImpl instance.
+     * 
+     * @param factoryContext
+     */
+    public MethodValidatorImpl(ApacheFactoryContext factoryContext) {
+        super(factoryContext);
+        patchFactoryContextForMethodValidation(factoryContext);
+    }
+
+    /**
+     * experimental: replace the Jsr303MetaBeanFactory with a
+     * MethodValidatorMetaBeanFactory in the factoryContext.
+     * 
+     * @param factoryContext
+     */
+    private void patchFactoryContextForMethodValidation(ApacheFactoryContext factoryContext) {
+        MetaBeanFactory[] factories = ((MetaBeanManager) getMetaBeanFinder()).getBuilder().getFactories();
+        for (int i = 0; i < factories.length; i++) {
+            if (factories[i] instanceof Jsr303MetaBeanFactory
+                && !(factories[i] instanceof MethodValidatorMetaBeanFactory)) {
+                factories[i] = new MethodValidatorMetaBeanFactory(factoryContext);
+            }
         }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected BeanDescriptorImpl createBeanDescriptor(MetaBean metaBean) {
+        MethodBeanDescriptorImpl descriptor =
+            new MethodBeanDescriptorImpl(factoryContext, metaBean, metaBean.getValidations());
+        MethodValidatorMetaBeanFactory factory = new MethodValidatorMetaBeanFactory(factoryContext);
+        factory.buildMethodDescriptor(descriptor);
+        return descriptor;
+    }
+
+    /**
+     * {@inheritDoc} enhancement: method-level-validation not yet completly
+     * implemented
+     * 
+     * <pre>
+     * example:
+     * <code>
+     * public @NotNull String saveItem(@Valid @NotNull Item item, @Max(23) BigDecimal
+     * </code>
+     * </pre>
+     * 
+     * spec: The constraints declarations evaluated are the constraints hosted
+     * on the parameters of the method or constructor. If @Valid is placed on a
+     * parameter, constraints declared on the object itself are considered.
+     * 
+     * @throws IllegalArgumentException
+     *             enhancement: if the method does not belong to <code>T</code>
+     *             or if the Object[] does not match the method signature
+     */
+    public <T> Set<ConstraintViolation<T>> validateParameters(Class<T> clazz, Method method, Object[] parameters,
+        Class<?>... groupArray) {
+        MethodBeanDescriptorImpl beanDesc = (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
+        MethodDescriptorImpl methodDescriptor = (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
+        if (methodDescriptor == null) {
+            throw new ValidationException("Method " + method + " doesn't belong to class " + clazz);
+        }
+        return validateParameters(methodDescriptor.getMetaBean(), methodDescriptor.getParameterDescriptors(),
+            parameters, groupArray);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz, Method method, Object parameter,
+        int parameterIndex, Class<?>... groupArray) {
+        MethodBeanDescriptorImpl beanDesc = (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
+        MethodDescriptorImpl methodDescriptor = (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
+        if (methodDescriptor == null) {
+            throw new ValidationException("Method " + method + " doesn't belong to class " + clazz);
+        }
+        ParameterDescriptorImpl paramDesc =
+            (ParameterDescriptorImpl) methodDescriptor.getParameterDescriptors().get(parameterIndex);
+        return validateParameter(paramDesc, parameter, groupArray);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public <T> Set<ConstraintViolation<T>> validateParameters(Class<T> clazz, Constructor<T> constructor,
+        Object[] parameters, Class<?>... groupArray) {
+        MethodBeanDescriptorImpl beanDesc = (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
+        ConstructorDescriptorImpl constructorDescriptor =
+            (ConstructorDescriptorImpl) beanDesc.getConstraintsForConstructor(constructor);
+        if (constructorDescriptor == null) {
+            throw new ValidationException("Constructor " + constructor + " doesn't belong to class " + clazz);
+        }
+        return validateParameters(constructorDescriptor.getMetaBean(), constructorDescriptor.getParameterDescriptors(),
+            parameters, groupArray);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz, Constructor<T> constructor,
+        Object parameter, int parameterIndex, Class<?>... groupArray) {
+        MethodBeanDescriptorImpl beanDesc = (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
+        ConstructorDescriptorImpl constructorDescriptor =
+            (ConstructorDescriptorImpl) beanDesc.getConstraintsForConstructor(constructor);
+        if (constructorDescriptor == null) {
+            throw new ValidationException("Constructor " + constructor + " doesn't belong to class " + clazz);
+        }
+        ParameterDescriptorImpl paramDesc =
+            (ParameterDescriptorImpl) constructorDescriptor.getParameterDescriptors().get(parameterIndex);
+        return validateParameter(paramDesc, parameter, groupArray);
+    }
+
+    /**
+     * {@inheritDoc} If @Valid is placed on the method, the constraints declared
+     * on the object itself are considered.
+     */
+    @SuppressWarnings("unchecked")
+    public <T> Set<ConstraintViolation<T>> validateReturnedValue(Class<T> clazz, Method method, Object returnedValue,
+        Class<?>... groupArray) {
+        MethodBeanDescriptorImpl beanDesc = (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
+        MethodDescriptorImpl methodDescriptor = (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
+        if (methodDescriptor == null) {
+            throw new ValidationException("Method " + method + " doesn't belong to class " + clazz);
+        }
+        final GroupValidationContext<Object> context =
+            createContext(methodDescriptor.getMetaBean(), returnedValue, null, groupArray);
+        validateReturnedValueInContext(context, methodDescriptor);
         ConstraintValidationListener<T> result = (ConstraintValidationListener<T>) context.getListener();
         return result.getConstraintViolations();
-      } catch (RuntimeException ex) {
-        throw unrecoverableValidationError(ex, parameters);
-      }
-    } else {
-      return Collections.<ConstraintViolation<T>> emptySet();
-    }
-  }
-
-  @SuppressWarnings("unchecked")
-  private <T> Set<ConstraintViolation<T>> validateParameter(
-      ParameterDescriptorImpl paramDesc, Object parameter, Class<?>... groupArray) {
-    try {
-      final GroupValidationContext<Object> context =
-          createContext(paramDesc.getMetaBean(), parameter, null, groupArray);
-      final ConstraintValidationListener<T> result = (ConstraintValidationListener<T>) context.getListener();
-      validateParameterInContext(context, paramDesc);
-      return result.getConstraintViolations();
-    } catch (RuntimeException ex) {
-      throw unrecoverableValidationError(ex, parameter);
-    }
-  }
-
-  /**
-   * validate constraints hosted on parameters of a method
-   */
-  private <T> void validateParameterInContext(
-      GroupValidationContext<T> context,
-      ParameterDescriptorImpl paramDesc) {
-
-    final Groups groups = context.getGroups();
-
-    for (ConstraintDescriptor<?> consDesc : paramDesc.getConstraintDescriptors()) {
-      ConstraintValidation<?> validation = (ConstraintValidation<?>) consDesc;
-      // 1. process groups
-      for (Group current : groups.getGroups()) {
-        context.setCurrentGroup(current);
-        validation.validate(context);
-      }
-      // 2. process sequences
-      for (List<Group> eachSeq : groups.getSequences()) {
-        for (Group current : eachSeq) {
-          context.setCurrentGroup(current);
-          validation.validate(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()) break;
-        }
-      }
-    }
-    if (paramDesc.isCascaded() && context.getValidatedValue() != null) {
-      context.setMetaBean(factoryContext.getMetaBeanFinder().
-          findForClass(context.getValidatedValue().getClass()));
-      // 1. process groups
-      for (Group current : groups.getGroups()) {
-        context.setCurrentGroup(current);
-        ValidationHelper.validateContext(context, new Jsr303ValidationCallback(context), isTreatMapsLikeBeans());
-      }
-      // 2. process sequences
-      for (List<Group> eachSeq : groups.getSequences()) {
-        for (Group current : eachSeq) {
-          context.setCurrentGroup(current);
-          ValidationHelper.validateContext(context, new Jsr303ValidationCallback(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()) break;
-        }
-      }
-    }
-  }
-
-  /**
-   * validate constraints hosted on parameters of a method
-   */
-  private <T> void validateReturnedValueInContext(
-      GroupValidationContext<T> context,
-      MethodDescriptorImpl methodDescriptor) {
-
-    final Groups groups = context.getGroups();
-
-    for (ConstraintDescriptor<?> consDesc : methodDescriptor.getConstraintDescriptors()) {
-      ConstraintValidation<?> validation = (ConstraintValidation<?>) consDesc;
-      // 1. process groups
-      for (Group current : groups.getGroups()) {
-        context.setCurrentGroup(current);
-        validation.validate(context);
-      }
-      // 2. process sequences
-      for (List<Group> eachSeq : groups.getSequences()) {
-        for (Group current : eachSeq) {
-          context.setCurrentGroup(current);
-          validation.validate(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()) break;
-        }
-      }
-    }
-    if (methodDescriptor.isCascaded() && context.getValidatedValue() != null) {
-      context.setMetaBean(factoryContext.getMetaBeanFinder().
-          findForClass(context.getValidatedValue().getClass()));
-      // 1. process groups
-      for (Group current : groups.getGroups()) {
-        context.setCurrentGroup(current);
-        ValidationHelper.validateContext(context, new Jsr303ValidationCallback(context), isTreatMapsLikeBeans());
-      }
-      // 2. process sequences
-      for (List<Group> eachSeq : groups.getSequences()) {
-        for (Group current : eachSeq) {
-          context.setCurrentGroup(current);
-          ValidationHelper.validateContext(context, new Jsr303ValidationCallback(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()) break;
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> Set<ConstraintViolation<T>> validateParameters(MetaBean metaBean,
+        List<ParameterDescriptor> paramDescriptors, Object[] parameters, Class<?>... groupArray) {
+        if (parameters == null)
+            throw new IllegalArgumentException("cannot validate null");
+        if (parameters.length > 0) {
+            try {
+                GroupValidationContext<ConstraintValidationListener<Object[]>> context =
+                    createContext(metaBean, null, null, groupArray);
+                for (int i = 0; i < parameters.length; i++) {
+                    ParameterDescriptorImpl paramDesc = (ParameterDescriptorImpl) paramDescriptors.get(i);
+                    context.setBean(parameters[i]);
+                    validateParameterInContext(context, paramDesc);
+                }
+                ConstraintValidationListener<T> result = (ConstraintValidationListener<T>) context.getListener();
+                return result.getConstraintViolations();
+            } catch (RuntimeException ex) {
+                throw unrecoverableValidationError(ex, parameters);
+            }
+        } else {
+            return Collections.<ConstraintViolation<T>> emptySet();
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> Set<ConstraintViolation<T>> validateParameter(ParameterDescriptorImpl paramDesc, Object parameter,
+        Class<?>... groupArray) {
+        try {
+            final GroupValidationContext<Object> context =
+                createContext(paramDesc.getMetaBean(), parameter, null, groupArray);
+            final ConstraintValidationListener<T> result = (ConstraintValidationListener<T>) context.getListener();
+            validateParameterInContext(context, paramDesc);
+            return result.getConstraintViolations();
+        } catch (RuntimeException ex) {
+            throw unrecoverableValidationError(ex, parameter);
+        }
+    }
+
+    /**
+     * validate constraints hosted on parameters of a method
+     */
+    private <T> void validateParameterInContext(GroupValidationContext<T> context, ParameterDescriptorImpl paramDesc) {
+
+        final Groups groups = context.getGroups();
+
+        for (ConstraintDescriptor<?> consDesc : paramDesc.getConstraintDescriptors()) {
+            ConstraintValidation<?> validation = (ConstraintValidation<?>) consDesc;
+            // 1. process groups
+            for (Group current : groups.getGroups()) {
+                context.setCurrentGroup(current);
+                validation.validate(context);
+            }
+            // 2. process sequences
+            for (List<Group> eachSeq : groups.getSequences()) {
+                for (Group current : eachSeq) {
+                    context.setCurrentGroup(current);
+                    validation.validate(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())
+                        break;
+                }
+            }
+        }
+        if (paramDesc.isCascaded() && context.getValidatedValue() != null) {
+            context
+                .setMetaBean(factoryContext.getMetaBeanFinder().findForClass(context.getValidatedValue().getClass()));
+            // 1. process groups
+            for (Group current : groups.getGroups()) {
+                context.setCurrentGroup(current);
+                ValidationHelper
+                    .validateContext(context, new Jsr303ValidationCallback(context), isTreatMapsLikeBeans());
+            }
+            // 2. process sequences
+            for (List<Group> eachSeq : groups.getSequences()) {
+                for (Group current : eachSeq) {
+                    context.setCurrentGroup(current);
+                    ValidationHelper.validateContext(context, new Jsr303ValidationCallback(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())
+                        break;
+                }
+            }
+        }
+    }
+
+    /**
+     * validate constraints hosted on parameters of a method
+     */
+    private <T> void validateReturnedValueInContext(GroupValidationContext<T> context,
+        MethodDescriptorImpl methodDescriptor) {
+
+        final Groups groups = context.getGroups();
+
+        for (ConstraintDescriptor<?> consDesc : methodDescriptor.getConstraintDescriptors()) {
+            ConstraintValidation<?> validation = (ConstraintValidation<?>) consDesc;
+            // 1. process groups
+            for (Group current : groups.getGroups()) {
+                context.setCurrentGroup(current);
+                validation.validate(context);
+            }
+            // 2. process sequences
+            for (List<Group> eachSeq : groups.getSequences()) {
+                for (Group current : eachSeq) {
+                    context.setCurrentGroup(current);
+                    validation.validate(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())
+                        break;
+                }
+            }
+        }
+        if (methodDescriptor.isCascaded() && context.getValidatedValue() != null) {
+            context
+                .setMetaBean(factoryContext.getMetaBeanFinder().findForClass(context.getValidatedValue().getClass()));
+            // 1. process groups
+            for (Group current : groups.getGroups()) {
+                context.setCurrentGroup(current);
+                ValidationHelper
+                    .validateContext(context, new Jsr303ValidationCallback(context), isTreatMapsLikeBeans());
+            }
+            // 2. process sequences
+            for (List<Group> eachSeq : groups.getSequences()) {
+                for (Group current : eachSeq) {
+                    context.setCurrentGroup(current);
+                    ValidationHelper.validateContext(context, new Jsr303ValidationCallback(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())
+                        break;
+                }
+            }
         }
-      }
     }
-  }
 }

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=992420&r1=992419&r2=992420&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 Fri Sep  3 19:02:18 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.bval.jsr303.extensions;
 
-
 import org.apache.bval.jsr303.ApacheFactoryContext;
 import org.apache.bval.jsr303.AppendValidation;
 import org.apache.bval.jsr303.Jsr303MetaBeanFactory;
@@ -35,145 +34,142 @@ import java.lang.reflect.Method;
 import java.util.HashMap;
 
 /**
- * Description: extension to validate parameters/return values of methods/constructors.<br/>
+ * Description: extension to validate parameters/return values of
+ * methods/constructors.<br/>
  */
-//TODO RSt - move. this is an optional module: move the whole package. core code has no dependencies on it 
+// TODO RSt - move. this is an optional module: move the whole package. core
+// code has no dependencies on it
 public class MethodValidatorMetaBeanFactory extends Jsr303MetaBeanFactory {
-  /**
-   * Create a new MethodValidatorMetaBeanFactory instance.
-   * @param factoryContext
-   */
-  public MethodValidatorMetaBeanFactory(ApacheFactoryContext factoryContext) {
-    super(factoryContext);
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override
-  protected boolean hasValidationConstraintsDefined(Method method) {
-    return false;
-  }
-
-  /**
-   * Finish building the specified {@link MethodBeanDescriptorImpl}.
-   * @param descriptor
-   */
-  public void buildMethodDescriptor(MethodBeanDescriptorImpl descriptor) {
-    try {
-      buildMethodConstraints(descriptor);
-      buildConstructorConstraints(descriptor);
-    } catch (Exception e) {
-      throw new IllegalArgumentException(e.getMessage(), e);
-    }
-  }
-
-  private void buildConstructorConstraints(MethodBeanDescriptorImpl beanDesc)
-      throws InvocationTargetException, IllegalAccessException {
-    beanDesc.setConstructorConstraints(new HashMap<Constructor<?>, ConstructorDescriptor>());
-
-    for (Constructor<?> cons : beanDesc.getMetaBean().getBeanClass()
-        .getDeclaredConstructors()) {
-      if (!factoryContext.getFactory().getAnnotationIgnores()
-          .isIgnoreAnnotations(cons)) {
-
-        ConstructorDescriptorImpl consDesc =
-            new ConstructorDescriptorImpl(beanDesc.getMetaBean(), new Validation[0]);
-        beanDesc.putConstructorDescriptor(cons, consDesc);
-
-        Annotation[][] paramsAnnos = cons.getParameterAnnotations();
-        int idx = 0;
-        for (Annotation[] paramAnnos : paramsAnnos) {
-          ParameterAccess access = new ParameterAccess(cons.getParameterTypes()[idx], idx);
-          processAnnotations(consDesc, paramAnnos, access, idx);
-          idx++;
-        }
-      }
+    /**
+     * Create a new MethodValidatorMetaBeanFactory instance.
+     * 
+     * @param factoryContext
+     */
+    public MethodValidatorMetaBeanFactory(ApacheFactoryContext factoryContext) {
+        super(factoryContext);
     }
-  }
-
-  private void buildMethodConstraints(MethodBeanDescriptorImpl beanDesc)
-      throws InvocationTargetException, IllegalAccessException {
-    beanDesc.setMethodConstraints(new HashMap<Method, MethodDescriptor>());
 
-    for (Method method : beanDesc.getMetaBean().getBeanClass().getDeclaredMethods()) {
-      if (!factoryContext.getFactory().getAnnotationIgnores()
-          .isIgnoreAnnotations(method)) {
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected boolean hasValidationConstraintsDefined(Method method) {
+        return false;
+    }
 
+    /**
+     * Finish building the specified {@link MethodBeanDescriptorImpl}.
+     * 
+     * @param descriptor
+     */
+    public void buildMethodDescriptor(MethodBeanDescriptorImpl descriptor) {
+        try {
+            buildMethodConstraints(descriptor);
+            buildConstructorConstraints(descriptor);
+        } catch (Exception e) {
+            throw new IllegalArgumentException(e.getMessage(), e);
+        }
+    }
 
-        MethodDescriptorImpl methodDesc = new MethodDescriptorImpl(
-            beanDesc.getMetaBean(), new Validation[0]);
-        beanDesc.putMethodDescriptor(method, methodDesc);
+    private void buildConstructorConstraints(MethodBeanDescriptorImpl beanDesc) throws InvocationTargetException,
+        IllegalAccessException {
+        beanDesc.setConstructorConstraints(new HashMap<Constructor<?>, ConstructorDescriptor>());
+
+        for (Constructor<?> cons : beanDesc.getMetaBean().getBeanClass().getDeclaredConstructors()) {
+            if (!factoryContext.getFactory().getAnnotationIgnores().isIgnoreAnnotations(cons)) {
+
+                ConstructorDescriptorImpl consDesc =
+                    new ConstructorDescriptorImpl(beanDesc.getMetaBean(), new Validation[0]);
+                beanDesc.putConstructorDescriptor(cons, consDesc);
+
+                Annotation[][] paramsAnnos = cons.getParameterAnnotations();
+                int idx = 0;
+                for (Annotation[] paramAnnos : paramsAnnos) {
+                    ParameterAccess access = new ParameterAccess(cons.getParameterTypes()[idx], idx);
+                    processAnnotations(consDesc, paramAnnos, access, idx);
+                    idx++;
+                }
+            }
+        }
+    }
 
-        // return value validations
-        AppendValidationToList validations = new AppendValidationToList();
-        ReturnAccess returnAccess = new ReturnAccess(method.getReturnType());
-        for (Annotation anno : method.getAnnotations()) {
-          if (anno instanceof Valid) {
-            methodDesc.setCascaded(true);
-          } else {
-            processAnnotation(anno, methodDesc, returnAccess, validations);
-          }
+    private void buildMethodConstraints(MethodBeanDescriptorImpl beanDesc) throws InvocationTargetException,
+        IllegalAccessException {
+        beanDesc.setMethodConstraints(new HashMap<Method, MethodDescriptor>());
+
+        for (Method method : beanDesc.getMetaBean().getBeanClass().getDeclaredMethods()) {
+            if (!factoryContext.getFactory().getAnnotationIgnores().isIgnoreAnnotations(method)) {
+
+                MethodDescriptorImpl methodDesc = new MethodDescriptorImpl(beanDesc.getMetaBean(), new Validation[0]);
+                beanDesc.putMethodDescriptor(method, methodDesc);
+
+                // return value validations
+                AppendValidationToList validations = new AppendValidationToList();
+                ReturnAccess returnAccess = new ReturnAccess(method.getReturnType());
+                for (Annotation anno : method.getAnnotations()) {
+                    if (anno instanceof Valid) {
+                        methodDesc.setCascaded(true);
+                    } else {
+                        processAnnotation(anno, methodDesc, returnAccess, validations);
+                    }
+                }
+                methodDesc.getConstraintDescriptors().addAll(validations.getValidations());
+
+                // parameter validations
+                Annotation[][] paramsAnnos = method.getParameterAnnotations();
+                int idx = 0;
+                for (Annotation[] paramAnnos : paramsAnnos) {
+                    ParameterAccess access = new ParameterAccess(method.getParameterTypes()[idx], idx);
+                    processAnnotations(methodDesc, paramAnnos, access, idx);
+                    idx++;
+                }
+            }
         }
-        methodDesc.getConstraintDescriptors().addAll(validations.getValidations());
+    }
 
-        // parameter validations
-        Annotation[][] paramsAnnos = method.getParameterAnnotations();
-        int idx = 0;
-        for (Annotation[] paramAnnos : paramsAnnos) {
-          ParameterAccess access = new ParameterAccess(method.getParameterTypes()[idx], idx);
-          processAnnotations(methodDesc, paramAnnos, access, idx);
-          idx++;
+    private void processAnnotations(ProcedureDescriptor methodDesc, Annotation[] paramAnnos, AccessStrategy access,
+        int idx) throws InvocationTargetException, IllegalAccessException {
+        AppendValidationToList validations = new AppendValidationToList();
+        boolean cascaded = false;
+        for (Annotation anno : paramAnnos) {
+            if (anno instanceof Valid) {
+                cascaded = true;
+            } else {
+                processAnnotation(anno, methodDesc, access, validations);
+            }
         }
-      }
+        ParameterDescriptorImpl paramDesc =
+            new ParameterDescriptorImpl(methodDesc.getMetaBean(), validations.getValidations().toArray(
+                new Validation[validations.getValidations().size()]));
+        paramDesc.setIndex(idx);
+        paramDesc.setCascaded(cascaded);
+        methodDesc.getParameterDescriptors().add(paramDesc);
     }
-  }
 
-  private void processAnnotations(ProcedureDescriptor methodDesc, Annotation[] paramAnnos,
-                                  AccessStrategy access, int idx)
-      throws InvocationTargetException, IllegalAccessException {
-    AppendValidationToList validations = new AppendValidationToList();
-    boolean cascaded = false;
-    for (Annotation anno : paramAnnos) {
-      if (anno instanceof Valid) {
-        cascaded = true;
-      } else {
-        processAnnotation(anno, methodDesc, access, validations);
-      }
-    }
-    ParameterDescriptorImpl paramDesc = new ParameterDescriptorImpl(
-        methodDesc.getMetaBean(), validations.getValidations().toArray(
-            new Validation[validations.getValidations().size()]));
-    paramDesc.setIndex(idx);
-    paramDesc.setCascaded( cascaded );
-    methodDesc.getParameterDescriptors().add(paramDesc);
-  }
-
-  private <A extends Annotation> void processAnnotation(A annotation, ProcedureDescriptor desc,
-                                 AccessStrategy access, AppendValidation validations)
-      throws InvocationTargetException, IllegalAccessException {
-
-    if (annotation instanceof Valid) {
-      desc.setCascaded(true);
-    } else {
-      Constraint vcAnno = annotation.annotationType().getAnnotation(Constraint.class);
-      if (vcAnno != null) {
-        Class<? extends ConstraintValidator<A, ?>>[] validatorClasses;
-        validatorClasses = findConstraintValidatorClasses(annotation, vcAnno);
-        applyConstraint(annotation, validatorClasses, null,
-            ClassUtils.primitiveToWrapper((Class<?>) access.getJavaType()), access, validations);
-      } else {
-        /**
-         * Multi-valued constraints
-         */
-        Object result = SecureActions.getAnnotationValue(annotation, ANNOTATION_VALUE);
-        if (result != null && result instanceof Annotation[]) {
-          for (Annotation each : (Annotation[]) result) {
-            processAnnotation(each, desc, access, validations); // recursion
-          }
+    private <A extends Annotation> void processAnnotation(A annotation, ProcedureDescriptor desc,
+        AccessStrategy access, AppendValidation validations) throws InvocationTargetException, IllegalAccessException {
+
+        if (annotation instanceof Valid) {
+            desc.setCascaded(true);
+        } else {
+            Constraint vcAnno = annotation.annotationType().getAnnotation(Constraint.class);
+            if (vcAnno != null) {
+                Class<? extends ConstraintValidator<A, ?>>[] validatorClasses;
+                validatorClasses = findConstraintValidatorClasses(annotation, vcAnno);
+                applyConstraint(annotation, validatorClasses, null, ClassUtils.primitiveToWrapper((Class<?>) access
+                    .getJavaType()), access, validations);
+            } else {
+                /**
+                 * Multi-valued constraints
+                 */
+                Object result = SecureActions.getAnnotationValue(annotation, ANNOTATION_VALUE);
+                if (result != null && result instanceof Annotation[]) {
+                    for (Annotation each : (Annotation[]) result) {
+                        processAnnotation(each, desc, access, validations); // recursion
+                    }
+                }
+            }
         }
-      }
     }
-  }
 
 }

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/DecimalMinMaxValidatorsTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/DecimalMinMaxValidatorsTest.java?rev=992420&r1=992419&r2=992420&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/DecimalMinMaxValidatorsTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/DecimalMinMaxValidatorsTest.java Fri Sep  3 19:02:18 2010
@@ -35,31 +35,29 @@ import java.util.Set;
  */
 public class DecimalMinMaxValidatorsTest extends TestCase {
 
-  @DecimalMin("922392239223.06")
-  public double dmin;
-  @DecimalMax("922392239223.09")
-  public double dmax;
-
-
-  public void testDecimalMinValue() {
-    Validator v = Validation.buildDefaultValidatorFactory().getValidator();
-
-    this.dmin = 922392239223.05;
-    this.dmax = 922392239223.08;
-
-    Set<ConstraintViolation<DecimalMinMaxValidatorsTest>> res = v.validate(this);
-    assertFalse("Min validation failed", res.isEmpty());
-  }
-
-  public void testDecimalMaxValue() {
-    Validator v = Validation.buildDefaultValidatorFactory().getValidator();
-
-    this.dmin = Double.MAX_VALUE;
-    this.dmax = 922392239223.1;
-
-    Set<ConstraintViolation<DecimalMinMaxValidatorsTest>> res = v.validate(this);
-    assertFalse("Max validation failed", res.isEmpty());
-  }
-
+    @DecimalMin("922392239223.06")
+    public double dmin;
+    @DecimalMax("922392239223.09")
+    public double dmax;
+
+    public void testDecimalMinValue() {
+        Validator v = Validation.buildDefaultValidatorFactory().getValidator();
+
+        this.dmin = 922392239223.05;
+        this.dmax = 922392239223.08;
+
+        Set<ConstraintViolation<DecimalMinMaxValidatorsTest>> res = v.validate(this);
+        assertFalse("Min validation failed", res.isEmpty());
+    }
+
+    public void testDecimalMaxValue() {
+        Validator v = Validation.buildDefaultValidatorFactory().getValidator();
+
+        this.dmin = Double.MAX_VALUE;
+        this.dmax = 922392239223.1;
+
+        Set<ConstraintViolation<DecimalMinMaxValidatorsTest>> res = v.validate(this);
+        assertFalse("Max validation failed", res.isEmpty());
+    }
 
 }

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/MinMaxValidatorsForNumberTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/MinMaxValidatorsForNumberTest.java?rev=992420&r1=992419&r2=992420&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/MinMaxValidatorsForNumberTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/constraints/MinMaxValidatorsForNumberTest.java Fri Sep  3 19:02:18 2010
@@ -27,46 +27,43 @@ import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import java.util.Set;
 
-
 /**
  * Check correct behaviour of {@link MinValidatorForNumber} and
  * {@link MaxValidatorForNumber} on boundary values.
  * <p/>
- * The chosen numbers: 9223372036854775806l and 9223372036854775807l cast to
- * the same double value.
- *
+ * The chosen numbers: 9223372036854775806l and 9223372036854775807l cast to the
+ * same double value.
+ * 
  * @author Carlos Vara
  */
 public class MinMaxValidatorsForNumberTest extends TestCase {
 
-  @Min(value = 9223372036854775807l)
-  public long min;
-
-  @Max(value = 9223372036854775806l)
-  public long max;
-
+    @Min(value = 9223372036854775807l)
+    public long min;
 
-  public void testMinBoundaryValue() {
-    Validator v = Validation.buildDefaultValidatorFactory().getValidator();
+    @Max(value = 9223372036854775806l)
+    public long max;
 
-    this.min = 9223372036854775806l;
-    this.max = 0l;
+    public void testMinBoundaryValue() {
+        Validator v = Validation.buildDefaultValidatorFactory().getValidator();
 
-    // Current min value is smaller, should fail, but it doesn't
-    Set<ConstraintViolation<MinMaxValidatorsForNumberTest>> res = v.validate(this);
-    assertFalse("Min validation failed", res.isEmpty());
-  }
+        this.min = 9223372036854775806l;
+        this.max = 0l;
 
-  public void testMaxBoundaryValue() {
-    Validator v = Validation.buildDefaultValidatorFactory().getValidator();
+        // Current min value is smaller, should fail, but it doesn't
+        Set<ConstraintViolation<MinMaxValidatorsForNumberTest>> res = v.validate(this);
+        assertFalse("Min validation failed", res.isEmpty());
+    }
 
-    this.min = Long.MAX_VALUE;
-    this.max = 9223372036854775807l;
+    public void testMaxBoundaryValue() {
+        Validator v = Validation.buildDefaultValidatorFactory().getValidator();
 
-    // Current max value is bigger, should fail, but it doesn't
-    Set<ConstraintViolation<MinMaxValidatorsForNumberTest>> res = v.validate(this);
-    assertFalse("Max validation failed", res.isEmpty());
-  }
+        this.min = Long.MAX_VALUE;
+        this.max = 9223372036854775807l;
 
+        // Current max value is bigger, should fail, but it doesn't
+        Set<ConstraintViolation<MinMaxValidatorsForNumberTest>> res = v.validate(this);
+        assertFalse("Max validation failed", res.isEmpty());
+    }
 
 }

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java?rev=992420&r1=992419&r2=992420&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/DefaultMessageInterpolatorTest.java Fri Sep  3 19:02:18 2010
@@ -34,71 +34,65 @@ import java.util.Locale;
  */
 public class DefaultMessageInterpolatorTest extends TestCase {
 
-  private DefaultMessageInterpolator interpolator;
+    private DefaultMessageInterpolator interpolator;
 
-  public DefaultMessageInterpolatorTest(String name) {
-    super(name);
-  }
-
-  public static Test suite() {
-    return new TestSuite(DefaultMessageInterpolatorTest.class);
-  }
-
-  @Override
-  protected void setUp() throws Exception {
-    super.setUp();    // call super!
-    interpolator = new DefaultMessageInterpolator();
-    interpolator.setLocale(Locale.ENGLISH);
-  }
-
-  public void testCreateResolver() {
-
-    final Validator gvalidator = getValidator();
-
-    assertTrue(!gvalidator.getConstraintsForClass(PreferredGuest.class)
-        .getConstraintsForProperty("guestCreditCardNumber")
-        .getConstraintDescriptors().isEmpty());
-
-    MessageInterpolator.Context ctx = new MessageInterpolator.Context() {
-
-      public ConstraintDescriptor<?> getConstraintDescriptor() {
-        return (ConstraintDescriptor<?>) gvalidator
-            .getConstraintsForClass(PreferredGuest.class).
-                getConstraintsForProperty("guestCreditCardNumber")
-            .getConstraintDescriptors().toArray()[0];
-      }
-
-      public Object getValidatedValue() {
-        return "12345678";
-      }
-    };
-    String msg = interpolator.interpolate("{validator.creditcard}", ctx);
-    Assert.assertEquals("credit card is not valid", msg);
-
-    ctx = new MessageInterpolator.Context() {
-      public ConstraintDescriptor<?> getConstraintDescriptor() {
-        return (ConstraintDescriptor) gvalidator
-            .getConstraintsForClass(Author.class).
-                getConstraintsForProperty("lastName")
-            .getConstraintDescriptors().toArray()[0];
-      }
-
-      public Object getValidatedValue() {
-        return "";
-      }
-    };
-
-
-    msg = interpolator.interpolate("{org.apache.bval.constraints.NotEmpty.message}", ctx);
-    Assert.assertEquals("may not be empty", msg);
-  }
+    public DefaultMessageInterpolatorTest(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        return new TestSuite(DefaultMessageInterpolatorTest.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp(); // call super!
+        interpolator = new DefaultMessageInterpolator();
+        interpolator.setLocale(Locale.ENGLISH);
+    }
+
+    public void testCreateResolver() {
+
+        final Validator gvalidator = getValidator();
+
+        assertTrue(!gvalidator.getConstraintsForClass(PreferredGuest.class).getConstraintsForProperty(
+            "guestCreditCardNumber").getConstraintDescriptors().isEmpty());
+
+        MessageInterpolator.Context ctx = new MessageInterpolator.Context() {
+
+            public ConstraintDescriptor<?> getConstraintDescriptor() {
+                return (ConstraintDescriptor<?>) gvalidator.getConstraintsForClass(PreferredGuest.class)
+                    .getConstraintsForProperty("guestCreditCardNumber").getConstraintDescriptors().toArray()[0];
+            }
+
+            public Object getValidatedValue() {
+                return "12345678";
+            }
+        };
+        String msg = interpolator.interpolate("{validator.creditcard}", ctx);
+        Assert.assertEquals("credit card is not valid", msg);
+
+        ctx = new MessageInterpolator.Context() {
+            public ConstraintDescriptor<?> getConstraintDescriptor() {
+                return (ConstraintDescriptor) gvalidator.getConstraintsForClass(Author.class)
+                    .getConstraintsForProperty("lastName").getConstraintDescriptors().toArray()[0];
+            }
+
+            public Object getValidatedValue() {
+                return "";
+            }
+        };
+
+        msg = interpolator.interpolate("{org.apache.bval.constraints.NotEmpty.message}", ctx);
+        Assert.assertEquals("may not be empty", msg);
+    }
 
     /**
      * Checks that strings containing special characters are correctly
      * substituted when interpolating.
      */
     public void testReplacementWithSpecialChars() {
-        
+
         final Validator validator = getValidator();
         MessageInterpolator.Context ctx;
 
@@ -106,10 +100,8 @@ public class DefaultMessageInterpolatorT
         ctx = new MessageInterpolator.Context() {
 
             public ConstraintDescriptor<?> getConstraintDescriptor() {
-                return (ConstraintDescriptor<?>) validator
-                        .getConstraintsForClass(Person.class)
-                        .getConstraintsForProperty("idNumber")
-                        .getConstraintDescriptors().toArray()[0];
+                return (ConstraintDescriptor<?>) validator.getConstraintsForClass(Person.class)
+                    .getConstraintsForProperty("idNumber").getConstraintDescriptors().toArray()[0];
             }
 
             public Object getValidatedValue() {
@@ -118,28 +110,28 @@ public class DefaultMessageInterpolatorT
         };
 
         String result = this.interpolator.interpolate("Id number should match {regexp}", ctx);
-        Assert.assertEquals("Incorrect message interpolation when $ is in an attribute", "Id number should match ....$", result);
-        
+        Assert.assertEquals("Incorrect message interpolation when $ is in an attribute",
+            "Id number should match ....$", result);
+
         // Try to interpolate an annotation attribute containing \
         ctx = new MessageInterpolator.Context() {
 
             public ConstraintDescriptor<?> getConstraintDescriptor() {
-                return (ConstraintDescriptor<?>) validator
-                        .getConstraintsForClass(Person.class)
-                        .getConstraintsForProperty("otherId")
-                        .getConstraintDescriptors().toArray()[0];
+                return (ConstraintDescriptor<?>) validator.getConstraintsForClass(Person.class)
+                    .getConstraintsForProperty("otherId").getConstraintDescriptors().toArray()[0];
             }
 
             public Object getValidatedValue() {
                 return "12345678";
             }
         };
-        
+
         result = this.interpolator.interpolate("Other id should match {regexp}", ctx);
-        Assert.assertEquals("Incorrect message interpolation when \\ is in an attribute value", "Other id should match .\\n", result);
-        
+        Assert.assertEquals("Incorrect message interpolation when \\ is in an attribute value",
+            "Other id should match .\\n", result);
+
     }
-    
+
     public static class Person {
 
         @Pattern(message = "Id number should match {regexp}", regexp = "....$")
@@ -150,8 +142,7 @@ public class DefaultMessageInterpolatorT
 
     }
 
-
-  private Validator getValidator() {
-    return ApacheValidatorFactory.getDefault().getValidator();
-  }
+    private Validator getValidator() {
+        return ApacheValidatorFactory.getDefault().getValidator();
+    }
 }

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java?rev=992420&r1=992419&r2=992420&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/TckReproducerTest.java Fri Sep  3 19:02:18 2010
@@ -35,55 +35,53 @@ import java.util.Set;
  */
 public class TckReproducerTest extends TestCase {
 
-  public static <T> void assertCorrectNumberOfViolations(Set<ConstraintViolation<T>> violations,
-                                                         int expectedViolations) {
-    assertEquals(
-        "Wrong number of constraint violations. Expected: " + expectedViolations + " Actual: " + violations.size(),
-        expectedViolations, violations.size());
-  }
-
-  private Validator getValidator() {
-    return ApacheValidatorFactory.getDefault().getValidator();
-  }
-
-  public void testPropertyAccessOnNonPublicClass()
-      throws Exception {
-    Validator validator = getValidator();
-    Car car = new Car("USd-298");
-    assertEquals(car.getLicensePlateNumber(), PropertyAccess.getProperty(car, "licensePlateNumber"));
-
-    Set<ConstraintViolation<Car>> violations = validator.validateProperty(
-        car, "licensePlateNumber", First.class, org.apache.bval.jsr303.example.Second.class
-    );
-    assertCorrectNumberOfViolations(violations, 1);
-
-    car.setLicensePlateNumber("USD-298");
-    violations = validator.validateProperty(
-        car, "licensePlateNumber", First.class, org.apache.bval.jsr303.example.Second.class
-    );
-    assertCorrectNumberOfViolations(violations, 0);
-  }
-
-  class Car {
-    @Pattern(regexp = "[A-Z][A-Z][A-Z]-[0-9][0-9][0-9]", groups = {First.class, Second.class})
-    private String licensePlateNumber;
+    public static <T> void assertCorrectNumberOfViolations(Set<ConstraintViolation<T>> violations,
+        int expectedViolations) {
+        assertEquals("Wrong number of constraint violations. Expected: " + expectedViolations + " Actual: "
+            + violations.size(), expectedViolations, violations.size());
+    }
 
-    Car(String licensePlateNumber) {
-      this.licensePlateNumber = licensePlateNumber;
+    private Validator getValidator() {
+        return ApacheValidatorFactory.getDefault().getValidator();
     }
 
-    public String getLicensePlateNumber() {
-      return licensePlateNumber;
+    public void testPropertyAccessOnNonPublicClass() throws Exception {
+        Validator validator = getValidator();
+        Car car = new Car("USd-298");
+        assertEquals(car.getLicensePlateNumber(), PropertyAccess.getProperty(car, "licensePlateNumber"));
+
+        Set<ConstraintViolation<Car>> violations =
+            validator.validateProperty(car, "licensePlateNumber", First.class,
+                org.apache.bval.jsr303.example.Second.class);
+        assertCorrectNumberOfViolations(violations, 1);
+
+        car.setLicensePlateNumber("USD-298");
+        violations =
+            validator.validateProperty(car, "licensePlateNumber", First.class,
+                org.apache.bval.jsr303.example.Second.class);
+        assertCorrectNumberOfViolations(violations, 0);
     }
 
-    public void setLicensePlateNumber(String licensePlateNumber) {
-      this.licensePlateNumber = licensePlateNumber;
+    class Car {
+        @Pattern(regexp = "[A-Z][A-Z][A-Z]-[0-9][0-9][0-9]", groups = { First.class, Second.class })
+        private String licensePlateNumber;
+
+        Car(String licensePlateNumber) {
+            this.licensePlateNumber = licensePlateNumber;
+        }
+
+        public String getLicensePlateNumber() {
+            return licensePlateNumber;
+        }
+
+        public void setLicensePlateNumber(String licensePlateNumber) {
+            this.licensePlateNumber = licensePlateNumber;
+        }
     }
-  }
 
-  interface First {
-  }
+    interface First {
+    }
 
-  interface Second {
-  }
+    interface Second {
+    }
 }



Mime
View raw message