bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1513638 [2/2] - in /bval/branches/bval-11: ./ bval-core/src/main/java/org/apache/bval/ bval-core/src/main/java/org/apache/bval/model/ bval-core/src/main/java/org/apache/bval/util/ bval-core/src/main/java/org/apache/bval/util/reflection/ bv...
Date Tue, 13 Aug 2013 20:26:52 GMT
Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintAnnotationAttributes.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintAnnotationAttributes.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintAnnotationAttributes.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintAnnotationAttributes.java Tue Aug 13 20:26:51 2013
@@ -16,14 +16,13 @@
  */
 package org.apache.bval.jsr303;
 
-import org.apache.bval.jsr303.util.SecureActions;
+import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.reflect.TypeUtils;
 
 import javax.validation.Constraint;
 import javax.validation.ConstraintDefinitionException;
 import javax.validation.ConstraintTarget;
 import javax.validation.Payload;
-import javax.validation.ValidationException;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Array;
 import java.lang.reflect.Method;
@@ -41,27 +40,27 @@ public enum ConstraintAnnotationAttribut
     /**
      * "message"
      */
-    MESSAGE(false, false, "message"),
+    MESSAGE(false, "message"),
 
     /**
      * "groups"
      */
-    GROUPS(false, false, "groups"),
+    GROUPS(false, "groups"),
 
     /**
      * "payload"
      */
-    PAYLOAD(false, false, "payload"),
+    PAYLOAD(false, "payload"),
 
     /**
      * "validationAppliesTo"
      */
-    VALIDATION_APPLIES_TO(true, true, "validationAppliesTo"),
+    VALIDATION_APPLIES_TO(true, "validationAppliesTo"),
 
     /**
      * "value" for multi-valued constraints
      */
