bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r993586 - /incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java
Date Wed, 08 Sep 2010 02:34:25 GMT
Author: mbenson
Date: Wed Sep  8 02:34:25 2010
New Revision: 993586

URL: http://svn.apache.org/viewvc?rev=993586&view=rev
Log:
format; organize imports

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

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java?rev=993586&r1=993585&r2=993586&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java
Wed Sep  8 02:34:25 2010
@@ -18,6 +18,24 @@
  */
 package org.apache.bval.jsr303;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.validation.ConstraintDeclarationException;
+import javax.validation.ConstraintValidator;
+import javax.validation.OverridesAttribute;
+import javax.validation.Payload;
+import javax.validation.ReportAsSingleViolation;
 
 import org.apache.bval.jsr303.groups.GroupsComputer;
 import org.apache.bval.jsr303.util.SecureActions;
@@ -26,22 +44,15 @@ import org.apache.bval.util.AccessStrate
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.validation.*;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.security.PrivilegedAction;
-import java.util.*;
-
 /**
  * Description: helper class that builds a {@link ConstraintValidation} or its
- * composite constraint validations by parsing the jsr303-annotations
- * and providing information (e.g. for @OverridesAttributes) <br/>
+ * composite constraint validations by parsing the jsr303-annotations and
+ * providing information (e.g. for @OverridesAttributes) <br/>
  */
 final class AnnotationConstraintBuilder<A extends Annotation> {
     private static final Log log = LogFactory.getLog(AnnotationConstraintBuilder.class);
 
-    //TODO extract these to some neutral location; see AnnotationProxyBuilder
+    // TODO extract these to some neutral location; see AnnotationProxyBuilder
     private static final String ANNOTATION_PAYLOAD = "payload";
     private static final String ANNOTATION_GROUPS = "groups";
 
@@ -50,20 +61,20 @@ final class AnnotationConstraintBuilder<
 
     /**
      * Create a new AnnotationConstraintBuilder instance.
+     * 
      * @param validatorClasses
      * @param constraintValidator
      * @param annotation
      * @param owner
      * @param access
      */
-    public AnnotationConstraintBuilder(
-          Class<? extends ConstraintValidator<A, ?>>[] validatorClasses,
-          ConstraintValidator<A, ?> constraintValidator, A annotation, Class<?>
owner,
-          AccessStrategy access) {
-        boolean reportFromComposite = annotation != null && annotation.annotationType()
-              .isAnnotationPresent(ReportAsSingleViolation.class);
-        constraintValidation = new ConstraintValidation<A>(validatorClasses,
-              constraintValidator, annotation, owner, access, reportFromComposite);
+    public AnnotationConstraintBuilder(Class<? extends ConstraintValidator<A, ?>>[]
validatorClasses,
+        ConstraintValidator<A, ?> constraintValidator, A annotation, Class<?>
owner, AccessStrategy access) {
+        boolean reportFromComposite =
+            annotation != null && annotation.annotationType().isAnnotationPresent(ReportAsSingleViolation.class);
+        constraintValidation =
+            new ConstraintValidation<A>(validatorClasses, constraintValidator, annotation,
owner, access,
+                reportFromComposite);
         buildFromAnnotation();
     }
 
@@ -72,10 +83,9 @@ final class AnnotationConstraintBuilder<
         if (constraintValidation.getAnnotation() != null) {
             SecureActions.run(new PrivilegedAction<Object>() {
                 public Object run() {
-                    for (Method method : constraintValidation.getAnnotation()
-                          .annotationType()
-                          .getDeclaredMethods()) {
-                        // groups + payload must also appear in attributes (also checked
by TCK-Tests)
+                    for (Method method : constraintValidation.getAnnotation().annotationType().getDeclaredMethods())
{
+                        // groups + payload must also appear in attributes (also
+                        // checked by TCK-Tests)
                         if (method.getParameterTypes().length == 0) {
                             try {
                                 if (ANNOTATION_PAYLOAD.equals(method.getName())) {
@@ -83,13 +93,11 @@ final class AnnotationConstraintBuilder<
                                 } else if (ANNOTATION_GROUPS.equals(method.getName())) {
                                     buildGroups(method);
                                 } else {
-                                    constraintValidation.getAttributes()
-                                          .put(method.getName(), method.invoke(
-                                                constraintValidation.getAnnotation()));
+                                    constraintValidation.getAttributes().put(method.getName(),
+                                        method.invoke(constraintValidation.getAnnotation()));
                                 }
                             } catch (Exception e) { // do nothing
-                                log.warn("error processing annotation: " +
-                                      constraintValidation.getAnnotation(), e);
+                                log.warn("error processing annotation: " + constraintValidation.getAnnotation(),
e);
                             }
                         }
                     }
@@ -99,12 +107,11 @@ final class AnnotationConstraintBuilder<
         }
     }
 
-    private void buildGroups(Method method)
-          throws IllegalAccessException, InvocationTargetException {
+    private void buildGroups(Method method) throws IllegalAccessException, InvocationTargetException
{
         Object raw = method.invoke(constraintValidation.getAnnotation());
         Class<?>[] garr;
         if (raw instanceof Class<?>) {
-            garr = new Class[]{(Class<?>) raw};
+            garr = new Class[] { (Class<?>) raw };
         } else if (raw instanceof Class<?>[]) {
             garr = (Class<?>[]) raw;
         } else {
@@ -118,13 +125,12 @@ final class AnnotationConstraintBuilder<
     }
 
     @SuppressWarnings("unchecked")
-    private void buildPayload(Method method)
-          throws IllegalAccessException, InvocationTargetException {
+    private void buildPayload(Method method) throws IllegalAccessException, InvocationTargetException
{
         Class<? extends Payload>[] payload_raw =
-              (Class<? extends Payload>[]) method.invoke(constraintValidation.getAnnotation());
+            (Class<? extends Payload>[]) method.invoke(constraintValidation.getAnnotation());
         Set<Class<? extends Payload>> payloadSet;
         if (payload_raw == null) {
-            payloadSet = Collections.<Class<? extends Payload>>emptySet();
+            payloadSet = Collections.<Class<? extends Payload>> emptySet();
         } else {
             payloadSet = new HashSet<Class<? extends Payload>>(payload_raw.length);
             payloadSet.addAll(Arrays.asList(payload_raw));
@@ -134,6 +140,7 @@ final class AnnotationConstraintBuilder<
 
     /**
      * Get the configured {@link ConstraintValidation}.
+     * 
      * @return {@link ConstraintValidation}
      */
     public ConstraintValidation<?> getConstraintValidation() {
@@ -141,8 +148,8 @@ final class AnnotationConstraintBuilder<
     }
 
     /**
-     * initialize a child composite 'validation' with @OverridesAttribute
-     * from 'constraintValidation' and add to composites.
+     * initialize a child composite 'validation' with @OverridesAttribute from
+     * 'constraintValidation' and add to composites.
      */
     public void addComposed(ConstraintValidation<?> composite) {
         applyOverridesAttributes(composite);
@@ -158,27 +165,28 @@ final class AnnotationConstraintBuilder<
 
             // Search for the overrides to apply
             ConstraintOverrides generalOverride = findOverride(composite.getAnnotation().annotationType(),
-1);
-            if ( generalOverride != null ) {
-                if ( index > 0 ) {
-                    throw new ConstraintDeclarationException("Wrong OverridesAttribute declaration
for " + generalOverride.constraintType + ", it needs a defined index when there is a list
of constraints");
+            if (generalOverride != null) {
+                if (index > 0) {
+                    throw new ConstraintDeclarationException("Wrong OverridesAttribute declaration
for "
+                        + generalOverride.constraintType
+                        + ", it needs a defined index when there is a list of constraints");
                 }
                 generalOverride.applyOn(composite);
             }
 
             ConstraintOverrides override = findOverride(composite.getAnnotation().annotationType(),
index);
-            if ( override != null ) {
+            if (override != null) {
                 override.applyOn(composite);
             }
 
         }
     }
 
-
     /**
      * Calculates the index of the composite constraint. The index represents
      * the order in which it is added in reference to other constraints of the
      * same type.
-     *
+     * 
      * @param composite
      *            The composite constraint (not yet added).
      * @return An integer index always >= 0
@@ -196,11 +204,8 @@ final class AnnotationConstraintBuilder<
     /** read overridesAttributes from constraintValidation.annotation */
     private void buildOverridesAttributes() {
         overrides = new LinkedList<ConstraintOverrides>();
-        for (Method method : constraintValidation.getAnnotation()
-              .annotationType()
-              .getDeclaredMethods()) {
-            OverridesAttribute.List annoOAL =
-                  method.getAnnotation(OverridesAttribute.List.class);
+        for (Method method : constraintValidation.getAnnotation().annotationType().getDeclaredMethods())
{
+            OverridesAttribute.List annoOAL = method.getAnnotation(OverridesAttribute.List.class);
             if (annoOAL != null) {
                 for (OverridesAttribute annoOA : annoOAL.value()) {
                     parseConstraintOverride(method.getName(), annoOA);
@@ -219,15 +224,12 @@ final class AnnotationConstraintBuilder<
             target = new ConstraintOverrides(oa.constraint(), oa.constraintIndex());
             overrides.add(target);
         }
-        target.values
-              .put(oa.name(), constraintValidation.getAttributes().get(methodName));
+        target.values.put(oa.name(), constraintValidation.getAttributes().get(methodName));
     }
 
-    private ConstraintOverrides findOverride(Class<? extends Annotation> constraint,
-                                             int constraintIndex) {
+    private ConstraintOverrides findOverride(Class<? extends Annotation> constraint,
int constraintIndex) {
         for (ConstraintOverrides each : overrides) {
-            if (each.constraintType == constraint &&
-                  each.constraintIndex == constraintIndex) {
+            if (each.constraintType == constraint && each.constraintIndex == constraintIndex)
{
                 return each;
             }
         }
@@ -235,8 +237,8 @@ final class AnnotationConstraintBuilder<
     }
 
     /**
-     * Holds the values to override in a composed constraint
-     * during creation of a composed ConstraintValidation
+     * Holds the values to override in a composed constraint during creation of
+     * a composed ConstraintValidation
      */
     private static final class ConstraintOverrides {
         final Class<? extends Annotation> constraintType;
@@ -245,8 +247,7 @@ final class AnnotationConstraintBuilder<
         /** key = attributeName, value = overridden value */
         final Map<String, Object> values;
 
-        private ConstraintOverrides(Class<? extends Annotation> constraintType,
-                                    int constraintIndex) {
+        private ConstraintOverrides(Class<? extends Annotation> constraintType, int
constraintIndex) {
             this.constraintType = constraintType;
             this.constraintIndex = constraintIndex;
             values = new HashMap<String, Object>();
@@ -260,7 +261,7 @@ final class AnnotationConstraintBuilder<
             // And the annotation
             Annotation originalAnnot = composite.getAnnotation();
             AnnotationProxyBuilder<Annotation> apb = new AnnotationProxyBuilder<Annotation>(originalAnnot);
-            for ( String key : values.keySet() ) {
+            for (String key : values.keySet()) {
                 apb.putValue(key, values.get(key));
             }
             Annotation newAnnot = apb.createAnnotation();



Mime
View raw message