incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1000639 - /incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
Date Thu, 23 Sep 2010 21:32:08 GMT
Author: mbenson
Date: Thu Sep 23 21:32:08 2010
New Revision: 1000639

URL: http://svn.apache.org/viewvc?rev=1000639&view=rev
Log:
missed format merge

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java?rev=1000639&r1=1000638&r2=1000639&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
Thu Sep 23 21:32:08 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;
@@ -34,143 +33,140 @@ 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.addValidations(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.addValidations(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) {
-        annotationProcessor.processAnnotation(annotation, 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) {
+                annotationProcessor.processAnnotation(annotation, 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
+                    }
+                }
+            }
         }
-      }
     }
-  }
 
 }



Mime
View raw message