-    VALUE(false, true, "value");
+    VALUE(true, "value");
 
     @SuppressWarnings("unused")
     private static class Types {
@@ -75,11 +74,9 @@ public enum ConstraintAnnotationAttribut
     private final Type type;
     private final boolean permitNullDefaultValue;
     private final String attributeName;
-    private final boolean quiet;
 
-    private ConstraintAnnotationAttributes(final boolean quiet, final boolean permitNullDefaultValue, final String name) {
+    private ConstraintAnnotationAttributes(final boolean permitNullDefaultValue, final String name) {
         this.permitNullDefaultValue = permitNullDefaultValue;
-        this.quiet = quiet;
         this.attributeName = name;
         try {
             this.type = Types.class.getDeclaredField(getAttributeName()).getGenericType();
@@ -117,9 +114,6 @@ public enum ConstraintAnnotationAttribut
      * @return previous value mapped to <code>this.attributeName</code>
      */
     public <V> Object put(Map<? super String, ? super V> map, V value) {
-        if (!TypeUtils.isInstance(value, getType())) {
-            throw new IllegalArgumentException(String.format("Invalid '%s' value: %s", getAttributeName(), value));
-        }
         return map.put(getAttributeName(), value);
     }
 
@@ -139,133 +133,73 @@ public enum ConstraintAnnotationAttribut
         return result;
     }
 
-    /**
-     * Verify that this attribute is validly defined on the given type.
-     * 
-     * @param type
-     * @throws ConstraintDefinitionException
-     */
-    public <A extends Annotation> void validateOn(Class<A> type) {
-        new Worker<A>(type, quiet);
-    }
-
-    /**
-     * Benign means of checking for an attribute's existence.
-     * 
-     * @param type
-     * @return whether the attribute was (properly) declared
-     */
-    public <A extends Annotation> boolean isDeclaredOn(Class<A> type) {
-        return new Worker<A>(type, true).valid;
-    }
-
-    /**
-     * Get the value of this attribute from the specified constraint annotation.
-     * 
-     * @param constraint
-     * @return Object
-     */
-    public <T> T getValue(Annotation constraint) {
-        try {
-            @SuppressWarnings({ "rawtypes", "unchecked" })
-            T result = (T) new Worker(constraint.annotationType()).read(constraint);
-            return result;
-        } catch (Exception e) {
-            throw new ValidationException(String.format("Could not get value of %1$s() from %2$s", getType(),
-                constraint));
-        }
-    }
-
-    /**
-     * Get the default value of this attribute on the given annotation type.
-     * @param <T>
-     * @param type
-     * @return Object
-     */
-    public <T, A extends Annotation> T getDefaultValue(Class<A> type) {
-        return  (T) new Worker<A>(type, quiet).defaultValue;
-    }
-
-    private static <T> T doPrivileged(final PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
-        }
+    public <C extends Annotation> Worker<C> analyze(final Class<C> clazz) {
+        return new Worker<C>(clazz);
     }
 
-    private class Worker<C> {
-        final Method method;
-        final Object defaultValue;
-        final boolean valid;
+    public class Worker<C extends Annotation> {
+        public final Method method;
+        public final Object defaultValue;
+        private RuntimeException error;
 
         /**
          * Create a new Worker instance.
          * @param constraintType to handle
          */
-        Worker(Class<C> constraintType) {
-            this(constraintType, false);
-        }
-
-        /**
-         * Create a new Worker instance.
-         * @param constraintType to handle
-         * @param quiet whether to simply set !valid rather than throw an Exception on error
-         */
-        Worker(Class<C> constraintType, boolean quiet) {
-            super();
-            boolean _valid = true;
+        Worker(final Class<C> constraintType) {
             Object _defaultValue = null;
             try {
-                method = doPrivileged(SecureActions.getPublicMethod(constraintType, getAttributeName()));
+                method = Reflection.INSTANCE.getPublicMethod(constraintType, getAttributeName());
                 if (method == null) {
-                    if (quiet) {
-                        _valid = false;
-                        return;
-                    }
-                    throw new ConstraintDefinitionException(String.format("Annotation %1$s has no %2$s() method",
-                        constraintType, getAttributeName()));
+                    error = new ConstraintDefinitionException(String.format("Annotation %1$s has no %2$s() method", constraintType, getAttributeName()));
+                    return;
                 }
 
                 if (!TypeUtils.isAssignable(method.getReturnType(), getType())) {
-                    if (quiet) {
-                        _valid = false;
-                        return;
-                    }
-                    throw new ConstraintDefinitionException(String.format(
-                        "Return type for %1$s() must be of type %2$s", getAttributeName(), getType()));
+                    error = new ConstraintDefinitionException(String.format("Return type for %1$s() must be of type %2$s", getAttributeName(), getType()));
+                    return;
                 }
                 _defaultValue = method.getDefaultValue();
                 if (_defaultValue == null && permitNullDefaultValue) {
                     return;
                 }
                 if (TypeUtils.isArrayType(getType()) && Array.getLength(_defaultValue) > 0) {
-                    if (quiet) {
-                        _valid = false;
-                        return;
-                    }
-                    throw new ConstraintDefinitionException(String.format(
-                        "Default value for %1$s() must be an empty array", getAttributeName()));
+                    error = new ConstraintDefinitionException(String.format("Default value for %1$s() must be an empty array", getAttributeName()));
                 }
             } finally {
-                valid = _valid;
                 defaultValue = _defaultValue;
             }
         }
 
-        <T> T read(final C constraint) {
-            @SuppressWarnings("unchecked")
-            T result = (T) doPrivileged(new PrivilegedAction<Object>() {
+        public boolean isValid() {
+            return error == null;
+        }
+
+        public Worker<C> valid() {
+            if (!isValid()) {
+                throw error;
+            }
+            return this;
+        }
+
+        public Object read(final Annotation constraint) {
+            if (System.getSecurityManager() == null) {
+                return doInvoke(constraint);
+            }
+            return AccessController.doPrivileged(new PrivilegedAction<Object>() {
                 public Object run() {
-                    try {
-                        method.setAccessible(true);
-                        return method.invoke(constraint);
-                    } catch (Exception e) {
-                        throw new RuntimeException(e);
-                    }
+                    return doInvoke(constraint);
                 }
             });
-            return result;
+        }
+
+        private Object doInvoke(final Annotation constraint) {
+            try {
+                method.setAccessible(true);
+                return method.invoke(constraint);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
         }
     }
 }

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintDefaults.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintDefaults.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintDefaults.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintDefaults.java Tue Aug 13 20:26:51 2013
@@ -24,7 +24,11 @@ import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-import java.util.*;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -59,7 +63,7 @@ public class ConstraintDefaults {
 
     /**
      * Get the default validator implementation types for the specified constraint annotation type. 
-     * @param annotationType
+     * @param annotationType the annotation type
      * @return array of {@link ConstraintValidator} implementation classes
      */
     @SuppressWarnings("unchecked")
@@ -83,34 +87,42 @@ public class ConstraintDefaults {
             log.log(Level.WARNING, String.format("Cannot find %s", resource));
         }
 
-        Map<String, Class<? extends ConstraintValidator<?, ?>>[]> loadedConstraints
-                = new HashMap<String, Class<? extends ConstraintValidator<?,?>>[]>();
-        for (Map.Entry<Object, Object> entry : constraintProperties.entrySet()) {
+        final Map<String, Class<? extends ConstraintValidator<?, ?>>[]> loadedConstraints = new HashMap<String, Class<? extends ConstraintValidator<?,?>>[]>();
+        for (final Map.Entry<Object, Object> entry : constraintProperties.entrySet()) {
 
-            StringTokenizer tokens = new StringTokenizer((String) entry.getValue(), ", ");
-            LinkedList<Class<?>> classes = new LinkedList<Class<?>>();
+            final StringTokenizer tokens = new StringTokenizer((String) entry.getValue(), ", ");
+            final LinkedList<Class<?>> classes = new LinkedList<Class<?>>();
             while (tokens.hasMoreTokens()) {
                 final String eachClassName = tokens.nextToken();
 
-                Class<?> constraintValidatorClass =
-                      run(new PrivilegedAction<Class<?>>() {
+                Class<?> constraintValidatorClass;
+                if (System.getSecurityManager() == null) {
+                    try {
+                        constraintValidatorClass = Class.forName(eachClassName, true, classloader);
+                    } catch (final ClassNotFoundException e) {
+                        log.log(Level.SEVERE, String.format("Cannot find class %s", eachClassName), e);
+                        constraintValidatorClass = null;
+                    }
+                } else {
+                    constraintValidatorClass = AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
                           public Class<?> run() {
                               try {
                                   return Class.forName(eachClassName, true, classloader);
-                              } catch (ClassNotFoundException e) {
+                              } catch (final ClassNotFoundException e) {
                                   log.log(Level.SEVERE, String.format("Cannot find class %s", eachClassName), e);
                                   return null;
                               }
                           }
                       });
+                }
 
-                if (constraintValidatorClass != null) classes.add(constraintValidatorClass);
+                if (constraintValidatorClass != null) {
+                    classes.add(constraintValidatorClass);
+                }
 
             }
-            loadedConstraints
-                  .put((String) entry.getKey(),
-                        (Class<? extends ConstraintValidator<?, ?>>[]) classes.toArray(new Class[classes.size()]));
 
+            loadedConstraints.put((String) entry.getKey(), classes.toArray(new Class[classes.size()]));
         }
         return loadedConstraints;
     }
@@ -120,12 +132,4 @@ public class ConstraintDefaults {
         if (classloader == null) classloader = getClass().getClassLoader();
         return classloader;
     }
-
-    private static <T> T run(PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
-        }
-    }
 }

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java Tue Aug 13 20:26:51 2013
@@ -114,9 +114,15 @@ public class ConstraintValidation<T exte
      * 
      * @param groups
      */
-    void setGroups(Set<Class<?>> groups) {
+    void setGroups(final Set<Class<?>> groups) {
         this.groups = groups;
-        ConstraintAnnotationAttributes.GROUPS.put(attributes, groups.toArray(new Class[groups.size()]));
+        ConstraintAnnotationAttributes.GROUPS.put(attributes, groups.toArray(new Class<?>[groups.size()]));
+    }
+
+    void setGroups(final Class<?>[] groups) {
+        this.groups = new HashSet<Class<?>>();
+        Collections.addAll(this.groups, groups);
+        ConstraintAnnotationAttributes.GROUPS.put(attributes, groups);
     }
 
     /**

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/DefaultMessageInterpolator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/DefaultMessageInterpolator.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/DefaultMessageInterpolator.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/DefaultMessageInterpolator.java Tue Aug 13 20:26:51 2013
@@ -17,12 +17,10 @@
 package org.apache.bval.jsr303;
 
 import org.apache.bval.el.MessageEvaluator;
-import org.apache.bval.jsr303.util.SecureActions;
+import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.ArrayUtils;
 
 import javax.validation.MessageInterpolator;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.Locale;
 import java.util.Map;
 import java.util.MissingResourceException;
@@ -41,6 +39,7 @@ import java.util.regex.Pattern;
  */
 public class DefaultMessageInterpolator implements MessageInterpolator {
     private static final Logger log = Logger.getLogger(DefaultMessageInterpolator.class.getName());
+    private static final boolean LOG_FINEST = log.isLoggable(Level.FINEST);
     private static final String DEFAULT_VALIDATION_MESSAGES = "org.apache.bval.jsr303.ValidationMessages";
     private static final String USER_VALIDATION_MESSAGES = "ValidationMessages";
 
@@ -174,7 +173,7 @@ public class DefaultMessageInterpolator 
      */
     private ResourceBundle getFileBasedResourceBundle(Locale locale) {
         ResourceBundle rb = null;
-        final ClassLoader classLoader = doPrivileged(SecureActions.getContextClassLoader());
+        final ClassLoader classLoader = Reflection.INSTANCE.getClassLoader(DefaultMessageInterpolator.class);
         if (classLoader != null) {
             rb = loadBundle(classLoader, locale,
                   USER_VALIDATION_MESSAGES + " not found by thread local classloader");
@@ -183,16 +182,14 @@ public class DefaultMessageInterpolator 
         // 2011-03-27 jw: No privileged action required.
         // A class can always access the classloader of itself and of subclasses.
         if (rb == null) {
-            rb = loadBundle(
-              getClass().getClassLoader(),
-              locale,
-              USER_VALIDATION_MESSAGES + " not found by validator classloader"
-            );
+            rb = loadBundle(getClass().getClassLoader(), locale, USER_VALIDATION_MESSAGES + " not found by validator classloader");
         }
-        if (rb != null) {
-            log.log(Level.FINEST, String.format("%s found", USER_VALIDATION_MESSAGES));
-        } else {
-        	log.log(Level.FINEST, String.format("%s not found. Delegating to %s", USER_VALIDATION_MESSAGES, DEFAULT_VALIDATION_MESSAGES));
+        if (LOG_FINEST) {
+            if (rb != null) {
+                log.log(Level.FINEST, String.format("%s found", USER_VALIDATION_MESSAGES));
+            } else {
+                log.log(Level.FINEST, String.format("%s not found. Delegating to %s", USER_VALIDATION_MESSAGES, DEFAULT_VALIDATION_MESSAGES));
+            }
         }
         return rb;
     }
@@ -202,7 +199,7 @@ public class DefaultMessageInterpolator 
         ResourceBundle rb = null;
         try {
             rb = ResourceBundle.getBundle(USER_VALIDATION_MESSAGES, locale, classLoader);
-        } catch (MissingResourceException e) {
+        } catch (final MissingResourceException e) {
             log.fine(message);
         }
         return rb;
@@ -311,22 +308,4 @@ public class DefaultMessageInterpolator 
     private String sanitizeForAppendReplacement(String src) {
         return src.replace("\\", "\\\\").replace("$", "\\$");
     }
-
-
-
-    /**
-     * Perform action with AccessController.doPrivileged() if a security manager is installed.
-     *
-     * @param action
-     *  the action to run
-     * @return
-     *  result of the action
-     */
-    private static <T> T doPrivileged(final PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
-        }
-    }
 }

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/DefaultValidationProviderResolver.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/DefaultValidationProviderResolver.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/DefaultValidationProviderResolver.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/DefaultValidationProviderResolver.java Tue Aug 13 20:26:51 2013
@@ -34,7 +34,7 @@ public class DefaultValidationProviderRe
 
     //TODO - Spec recommends caching per classloader
     private static final String SPI_CFG =
-            "META-INF/services/javax.validation.spi.ValidationProvider";
+        "META-INF/services/javax.validation.spi.ValidationProvider";
 
     /**
      * {@inheritDoc}
@@ -62,21 +62,29 @@ public class DefaultValidationProviderRe
                                 // try loading the specified class
                                 final Class<?> provider = cl.loadClass(line);
                                 // create an instance to return
-                                ValidationProvider<?> vp =
-                                        AccessController.doPrivileged(new PrivilegedAction<ValidationProvider<?>>() {
-                                            public ValidationProvider<?> run() {
-                                                try {
-                                                    return (ValidationProvider<?>) provider.newInstance();
-                                                } catch (final Exception ex) {
-                                                    throw new ValidationException("Cannot instantiate : " + provider, ex);
-                                                }
+                                final ValidationProvider<?> vp;
+                                if (System.getSecurityManager() == null) {
+                                    try {
+                                        vp = (ValidationProvider<?>) provider.newInstance();
+                                    } catch (final Exception ex) {
+                                        throw new ValidationException("Cannot instantiate : " + provider, ex);
+                                    }
+                                } else {
+                                    vp = AccessController.doPrivileged(new PrivilegedAction<ValidationProvider<?>>() {
+                                        public ValidationProvider<?> run() {
+                                            try {
+                                                return (ValidationProvider<?>) provider.newInstance();
+                                            } catch (final Exception ex) {
+                                                throw new ValidationException("Cannot instantiate : " + provider, ex);
                                             }
-                                        });
-                                 providers.add(vp);
+                                        }
+                                    });
+                                }
+                                providers.add(vp);
 
                             } catch (ClassNotFoundException e) {
                                 throw new ValidationException("Failed to load provider " +
-                                        line + " configured in file " + url, e);
+                                    line + " configured in file " + url, e);
                             }
                         }
                         line = br.readLine();

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java Tue Aug 13 20:26:51 2013
@@ -21,7 +21,6 @@ package org.apache.bval.jsr303;
 import org.apache.bval.MetaBeanFactory;
 import org.apache.bval.jsr303.groups.Group;
 import org.apache.bval.jsr303.util.ClassHelper;
-import org.apache.bval.jsr303.util.SecureActions;
 import org.apache.bval.jsr303.xml.MetaConstraint;
 import org.apache.bval.model.Meta;
 import org.apache.bval.model.MetaBean;
@@ -32,6 +31,7 @@ import org.apache.bval.model.MetaPropert
 import org.apache.bval.util.AccessStrategy;
 import org.apache.bval.util.FieldAccess;
 import org.apache.bval.util.MethodAccess;
+import org.apache.bval.util.reflection.Reflection;
 
 import javax.validation.Constraint;
 import javax.validation.ConstraintDeclarationException;
@@ -39,7 +39,6 @@ import javax.validation.GroupDefinitionE
 import javax.validation.GroupSequence;
 import javax.validation.groups.ConvertGroup;
 import javax.validation.groups.Default;
-import javax.validation.metadata.PropertyDescriptor;
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.annotation.ElementType;
@@ -47,8 +46,6 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -134,7 +131,7 @@ public class Jsr303MetaBeanFactory imple
 
         final Collection<String> missingValid = new ArrayList<String>();
 
-        final Field[] fields = doPrivileged(SecureActions.getDeclaredFields(beanClass));
+        final Field[] fields = Reflection.INSTANCE.getDeclaredFields(beanClass);
         for (final Field field : fields) {
             MetaProperty metaProperty = metabean.getProperty(field.getName());
             // create a property for those fields for which there is not yet a
@@ -155,7 +152,7 @@ public class Jsr303MetaBeanFactory imple
                 }
             }
         }
-        final Method[] methods = doPrivileged(SecureActions.getDeclaredMethods(beanClass));
+        final Method[] methods = Reflection.INSTANCE.getDeclaredMethods(beanClass);
         for (final Method method : methods) {
             String propName = null;
             if (method.getParameterTypes().length == 0) {
@@ -205,17 +202,18 @@ public class Jsr303MetaBeanFactory imple
         return false;
     }
 
-    private boolean hasValidationConstraintsDefined(Annotation annot) {
+    private boolean hasValidationConstraintsDefined(final Annotation annot) {
         // If it is annotated with @Constraint
         if (annot.annotationType().getAnnotation(Constraint.class) != null) {
             return true;
         }
 
         // Check whether it is a multivalued constraint:
-        if (ConstraintAnnotationAttributes.VALUE.isDeclaredOn(annot.annotationType())) {
-            Annotation[] children = ConstraintAnnotationAttributes.VALUE.getValue(annot);
+        final ConstraintAnnotationAttributes.Worker<?> worker = ConstraintAnnotationAttributes.VALUE.analyze(annot.annotationType());
+        if (worker.isValid()) {
+            Annotation[] children = Annotation[].class.cast(worker.read(annot));
             if (children != null) {
-                for (Annotation child : children) {
+                for (final Annotation child : children) {
                     if (hasValidationConstraintsDefined(child)) {
                         return true;
                     }
@@ -369,23 +367,4 @@ public class Jsr303MetaBeanFactory imple
         parentMetaBean.putProperty(name, result);
         return result;
     }
-
-
-
-
-    /**
-     * Perform action with AccessController.doPrivileged() if a security manager is installed.
-     *
-     * @param action
-     *  the action to run
-     * @return
-     *  result of the action
-     */
-    private static <T> T doPrivileged(final PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
-        }
-    }
 }

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java Tue Aug 13 20:26:51 2013
@@ -31,19 +31,12 @@ import java.util.*;
  * Implementation is thread-safe.
  */
 public class GroupsComputer {
+    public static final Class<?>[] DEFAULT_GROUP = new Class<?>[]{Default.class};
+
     /** The default group array used in case any of the validate methods is called without a group. */
     private static final Groups DEFAULT_GROUPS;
-
     static {
-        DEFAULT_GROUPS = new GroupsComputer().computeGroups(Arrays.asList(getDefaultGroupArray()));
-    }
-
-    /**
-     * Get the default group array.
-     * @return <code>{@link Default}.class</code> only
-     */
-    public static Class<?>[] getDefaultGroupArray() {
-        return new Class<?>[] { Default.class };
+        DEFAULT_GROUPS = new GroupsComputer().computeGroups(Arrays.asList(DEFAULT_GROUP));
     }
 
     /** caching resolved groups in a thread-safe map. */

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/DefaultTraversableResolver.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/DefaultTraversableResolver.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/DefaultTraversableResolver.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/DefaultTraversableResolver.java Tue Aug 13 20:26:51 2013
@@ -16,22 +16,19 @@
  */
 package org.apache.bval.jsr303.resolver;
 
-import java.lang.annotation.ElementType;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.apache.bval.util.reflection.Reflection;
+import org.apache.commons.lang3.ClassUtils;
 
 import javax.validation.Path;
 import javax.validation.TraversableResolver;
-
-import org.apache.bval.jsr303.util.ClassHelper;
-import org.apache.bval.util.PrivilegedActions;
-import org.apache.commons.lang3.ClassUtils;
+import java.lang.annotation.ElementType;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /** @see javax.validation.TraversableResolver */
 public class DefaultTraversableResolver implements TraversableResolver, CachingRelevant {
     private static final Logger log = Logger.getLogger(DefaultTraversableResolver.class.getName());
+    private static final boolean LOG_FINEST = log.isLoggable(Level.FINEST);
 
     /** Class to load to check whether JPA 2 is on the classpath. */
     private static final String PERSISTENCE_UTIL_CLASSNAME =
@@ -76,9 +73,11 @@ public class DefaultTraversableResolver 
     private void initJpa() {
         final ClassLoader classLoader = getClassLoader();
         try {
-            PrivilegedActions.getClass(classLoader, PERSISTENCE_UTIL_CLASSNAME);
-            log.log(Level.FINEST, String.format("Found %s on classpath.", PERSISTENCE_UTIL_CLASSNAME));
-        } catch (Exception e) {
+            Reflection.INSTANCE.getClass(classLoader, PERSISTENCE_UTIL_CLASSNAME);
+            if (LOG_FINEST) {
+                log.log(Level.FINEST, String.format("Found %s on classpath.", PERSISTENCE_UTIL_CLASSNAME));
+            }
+        } catch (final Exception e) {
             log.log(Level.FINEST, String.format("Cannot find %s on classpath. All properties will per default be traversable.", PERSISTENCE_UTIL_CLASSNAME));
             return;
         }
@@ -88,12 +87,11 @@ public class DefaultTraversableResolver 
               (Class<? extends TraversableResolver>)
                 ClassUtils.getClass(classLoader, JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME, true);
             jpaTR = jpaAwareResolverClass.newInstance();
-            log.log(Level.FINEST, String.format("Instantiated an instance of %s.", JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME));
-        } catch (Exception e) {
-			log.log(Level.WARNING,
-					String.format(
-							"Unable to load or instantiate JPA aware resolver %s. All properties will per default be traversable.",
-							JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME, e));
+            if (LOG_FINEST) {
+                log.log(Level.FINEST, String.format("Instantiated an instance of %s.", JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME));
+            }
+        } catch (final Exception e) {
+			log.log(Level.WARNING, String.format("Unable to load or instantiate JPA aware resolver %s. All properties will per default be traversable.", JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME), e);
         }
     }
 
@@ -106,18 +104,6 @@ public class DefaultTraversableResolver 
 
     private static ClassLoader getClassLoader()
     {
-      return (System.getSecurityManager() == null)
-        ? getClassLoader0()
-        : AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
-              public ClassLoader run() {
-                return getClassLoader0();
-              }
-          });
-    }
-
-    private static ClassLoader getClassLoader0()
-    {
-      final ClassLoader loader = Thread.currentThread().getContextClassLoader();
-      return (loader != null) ? loader : ClassHelper.class.getClassLoader();
+      return Reflection.INSTANCE.getClassLoader(DefaultTraversableResolver.class);
     }
 }

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/ConstraintDefinitionValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/ConstraintDefinitionValidator.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/ConstraintDefinitionValidator.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/ConstraintDefinitionValidator.java Tue Aug 13 20:26:51 2013
@@ -18,17 +18,12 @@
  */
 package org.apache.bval.jsr303.util;
 
+import org.apache.bval.jsr303.ConstraintAnnotationAttributes;
+
 import javax.validation.Constraint;
 import javax.validation.ConstraintDefinitionException;
 import javax.validation.ConstraintTarget;
-
-import org.apache.bval.jsr303.ConstraintAnnotationAttributes;
-
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Locale;
 
 /**
  * Internal validator that ensures the correct definition of constraint
@@ -49,43 +44,14 @@ public class ConstraintDefinitionValidat
     public static void validateConstraintDefinition(final Annotation annotation) {
         final Class<? extends Annotation> type = annotation.annotationType();
 
-        ConstraintAnnotationAttributes.GROUPS.validateOn(type);
-        ConstraintAnnotationAttributes.PAYLOAD.validateOn(type);
-        ConstraintAnnotationAttributes.MESSAGE.validateOn(type);
-        ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.validateOn(type);
+        ConstraintAnnotationAttributes.GROUPS.analyze(type).valid();
+        ConstraintAnnotationAttributes.PAYLOAD.analyze(type).valid();
+        ConstraintAnnotationAttributes.MESSAGE.analyze(type).valid();
 
-        final Object defaultValidationApplies = ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.getDefaultValue(type);
-        if (ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.isDeclaredOn(type) && !ConstraintTarget.IMPLICIT.equals(defaultValidationApplies)) {
-            throw new ConstraintDefinitionException("validationAppliesTo default value should be IMPLICIT");
-        }
-
-        validAttributes(annotation);
-    }
+        final ConstraintAnnotationAttributes.Worker<? extends Annotation> validationAppliesToWorker = ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.analyze(type);
 
-    /**
-     * Check that the annotation has no methods that start with "valid".
-     * 
-     * @param annotation
-     *            The annotation to check.
-     */
-    private static void validAttributes(final Annotation annotation) {
-        /*
-        final Method[] methods = run(SecureActions.getDeclaredMethods(annotation.annotationType()));
-        for (Method method : methods ){
-            // Currently case insensitive, the spec is unclear about this
-            if (method.getName().toLowerCase(Locale.ENGLISH).startsWith("valid")) {
-                throw new ConstraintDefinitionException(
-                    "A constraint annotation cannot have methods which start with 'valid'");
-            }
-        }
-        */
-    }
-
-    private static <T> T run(PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
+        if (validationAppliesToWorker.isValid() && !ConstraintTarget.IMPLICIT.equals(validationAppliesToWorker.defaultValue)) {
+            throw new ConstraintDefinitionException("validationAppliesTo default value should be IMPLICIT");
         }
     }
 }

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/AnnotationProxy.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/AnnotationProxy.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/AnnotationProxy.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/AnnotationProxy.java Tue Aug 13 20:26:51 2013
@@ -16,21 +16,18 @@
  */
 package org.apache.bval.jsr303.xml;
 
+import org.apache.bval.util.reflection.Reflection;
+
+import javax.validation.Valid;
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import org.apache.bval.jsr303.util.SecureActions;
-
-import javax.validation.Valid;
-
 /**
  * Description: <br/>
  * InvocationHandler implementation of <code>Annotation</code> that pretends it
@@ -59,9 +56,7 @@ class AnnotationProxy implements Annotat
     private <A extends Annotation> Map<String, Object> getAnnotationValues(AnnotationProxyBuilder<A> descriptor) {
         Map<String, Object> result = new HashMap<String, Object>();
         int processedValuesFromDescriptor = 0;
-        final Method[] declaredMethods = doPrivileged(
-          SecureActions.getDeclaredMethods(annotationType)
-        );
+        final Method[] declaredMethods = Reflection.INSTANCE.getDeclaredMethods(annotationType);
         for (Method m : declaredMethods) {
             if (descriptor.contains(m.getName())) {
                 result.put(m.getName(), descriptor.getValue(m.getName()));
@@ -118,14 +113,4 @@ class AnnotationProxy implements Annotat
         result.addAll(values.keySet());
         return result;
     }
-
-
-
-    private static <T> T doPrivileged(final PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
-        }
-    }
 }

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/AnnotationProxyBuilder.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/AnnotationProxyBuilder.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/AnnotationProxyBuilder.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/AnnotationProxyBuilder.java Tue Aug 13 20:26:51 2013
@@ -17,7 +17,7 @@
 package org.apache.bval.jsr303.xml;
 
 import org.apache.bval.jsr303.ConstraintAnnotationAttributes;
-import org.apache.bval.jsr303.util.SecureActions;
+import org.apache.bval.util.reflection.Reflection;
 
 import javax.validation.Payload;
 import javax.validation.Valid;
@@ -76,7 +76,7 @@ final public class AnnotationProxyBuilde
     public AnnotationProxyBuilder(A annot) {
         this((Class<A>) annot.annotationType());
         // Obtain the "elements" of the annotation
-        final Method[] methods = doPrivileged(SecureActions.getDeclaredMethods(annot.annotationType()));
+        final Method[] methods = Reflection.INSTANCE.getDeclaredMethods(annot.annotationType());
         for (Method m : methods) {
             if (!m.isAccessible()) {
                 m.setAccessible(true);
@@ -177,31 +177,29 @@ final public class AnnotationProxyBuilde
      * @return {@link Annotation}
      */
     public A createAnnotation() {
-        ClassLoader classLoader = SecureActions.getClassLoader(getType());
+        ClassLoader classLoader = Reflection.INSTANCE.getClassLoader(getType());
         @SuppressWarnings("unchecked")
         final Class<A> proxyClass = (Class<A>) Proxy.getProxyClass(classLoader, getType());
         final InvocationHandler handler = new AnnotationProxy(this);
-        return doPrivileged(new PrivilegedAction<A>() {
+        if (System.getSecurityManager() == null) {
+            return doCreateAnnotation(proxyClass, handler);
+        }
+        return AccessController.doPrivileged(new PrivilegedAction<A>() {
             public A run() {
-                try {
-                    Constructor<A> constructor = proxyClass.getConstructor(InvocationHandler.class);
-                    return constructor.newInstance(handler);
-                } catch (Exception e) {
-                    throw new ValidationException("Unable to create annotation for configured constraint", e);
-                }
+                return doCreateAnnotation(proxyClass, handler);
             }
         });
     }
 
-    private static <T> T doPrivileged(final PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
+    private A doCreateAnnotation(final Class<A> proxyClass, final InvocationHandler handler) {
+        try {
+            Constructor<A> constructor = proxyClass.getConstructor(InvocationHandler.class);
+            return constructor.newInstance(handler);
+        } catch (Exception e) {
+            throw new ValidationException("Unable to create annotation for configured constraint", e);
         }
     }
 
-
     public static final class ValidAnnotation implements Valid {
         public static final ValidAnnotation INSTANCE = new ValidAnnotation();
 

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationMappingParser.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationMappingParser.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationMappingParser.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationMappingParser.java Tue Aug 13 20:26:51 2013
@@ -21,9 +21,9 @@ import org.apache.bval.jsr303.ApacheVali
 import org.apache.bval.jsr303.ConstraintAnnotationAttributes;
 import org.apache.bval.jsr303.util.EnumerationConverter;
 import org.apache.bval.jsr303.util.IOUtils;
-import org.apache.bval.jsr303.util.SecureActions;
 import org.apache.bval.util.FieldAccess;
 import org.apache.bval.util.MethodAccess;
+import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.beanutils.ConvertUtils;
 import org.apache.commons.beanutils.Converter;
 import org.apache.commons.lang3.StringUtils;
@@ -200,7 +200,7 @@ public class ValidationMappingParser {
 
     private <A extends Annotation> Class<?> getAnnotationParameterType(
           final Class<A> annotationClass, final String name) {
-        final Method m = doPrivileged(SecureActions.getPublicMethod(annotationClass, name));
+        final Method m = Reflection.INSTANCE.getPublicMethod(annotationClass, name);
         if (m == null) {
             throw new ValidationException("Annotation of type " + annotationClass.getName() +
                   " does not contain a parameter " + name + ".");
@@ -385,7 +385,7 @@ public class ValidationMappingParser {
             } else {
                 methodNames.add(methodName);
             }
-            final Method method = doPrivileged(SecureActions.getDeclaredMethod(beanClass, methodName, toTypes(methodType.getParameter(), defaultPackage)));
+            final Method method = Reflection.INSTANCE.getDeclaredMethod(beanClass, methodName, toTypes(methodType.getParameter(), defaultPackage));
             if (method == null) {
                 throw new ValidationException(beanClass.getName() + " does not contain the method  " + methodName);
             }
@@ -466,7 +466,7 @@ public class ValidationMappingParser {
 
     private <A> void processConstructorLevel(final List<ConstructorType> constructors, final Class<A> beanClass, final String defaultPackage, final boolean parentIgnore) {
         for (final ConstructorType constructorType : constructors) {
-            final Constructor<?> constructor = doPrivileged(SecureActions.getDeclaredConstructor(beanClass, toTypes(constructorType.getParameter(), defaultPackage)));
+            final Constructor<?> constructor = Reflection.INSTANCE.getDeclaredConstructor(beanClass, toTypes(constructorType.getParameter(), defaultPackage));
             if (constructor == null) {
                 throw new ValidationException(beanClass.getName() + " does not contain the constructor  " + constructorType);
             }
@@ -575,7 +575,7 @@ public class ValidationMappingParser {
             } else {
                 fieldNames.add(fieldName);
             }
-            final Field field = doPrivileged(SecureActions.getDeclaredField(beanClass, fieldName));
+            final Field field = Reflection.INSTANCE.getDeclaredField(beanClass, fieldName);
             if (field == null) {
                 throw new ValidationException(
                       beanClass.getName() + " does not contain the fieldType  " + fieldName);
@@ -747,40 +747,34 @@ public class ValidationMappingParser {
         return clazz.contains(".");
     }
 
-
-
-    private static <T> T doPrivileged(final PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
-        }
-    }
-
-
-
     private static Method getGetter(final Class<?> clazz, final String propertyName) {
-        return doPrivileged(new PrivilegedAction<Method>() {
+        if (System.getSecurityManager() == null) {
+            return doGetGetter(propertyName, clazz);
+        }
+        return AccessController.doPrivileged(new PrivilegedAction<Method>() {
             public Method run() {
-                try {
-                    final String p = StringUtils.capitalize(propertyName);
-                    try {
-                        return clazz.getMethod("get" + p);
-                    } catch (NoSuchMethodException e) {
-                        return clazz.getMethod("is" + p);
-                    }
-                } catch (NoSuchMethodException e) {
-                    return null;
-                }
+                return doGetGetter(propertyName, clazz);
             }
         });
 
     }
 
+    private static Method doGetGetter(String propertyName, Class<?> clazz) {
+        try {
+            final String p = StringUtils.capitalize(propertyName);
+            try {
+                return clazz.getMethod("get" + p);
+            } catch (NoSuchMethodException e) {
+                return clazz.getMethod("is" + p);
+            }
+        } catch (NoSuchMethodException e) {
+            return null;
+        }
+    }
 
 
     private Class<?> loadClass(final String className) {
-        ClassLoader loader = doPrivileged(SecureActions.getContextClassLoader());
+        ClassLoader loader = Reflection.INSTANCE.getClassLoader(ValidationMappingParser.class);
         if (loader == null)
             loader = getClass().getClassLoader();
 

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java Tue Aug 13 20:26:51 2013
@@ -24,8 +24,7 @@ import org.apache.bval.jsr303.BootstrapC
 import org.apache.bval.jsr303.ConfigurationImpl;
 import org.apache.bval.jsr303.util.IOUtils;
 import org.apache.bval.jsr303.util.IOs;
-import org.apache.bval.jsr303.util.SecureActions;
-import org.apache.bval.util.PrivilegedActions;
+import org.apache.bval.util.reflection.Reflection;
 import org.xml.sax.SAXException;
 
 import javax.validation.ConstraintValidatorFactory;
@@ -103,11 +102,6 @@ public class ValidationParser implements
         return file;
     }
 
-    /**
-     * Process the validation configuration into <code>targetConfig</code>.
-     *
-     * @param targetConfig
-     */
     public static ValidationParser processValidationConfig(final String file, final ConfigurationImpl targetConfig, final boolean ignoreXml) {
         final ValidationParser parser = new ValidationParser();
 
@@ -198,7 +192,7 @@ public class ValidationParser implements
     }
 
     protected static InputStream getInputStream(String path) throws IOException {
-        ClassLoader loader = PrivilegedActions.getClassLoader(ValidationParser.class);
+        ClassLoader loader = Reflection.INSTANCE.getClassLoader(ValidationParser.class);
         InputStream inputStream = loader.getResourceAsStream(path);
 
         if (inputStream != null) {
@@ -222,16 +216,10 @@ public class ValidationParser implements
         return getSchema(VALIDATION_CONFIGURATION_XSD);
     }
 
-    /**
-     * Get a Schema object from the specified resource name.
-     *
-     * @param xsd
-     * @return {@link Schema}
-     */
-    static Schema getSchema(String xsd) {
-        ClassLoader loader = PrivilegedActions.getClassLoader(ValidationParser.class);
-        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-        URL schemaUrl = loader.getResource(xsd);
+    static Schema getSchema(final String xsd) {
+        final ClassLoader loader = Reflection.INSTANCE.getClassLoader(ValidationParser.class);
+        final SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+        final URL schemaUrl = loader.getResource(xsd);
         try {
             return sf.newSchema(schemaUrl);
         } catch (SAXException e) {
@@ -320,26 +308,33 @@ public class ValidationParser implements
     }
 
     private <T> T newInstance(final Class<T> cls) {
+        if (System.getSecurityManager() == null) {
+            return doNewInstance(cls);
+        }
         return AccessController.doPrivileged(new PrivilegedAction<T>() {
             public T run() {
-                try {
-                    try {
-                        final BValExtension.Releasable<T> releasable = BValExtension.inject(cls);
-                        releasables.add(releasable);
-                        return releasable.getInstance();
-                    } catch (final Exception e) {
-                        return cls.newInstance();
-                    } catch (final NoClassDefFoundError error) {
-                        return cls.newInstance();
-                    }
-                } catch (final Exception ex) {
-                    exceptions.add(new ValidationException("Cannot instantiate : " + cls, ex));
-                    return null; // ensure BootstrapConfiguration can be read even if class can't be instantiated
-                }
+                return doNewInstance(cls);
             }
         });
     }
 
+    private <T> T doNewInstance(final Class<T> cls) {
+        try {
+            try {
+                final BValExtension.Releasable<T> releasable = BValExtension.inject(cls);
+                releasables.add(releasable);
+                return releasable.getInstance();
+            } catch (final Exception e) {
+                return cls.newInstance();
+            } catch (final NoClassDefFoundError error) {
+                return cls.newInstance();
+            }
+        } catch (final Exception ex) {
+            exceptions.add(new ValidationException("Cannot instantiate : " + cls, ex));
+            return null; // ensure BootstrapConfiguration can be read even if class can't be instantiated
+        }
+    }
+
     @SuppressWarnings("unchecked")
     private void applyConstraintFactory(ValidationConfigType xmlConfig,
                                         ConfigurationImpl target) {
@@ -379,23 +374,11 @@ public class ValidationParser implements
         }
     }
 
-
-    private static <T> T doPrivileged(final PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
-        }
-    }
-
     private Class<?> loadClass(final String className) {
-        ClassLoader loader = doPrivileged(SecureActions.getContextClassLoader());
-        if (loader == null)
-            loader = ValidationParser.class.getClassLoader();
-
+        final ClassLoader loader = Reflection.INSTANCE.getClassLoader(ValidationParser.class);
         try {
             return Class.forName(className, true, loader);
-        } catch (ClassNotFoundException ex) {
+        } catch (final ClassNotFoundException ex) {
             // TCK check BootstrapConfig is present in all cases
             // so throw next exception later
             exceptions.add(new ValidationException("Unable to load class: " + className, ex));

Modified: bval/branches/bval-11/bval-tck11/pom.xml
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/pom.xml?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-tck11/pom.xml (original)
+++ bval/branches/bval-11/bval-tck11/pom.xml Tue Aug 13 20:26:51 2013
@@ -67,12 +67,12 @@ under the License.
             <scope>provided</scope>
         </dependency>
         -->
-      <dependency>
-        <groupId>org.jboss.spec.javax.interceptor</groupId>
-        <artifactId>jboss-interceptors-api_1.2_spec</artifactId>
-        <version>1.0.0.Alpha1</version>
-        <scope>provided</scope>
-      </dependency>
+        <dependency>
+            <groupId>org.jboss.spec.javax.interceptor</groupId>
+            <artifactId>jboss-interceptors-api_1.2_spec</artifactId>
+            <version>1.0.0.Alpha1</version>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-ejb_3.1_spec</artifactId>
@@ -95,14 +95,6 @@ under the License.
             <version>${project.version}</version>
         </dependency>
 
-        <!-- can be used to test in jse mode but globally it will need a lot of exclusions so not sure it is relevant
-        <dependency>
-          <groupId>org.hibernate.beanvalidation.tck</groupId>
-          <artifactId>beanvalidation-standalone-container-adapter</artifactId>
-          <version>${tck.version}</version>
-          <scope>test</scope>
-        </dependency>
-        -->
         <dependency>
             <groupId>org.jboss.arquillian.container</groupId>
             <artifactId>arquillian-container-test-spi</artifactId>

Modified: bval/branches/bval-11/bval-tck11/work-tests-suite.xml
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/work-tests-suite.xml?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-tck11/work-tests-suite.xml (original)
+++ bval/branches/bval-11/bval-tck11/work-tests-suite.xml Tue Aug 13 20:26:51 2013
@@ -21,9 +21,9 @@ think to add -Dvalidation.provider=org.a
 <suite name="tmp" verbose="1">
   <test name="tmp">
     <classes>
-      <class name="org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.priority.ValidationInterceptorPriorityTest">
+      <class name="org.hibernate.beanvalidation.tck.tests.metadata.ExecutableDescriptorTest">
         <methods>
-
+          <include name="testFindConstraintsForMethodDefinedOnSuperTypeLookingAt" />
         </methods>
       </class>
     </classes>

Modified: bval/branches/bval-11/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java (original)
+++ bval/branches/bval-11/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java Tue Aug 13 20:26:51 2013
@@ -19,7 +19,7 @@ package org.apache.bval.xml;
 import org.apache.bval.MetaBeanManager;
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.model.MetaProperty;
-import org.apache.bval.util.PrivilegedActions;
+import org.apache.bval.util.reflection.Reflection;
 
 import java.util.Map;
 
@@ -45,7 +45,7 @@ public class XMLMetaBeanManager extends 
     }
 
     public void addResourceLoader(String resource) {
-        addLoader(new XMLMetaBeanURLLoader(PrivilegedActions.getClassLoader(getClass()).getResource(resource)));
+        addLoader(new XMLMetaBeanURLLoader(Reflection.INSTANCE.getClassLoader(getClass()).getResource(resource)));
     }
 
     public synchronized void addLoader(XMLMetaBeanLoader loader) {

Modified: bval/branches/bval-11/pom.xml
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/pom.xml?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/pom.xml (original)
+++ bval/branches/bval-11/pom.xml Tue Aug 13 20:26:51 2013
@@ -635,12 +635,12 @@
         <module>bval-core</module>
         <module>bval-xstream</module>
         <module>bval-jsr303</module>
-        <module>bundle</module>
         <module>bval-json</module>
         <module>bval-guice</module>
         <module>bval-tck</module>
         <module>bval-extras</module>
         <module>bval-tck11</module>
+        <!--<module>bundle</module>-->
     </modules>
 
 </project>



Mime
View raw message