You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by rm...@apache.org on 2013/08/13 22:26:52 UTC

svn commit: r1513638 [1/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...

Author: rmannibucau
Date: Tue Aug 13 20:26:51 2013
New Revision: 1513638

URL: http://svn.apache.org/r1513638
Log:
some basic optim - still a lot todo

Added:
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/DefaultReflection.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/SecurityManagerReflection.java
Removed:
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/SecureActions.java
Modified:
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/ConstructorAccess.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/MetaBean.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/BValVersion.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/FieldAccess.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/MethodAccess.java
    bval/branches/bval-11/bval-guice/pom.xml
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationProcessor.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheFactoryContext.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConfigurationImpl.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintAnnotationAttributes.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintDefaults.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintValidation.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/DefaultMessageInterpolator.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/DefaultValidationProviderResolver.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/DefaultTraversableResolver.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/ConstraintDefinitionValidator.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/AnnotationProxy.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/AnnotationProxyBuilder.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationMappingParser.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
    bval/branches/bval-11/bval-tck11/pom.xml
    bval/branches/bval-11/bval-tck11/work-tests-suite.xml
    bval/branches/bval-11/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java
    bval/branches/bval-11/pom.xml

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/ConstructorAccess.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/ConstructorAccess.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/ConstructorAccess.java (original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/ConstructorAccess.java Tue Aug 13 20:26:51 2013
@@ -20,7 +20,6 @@ import org.apache.bval.util.AccessStrate
 
 import java.lang.annotation.ElementType;
 import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
 import java.lang.reflect.Type;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -32,12 +31,16 @@ public class ConstructorAccess extends A
     public ConstructorAccess(final Constructor<?> constructor) {
         this.constructor = constructor;
         if (!constructor.isAccessible()) {
-            run(new PrivilegedAction<Void>() {
-                public Void run() {
-                    constructor.setAccessible(true);
-                    return null;
-                }
-            });
+            if (System.getSecurityManager() == null) {
+                constructor.setAccessible(true);
+            } else {
+                AccessController.doPrivileged(new PrivilegedAction<Void>() {
+                    public Void run() {
+                        constructor.setAccessible(true);
+                        return null;
+                    }
+                });
+            }
         }
     }
 
@@ -79,12 +82,4 @@ public class ConstructorAccess extends A
     public int hashCode() {
         return constructor.hashCode();
     }
-
-    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-core/src/main/java/org/apache/bval/model/MetaBean.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/MetaBean.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/MetaBean.java (original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/MetaBean.java Tue Aug 13 20:26:51 2013
@@ -16,11 +16,15 @@
  */
 package org.apache.bval.model;
 
+import org.apache.bval.util.reflection.Reflection;
+
+import java.beans.Introspector;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -37,55 +41,9 @@ public class MetaBean extends FeaturesCa
     private String name;
     private Class<?> beanClass;
 
-    // TODO: optimize sortings
-
-    private Map<String, MetaProperty> properties = new TreeMap<String, MetaProperty>(new Comparator<String>() { // order of fields to ensure correct failling order
-        public int compare(final String o1, final String o2) {
-            return fieldIndex(o1) - fieldIndex(o2);
-        }
-
-        private int fieldIndex(final String o2) {
-            final Class<?> clazz = getBeanClass();
-
-            int i = 0;
-            Class<?> beanClass1 = clazz;
-            while (beanClass1 != null && beanClass1 != Object.class) {
-                for (final Field f : beanClass1.getDeclaredFields()) {
-                    i++;
-                    if (f.getName().equals(o2)) {
-                        return i;
-                    }
-                }
-                beanClass1 = beanClass1.getSuperclass();
-            }
-
-            if (clazz != null) {
-                final String getter = "get" + Character.toUpperCase(o2.charAt(0)) + o2.substring(1);
-                for (final Method m : clazz.getMethods()) {
-                    i++;
-                    if (m.getName().equals(getter) && m.getParameterTypes().length == 0) {
-                        return i;
-                    }
-                }
-            }
-
-            return Integer.MIN_VALUE; // to avoid collision and false positive in get() due to equals
-        }
-    });
-    private Map<Method, MetaMethod> methods = new TreeMap<Method, MetaMethod>(new Comparator<Method>() {
-        public int compare(final Method o1, final Method o2) {
-            final int i = o1.getName().compareTo(o2.getName());
-            if (i != 0) {
-                return i;
-            }
-            return Arrays.hashCode(o1.getParameterTypes()) - Arrays.hashCode(o2.getParameterTypes());
-        }
-    });
-    private Map<Constructor<?>, MetaConstructor> constructors = new TreeMap<Constructor<?>, MetaConstructor>(new Comparator<Constructor<?>>() {
-        public int compare(final Constructor<?> o1, final Constructor<?> o2) {
-            return Arrays.hashCode(o1.getParameterTypes()) - Arrays.hashCode(o2.getParameterTypes());
-        }
-    });
+    private Map<String, MetaProperty> properties = null;
+    private Map<Method, MetaMethod> methods = null;
+    private Map<Constructor<?>, MetaConstructor> constructors = null;
 
     /**
      * Get the id.
@@ -128,7 +86,7 @@ public class MetaBean extends FeaturesCa
     /**
      * Get the beanClass.
      * 
-     * @return Class<?>
+     * @return Class
      */
     public Class<?> getBeanClass() {
         return beanClass;
@@ -142,6 +100,25 @@ public class MetaBean extends FeaturesCa
      */
     public void setBeanClass(Class<?> beanClass) {
         this.beanClass = beanClass;
+        if (beanClass != null) {
+            // order of fields to ensure correct failling order
+            final Map<String, MetaProperty> oldProperties = properties;
+            final Map<Method, MetaMethod> oldMethods = methods;
+            final Map<Constructor<?>, MetaConstructor> oldConstructors = constructors;
+
+            properties = new TreeMap<String, MetaProperty>(new FieldComparator(beanClass));
+            if (oldProperties != null) {
+                properties.putAll(oldProperties);
+            }
+            methods = new TreeMap<Method, MetaMethod>(new MethodComparator(beanClass));
+            if (oldMethods != null) {
+                methods.putAll(oldMethods);
+            }
+            constructors = new TreeMap<Constructor<?>, MetaConstructor>(new ConstructorComparator(beanClass));
+            if (oldConstructors != null) {
+                constructors.putAll(oldConstructors);
+            }
+        }
     }
 
     /**
@@ -150,22 +127,30 @@ public class MetaBean extends FeaturesCa
      * @return MetaProperty[]
      */
     public MetaProperty[] getProperties() {
+        if (properties == null) {
+            return new MetaProperty[0];
+        }
         return properties.values().toArray(new MetaProperty[this.properties.size()]);
     }
 
     public MetaMethod[] getMethods() {
+        if (methods == null) {
+            return new MetaMethod[0];
+        }
         return methods.values().toArray(new MetaMethod[this.methods.size()]);
     }
 
     public void addMethod(final Method method, final MetaMethod meta) {
+        if (methods == null) {
+            methods = new HashMap<Method, MetaMethod>();
+        }
         methods.put(method, meta);
     }
 
-    public MetaConstructor[] getConstructors() {
-        return constructors.values().toArray(new MetaConstructor[this.constructors.size()]);
-    }
-
     public void addConstructor(final Constructor<?> constructor, final MetaConstructor meta) {
+        if (constructors == null) {
+            constructors = new HashMap<Constructor<?>, MetaConstructor>();
+        }
         constructors.put(constructor, meta);
     }
 
@@ -176,8 +161,8 @@ public class MetaBean extends FeaturesCa
      *            the MetaProperty[] to set
      */
     public void setProperties(MetaProperty[] properties) {
-        this.properties.clear();
-        for (MetaProperty property : properties) {
+        this.properties = new HashMap<String, MetaProperty>();
+        for (final MetaProperty property : properties) {
             this.properties.put(property.getName(), property);
         }
     }
@@ -185,10 +170,13 @@ public class MetaBean extends FeaturesCa
     /**
      * Get the specified {@link MetaProperty}.
      * 
-     * @param name
+     * @param name property name
      * @return MetaProperty found or <code>null</code>
      */
     public MetaProperty getProperty(String name) {
+        if (properties == null) {
+            return null;
+        }
         return this.properties.get(name);
     }
 
@@ -199,6 +187,9 @@ public class MetaBean extends FeaturesCa
      * @return true when at least one of the properties is a relationship
      */
     public boolean hasRelationships() {
+        if (properties == null) {
+            return false;
+        }
         for (MetaProperty property : this.properties.values()) {
             if (property.isRelationship()) {
                 return true;
@@ -208,22 +199,16 @@ public class MetaBean extends FeaturesCa
     }
 
     /**
-     * Learn whether there are any known properties.
-     * 
-     * @return boolean
-     */
-    public boolean hasProperties() {
-        return this.properties.size() > 0;
-    }
-
-    /**
      * bidirectional - set the relationship between a MetaProperty and its parentMetaBean
      * 
-     * @param name
+     * @param name property name
      * @param property
      *            if <code>null</code>, remove
      */
     public void putProperty(String name, MetaProperty property) {
+        if (properties == null) {
+            properties = new HashMap<String, MetaProperty>();
+        }
         if (property == null) {
             this.properties.remove(name);
         } else {        
@@ -267,7 +252,7 @@ public class MetaBean extends FeaturesCa
      * </ul>
      * </p>
      * 
-     * @param bean
+     * @param bean instance
      * @return <code>this</code> or <code>null</code>
      */
     public MetaBean resolveMetaBean(Object bean) {
@@ -275,10 +260,106 @@ public class MetaBean extends FeaturesCa
     }
 
     public MetaMethod getMethod(final Method method) {
+        if (methods == null) {
+            return null;
+        }
         return methods.get(method);
     }
 
     public MetaConstructor getConstructor(final Constructor<?> constructor) {
+        if (constructors == null) {
+            return null;
+        }
         return constructors.get(constructor);
     }
+
+    protected static class FieldComparator implements Comparator<String> {
+        private final Map<String, Integer> fields = new HashMap<String, Integer>();
+
+        protected FieldComparator(final Class<?> beanClass) {
+            int i = 0;
+            Class<?> clazz = beanClass;
+            while (clazz != null && clazz != Object.class) {
+                for (final Field f : Reflection.INSTANCE.getDeclaredFields(clazz)) {
+                    i++;
+                    final String name = f.getName();
+                    if (!fields.containsKey(name)) {
+                        fields.put(name, i);
+                    }
+                }
+                for (final Method m : clazz.getDeclaredMethods()) {
+                    if (m.getName().startsWith("get") && Void.TYPE != m.getReturnType() && m.getParameterTypes().length == 0) {
+                        final String name = Introspector.decapitalize(m.getName().substring("get".length()));
+                        if (!name.isEmpty()) {
+                            i++;
+                            if (!fields.containsKey(name)) {
+                                fields.put(name, i);
+                            }
+                        }
+                    }
+                }
+                clazz = clazz.getSuperclass();
+            }
+        }
+
+        public int compare(final String o1, final String o2) {
+            return fieldIndex(o1) - fieldIndex(o2);
+        }
+
+        private int fieldIndex(final String o2) {
+            final Integer idx = fields.get(o2);
+            if (idx != null) {
+                return idx;
+            }
+            return Integer.MIN_VALUE; // to avoid collision and false positive in get() due to equals
+        }
+    }
+
+    protected static class MethodComparator implements Comparator<Method> {
+        private final Map<Method, Integer> methods = new HashMap<Method, Integer>();
+
+        protected MethodComparator(final Class<?> beanClass) {
+            Class<?> clazz = beanClass;
+            while (clazz != null && clazz != Object.class) {
+                for (final Method m : Reflection.INSTANCE.getDeclaredMethods(clazz)) {
+                    methods.put(m, Arrays.hashCode(m.getParameterTypes()));
+                }
+                clazz = clazz.getSuperclass();
+            }
+        }
+
+        public int compare(final Method o1, final Method o2) {
+            if (o1 == o2) {
+                return 0;
+            }
+
+            final int i = o1.getName().compareTo(o2.getName());
+            if (i != 0) {
+                return i;
+            }
+            return methods.get(o1) - methods.get(o2);
+        }
+    }
+
+    protected static class ConstructorComparator implements Comparator<Constructor<?>> {
+        private final Map<Constructor<?>, Integer> constructors = new HashMap<Constructor<?>, Integer>();
+
+        protected ConstructorComparator(final Class<?> beanClass) {
+            for (final Constructor<?> c : Reflection.INSTANCE.getDeclaredConstructors(beanClass)) {
+                constructors.put(c, Arrays.hashCode(c.getParameterTypes()));
+            }
+        }
+
+        public int compare(final Constructor<?> o1, final Constructor<?> o2) {
+            if (o1 == o2) {
+                return 0;
+            }
+
+            final int i = o1.getName().compareTo(o2.getName());
+            if (i != 0) {
+                return i;
+            }
+            return constructors.get(o1) - constructors.get(o2);
+        }
+    }
 }

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/BValVersion.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/BValVersion.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/BValVersion.java (original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/BValVersion.java Tue Aug 13 20:26:51 2013
@@ -18,8 +18,10 @@
  */
 package org.apache.bval.util;
 
-import java.io.InputStream;
+import org.apache.bval.util.reflection.Reflection;
+
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Properties;
 import java.util.StringTokenizer;
 
@@ -168,7 +170,7 @@ public class BValVersion {
 
         buf.append("java.class.path:\n");
         StringTokenizer tok = new StringTokenizer(
-            PrivilegedActions.getProperty("java.class.path"));
+            Reflection.INSTANCE.getProperty("java.class.path"));
         while (tok.hasMoreTokens()) {
             buf.append("\t").append(tok.nextToken());
             buf.append("\n");
@@ -190,6 +192,6 @@ public class BValVersion {
 
     private StringBuilder appendProperty(String prop, StringBuilder buf) {
         return buf.append(prop).append(": ").append(
-            PrivilegedActions.getProperty(prop));
+            Reflection.INSTANCE.getProperty(prop));
     }
 }

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/FieldAccess.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/FieldAccess.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/FieldAccess.java (original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/FieldAccess.java Tue Aug 13 20:26:51 2013
@@ -36,12 +36,16 @@ public class FieldAccess extends AccessS
     public FieldAccess(final Field field) {
         this.field = field;
         if (!field.isAccessible()) {
-            run(new PrivilegedAction<Void>() {
-                public Void run() {
-                    field.setAccessible(true);
-                    return null;
-                }
-            });
+            if (System.getSecurityManager() == null) {
+                field.setAccessible(true);
+            } else {
+                AccessController.doPrivileged(new PrivilegedAction<Void>() {
+                    public Void run() {
+                        field.setAccessible(true);
+                        return null;
+                    }
+                });
+            }
         }
     }
 
@@ -102,12 +106,4 @@ public class FieldAccess extends AccessS
     public int hashCode() {
         return field.hashCode();
     }
-
-    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-core/src/main/java/org/apache/bval/util/MethodAccess.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/MethodAccess.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/MethodAccess.java (original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/MethodAccess.java Tue Aug 13 20:26:51 2013
@@ -48,12 +48,16 @@ public class MethodAccess extends Access
         this.method = method;
         this.propertyName = propertyName;
         if (!method.isAccessible()) {
-            run( new PrivilegedAction<Void>() {
-                public Void run() {
-                    method.setAccessible(true);
-                    return null;
-                }
-            });
+            if (System.getSecurityManager() == null) {
+                method.setAccessible(true);
+            } else {
+                AccessController.doPrivileged(new PrivilegedAction<Void>() {
+                    public Void run() {
+                        method.setAccessible(true);
+                        return null;
+                    }
+                });
+            }
         }
     }
 
@@ -144,12 +148,4 @@ public class MethodAccess extends Access
     public int hashCode() {
         return method.hashCode();
     }
-
-    private static <T> T run(PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
-        }
-    }
 }

Added: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/DefaultReflection.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/DefaultReflection.java?rev=1513638&view=auto
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/DefaultReflection.java (added)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/DefaultReflection.java Tue Aug 13 20:26:51 2013
@@ -0,0 +1,135 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bval.util.reflection;
+
+import org.apache.commons.lang3.ClassUtils;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+public class DefaultReflection implements Reflection {
+    public Class<?> getClass(final ClassLoader classLoader, final String className) throws Exception {
+        return ClassUtils.getClass(classLoader, className, true);
+    }
+
+    public Object getAnnotationValue(final Annotation annotation, final String name) throws IllegalAccessException, InvocationTargetException {
+        Method valueMethod;
+        try {
+            valueMethod = annotation.annotationType().getDeclaredMethod(name);
+        } catch (final NoSuchMethodException ex) {
+            // do nothing
+            valueMethod = null;
+        }
+        if (null != valueMethod) {
+            if (!valueMethod.isAccessible()) {
+                valueMethod.setAccessible(true);
+            }
+            return valueMethod.invoke(annotation);
+        }
+        return null;
+    }
+
+    public ClassLoader getClassLoader(final Class<?> clazz) {
+        final ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        if (cl != null) {
+            return cl;
+        }
+        return clazz.getClassLoader();
+    }
+
+    public String getProperty(final String name) {
+        return System.getProperty(name);
+    }
+
+    public Field getDeclaredField(final Class<?> clazz, final String fieldName) {
+        final Field f;
+        try {
+            f = clazz.getDeclaredField(fieldName);
+        } catch (final NoSuchFieldException e) {
+            return null;
+        }
+        setAccessibility(f);
+        return f;
+    }
+
+    public Field[] getDeclaredFields(final Class<?> clazz) {
+        final Field[] fields = clazz.getDeclaredFields();
+        if (fields.length > 0) {
+            for (final Field f : fields) {
+                if (!f.isAccessible()) {
+                    f.setAccessible(true);
+                }
+            }
+        }
+        return fields;
+    }
+
+    public Constructor<?> getDeclaredConstructor(final Class<?> clazz, final Class<?>... parameters) {
+        try {
+            return clazz.getDeclaredConstructor(parameters);
+        } catch (final NoSuchMethodException e) {
+            return null;
+        }
+    }
+
+    public Method getDeclaredMethod(final Class<?> clazz, final String name, final Class<?>... parameters) {
+        try {
+            return clazz.getDeclaredMethod(name, parameters);
+        } catch (final NoSuchMethodException e) {
+            return null;
+        }
+    }
+
+    public Method[] getDeclaredMethods(final Class<?> clazz) {
+        return clazz.getDeclaredMethods();
+    }
+
+    public Constructor<?>[] getDeclaredConstructors(final Class<?> clazz) {
+        return clazz.getDeclaredConstructors();
+    }
+
+    public Method getPublicMethod(final Class<?> clazz, final String methodName) {
+        try {
+            return clazz.getMethod(methodName);
+        } catch (final NoSuchMethodException e) {
+            return null;
+        }
+    }
+
+    public <T> T newInstance(final Class<T> cls) {
+        try {
+            return cls.newInstance();
+        } catch (final Exception ex) {
+            throw new RuntimeException("Cannot instantiate : " + cls, ex);
+        }
+    }
+
+    private static void setAccessibility(final Field field) {
+        // FIXME 2011-03-27 jw:
+        // - Why not simply call field.setAccessible(true)?
+        // - Fields can not be abstract.
+        if (!Modifier.isPublic(field.getModifiers()) || (
+            Modifier.isPublic(field.getModifiers()) &&
+                Modifier.isAbstract(field.getModifiers()))) {
+            field.setAccessible(true);
+        }
+    }
+}

Added: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java?rev=1513638&view=auto
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java (added)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java Tue Aug 13 20:26:51 2013
@@ -0,0 +1,64 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bval.util.reflection;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public interface Reflection {
+    static final Reflection INSTANCE = ReflectionFactory.newInstance();
+
+    Class<?> getClass(final ClassLoader classLoader, final String className) throws Exception;
+
+    Object getAnnotationValue(final Annotation annotation, final String name) throws IllegalAccessException, InvocationTargetException;
+
+    ClassLoader getClassLoader(final Class<?> clazz);
+
+    String getProperty(final String name);
+
+    Field getDeclaredField(final Class<?> clazz, final String fieldName);
+
+    Field[] getDeclaredFields(final Class<?> clazz);
+
+    Constructor<?> getDeclaredConstructor(final Class<?> clazz, final Class<?>... parameters);
+
+    Method getDeclaredMethod(final Class<?> clazz, final String name, final Class<?>... parameters);
+
+    Method[] getDeclaredMethods(final Class<?> clazz);
+
+    Constructor<?>[] getDeclaredConstructors(final Class<?> clazz);
+
+    Method getPublicMethod(final Class<?> clazz, final String methodName);
+
+    <T> T newInstance(final Class<T> cls);
+
+    public static class ReflectionFactory {
+        public static Reflection newInstance() {
+            if (System.getSecurityManager() != null) {
+                return new SecurityManagerReflection();
+            }
+            return new DefaultReflection();
+        }
+
+        private ReflectionFactory() {
+            // no-op
+        }
+    }
+}

Added: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/SecurityManagerReflection.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/SecurityManagerReflection.java?rev=1513638&view=auto
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/SecurityManagerReflection.java (added)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/SecurityManagerReflection.java Tue Aug 13 20:26:51 2013
@@ -0,0 +1,190 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bval.util.reflection;
+
+import java.lang.annotation.Annotation;
+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.security.PrivilegedExceptionAction;
+
+public class SecurityManagerReflection extends DefaultReflection implements Reflection {
+    /**
+     * Perform action with AccessController.doPrivileged() if security if enabled.
+     *
+     * @param action - the action to run
+     * @return result of running the action
+     */
+    // should not be called by just anyone; do not increase access
+    private static <T> T run(PrivilegedAction<T> action) {
+        if (System.getSecurityManager() != null) {
+            return AccessController.doPrivileged(action);
+        } else {
+            return action.run();
+        }
+    }
+
+    /**
+     * Perform action with AccessController.doPrivileged() if security if enabled.
+     *
+     * @param action - the action to run
+     * @return result of running the action
+     */
+    // should not be called by just anyone; do not increase access
+    private static <T> T run(final PrivilegedExceptionAction<T> action) throws Exception {
+        if (System.getSecurityManager() != null) {
+            return AccessController.doPrivileged(action);
+        } else {
+            return action.run();
+        }
+    }
+
+    /**
+     * Perform AccessController.doPrivileged() action for ClassUtil.getClass()
+     *
+     * @return Class
+     * @exception Exception
+     */
+    public Class<?> getClass(final ClassLoader classLoader, final String className) throws Exception {
+        return run(new PrivilegedExceptionAction<Class<?>>() {
+            public Class<?> run() throws Exception {
+                return SecurityManagerReflection.super.getClass(classLoader, className);
+            }
+        });
+    }
+
+    /**
+     * Return a PrivilegedAction object for clazz.getDeclaredMethod().invoke().
+     *
+     * Requires security policy
+     *  'permission java.lang.RuntimePermission "accessDeclaredMembers";'
+     *  'permission java.lang.reflect.ReflectPermission "suppressAccessChecks";'
+     *
+     * @return Object
+     * @exception IllegalAccessException, InvocationTargetException
+     */
+    public Object getAnnotationValue(final Annotation annotation, final String name) throws IllegalAccessException, InvocationTargetException {
+        return run(new PrivilegedAction<Object>() {
+            public Object run() {
+                try {
+                    return SecurityManagerReflection.super.getAnnotationValue(annotation, name);
+                } catch (final Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        });
+    }
+
+    /**
+     * Return a PrivilegeAction object for clazz.getClassloader().
+     *
+     * Requires security policy:
+     *   'permission java.lang.RuntimePermission "getClassLoader";'
+     *
+     * @return Classloader
+     */
+    public ClassLoader getClassLoader(final Class<?> clazz) {
+        return run(new PrivilegedAction<ClassLoader>() {
+            public ClassLoader run() {
+                return SecurityManagerReflection.super.getClassLoader(clazz);
+            }
+        });
+    }
+
+    /**
+     * Return a PrivilegeAction object for System.getProperty().
+     *
+     * Requires security policy:
+     *   'permission java.util.PropertyPermission "read";'
+     *
+     * @return String
+     */
+    public final String getProperty(final String name) {
+        return run(new PrivilegedAction<String>() {
+            public String run() {
+                return SecurityManagerReflection.super.getProperty(name);
+            }
+        });
+    }
+
+    public Field getDeclaredField(final Class<?> clazz, final String fieldName) {
+        return run(new PrivilegedAction<Field>() {
+            public Field run() {
+                return SecurityManagerReflection.super.getDeclaredField(clazz, fieldName);
+            }
+        });
+    }
+
+    public Field[] getDeclaredFields(final Class<?> clazz) {
+        return run(new PrivilegedAction<Field[]>() {
+            public Field[] run() {
+                return SecurityManagerReflection.super.getDeclaredFields(clazz);
+            }
+        });
+    }
+
+    public Constructor<?> getDeclaredConstructor(final Class<?> clazz, final Class<?>... parameters) {
+        return run(new PrivilegedAction<Constructor<?>>() {
+            public Constructor<?> run() {
+                return SecurityManagerReflection.super.getDeclaredConstructor(clazz, parameters);
+            }
+        });
+    }
+
+    public Method getDeclaredMethod(final Class<?> clazz, final String name, final Class<?>... parameters) {
+        return run(new PrivilegedAction<Method>() {
+            public Method run() {
+                return SecurityManagerReflection.super.getDeclaredMethod(clazz, name, parameters);
+            }
+        });
+    }
+
+    public Method[] getDeclaredMethods(final Class<?> clazz) {
+        return run(new PrivilegedAction<Method[]>() {
+            public Method[] run() {
+                return SecurityManagerReflection.super.getDeclaredMethods(clazz);
+            }
+        });
+    }
+
+    public Constructor<?>[] getDeclaredConstructors(final Class<?> clazz) {
+        return run(new PrivilegedAction<Constructor<?>[]>() {
+            public Constructor<?>[] run() {
+                return SecurityManagerReflection.super.getDeclaredConstructors(clazz);
+            }
+        });
+    }
+
+    public Method getPublicMethod(final Class<?> clazz, final String methodName) {
+        return run(new PrivilegedAction<Method>() {
+            public Method run() {
+                return SecurityManagerReflection.super.getPublicMethod(clazz, methodName);
+            }
+        });
+    }
+
+    public <T> T newInstance(final Class<T> cls) {
+        return run(new PrivilegedAction<T>() {
+            public T run() {
+                return SecurityManagerReflection.super.newInstance(cls);
+            }
+        });
+    }
+}

Modified: bval/branches/bval-11/bval-guice/pom.xml
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-guice/pom.xml?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-guice/pom.xml (original)
+++ bval/branches/bval-11/bval-guice/pom.xml Tue Aug 13 20:26:51 2013
@@ -39,7 +39,12 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.bval</groupId>
-            <artifactId>org.apache.bval.bundle</artifactId>
+            <artifactId>bval-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.bval</groupId>
+            <artifactId>bval-jsr303</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationConstraintBuilder.java Tue Aug 13 20:26:51 2013
@@ -19,17 +19,15 @@
 package org.apache.bval.jsr303;
 
 import org.apache.bval.jsr303.groups.GroupsComputer;
-import org.apache.bval.jsr303.util.SecureActions;
 import org.apache.bval.jsr303.xml.AnnotationProxyBuilder;
 import org.apache.bval.util.AccessStrategy;
+import org.apache.bval.util.reflection.Reflection;
 
-import javax.annotation.processing.SupportedAnnotationTypes;
 import javax.validation.Constraint;
 import javax.validation.ConstraintDeclarationException;
 import javax.validation.ConstraintDefinitionException;
 import javax.validation.ConstraintTarget;
 import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
 import javax.validation.OverridesAttribute;
 import javax.validation.Payload;
 import javax.validation.ReportAsSingleViolation;
@@ -85,54 +83,63 @@ final class AnnotationConstraintBuilder<
     /** build attributes, payload, groups from 'annotation' */
     private void buildFromAnnotation() {
         if (constraintValidation.getAnnotation() != null) {
-            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)
-                        if (method.getParameterTypes().length == 0) {
-                            try {
-                                final String name = method.getName();
-                                if (ConstraintAnnotationAttributes.PAYLOAD.getAttributeName().equals(name)) {
-                                    buildPayload(method);
-                                } else if (ConstraintAnnotationAttributes.GROUPS.getAttributeName().equals(name)) {
-                                    buildGroups(method);
-                                } else if (ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.getAttributeName().equals(name)) {
-                                    buildValidationAppliesTo(method);
-                                } else if (name.startsWith("valid")) {
-                                    throw new ConstraintDefinitionException("constraints parameters can't start with valid: " + name);
-                                } else {
-                                    constraintValidation.getAttributes().put(name, method.invoke(constraintValidation.getAnnotation()));
-                                }
-                            } catch (final ConstraintDefinitionException cde) {
-                                throw cde;
-                            } catch (final Exception e) { // do nothing
-                                log.log(Level.WARNING, String.format("Error processing annotation: %s ", constraintValidation.getAnnotation()), e);
-                            }
-                        }
-                    }
-
-                    // valid validationAppliesTo
-                    final Constraint annotation = constraintValidation.getAnnotation().annotationType().getAnnotation(Constraint.class);
-                    if (annotation == null) {
+            if (System.getSecurityManager() == null) {
+                doBuildFromAnnotations();
+            } else {
+                AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                    public Object run() {
+                        doBuildFromAnnotations();
                         return null;
                     }
+                });
+            }
+        }
+    }
+
+    private void doBuildFromAnnotations() {
+        final Class<? extends Annotation> annotationType = constraintValidation.getAnnotation().annotationType();
 
-                    final Pair validationTarget = computeValidationTarget(annotation.validatedBy());
-                    for (final Annotation a : constraintValidation.getAnnotation().annotationType().getAnnotations()) {
-                        final Constraint inheritedConstraint = a.annotationType().getAnnotation(Constraint.class);
-                        if (inheritedConstraint != null && !a.annotationType().getName().startsWith("javax.validation.constraints.")) {
-                            final Pair validationTargetInherited = computeValidationTarget(inheritedConstraint.validatedBy());
-                            if ((validationTarget.a > 0 && validationTargetInherited.b > 0 && validationTarget.b == 0)
-                                    || (validationTarget.b > 0 && validationTargetInherited.a > 0 && validationTarget.a == 0)) {
-                                throw new ConstraintDefinitionException("Parent and child constraint have different targets");
-                            }
-                        }
+        for (final Method method : Reflection.INSTANCE.getDeclaredMethods(annotationType)) {
+            // groups + payload must also appear in attributes (also
+            // checked by TCK-Tests)
+            if (method.getParameterTypes().length == 0) {
+                try {
+                    final String name = method.getName();
+                    if (ConstraintAnnotationAttributes.PAYLOAD.getAttributeName().equals(name)) {
+                        buildPayload(method);
+                    } else if (ConstraintAnnotationAttributes.GROUPS.getAttributeName().equals(name)) {
+                        buildGroups(method);
+                    } else if (ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.getAttributeName().equals(name)) {
+                        buildValidationAppliesTo(method);
+                    } else if (name.startsWith("valid")) {
+                        throw new ConstraintDefinitionException("constraints parameters can't start with valid: " + name);
+                    } else {
+                        constraintValidation.getAttributes().put(name, method.invoke(constraintValidation.getAnnotation()));
                     }
+                } catch (final ConstraintDefinitionException cde) {
+                    throw cde;
+                } catch (final Exception e) { // do nothing
+                    log.log(Level.WARNING, String.format("Error processing annotation: %s ", constraintValidation.getAnnotation()), e);
+                }
+            }
+        }
+
+        // valid validationAppliesTo
+        final Constraint annotation = annotationType.getAnnotation(Constraint.class);
+        if (annotation == null) {
+            return;
+        }
 
-                    return null;
+        final Pair validationTarget = computeValidationTarget(annotation.validatedBy());
+        for (final Annotation a : annotationType.getAnnotations()) {
+            final Constraint inheritedConstraint = a.annotationType().getAnnotation(Constraint.class);
+            if (inheritedConstraint != null && !a.annotationType().getName().startsWith("javax.validation.constraints.")) {
+                final Pair validationTargetInherited = computeValidationTarget(inheritedConstraint.validatedBy());
+                if ((validationTarget.a > 0 && validationTargetInherited.b > 0 && validationTarget.b == 0)
+                        || (validationTarget.b > 0 && validationTargetInherited.a > 0 && validationTarget.a == 0)) {
+                    throw new ConstraintDefinitionException("Parent and child constraint have different targets");
                 }
-            });
+            }
         }
     }
 
@@ -177,8 +184,8 @@ final class AnnotationConstraintBuilder<
         }
     }
 
-    private void buildGroups(Method method) throws IllegalAccessException, InvocationTargetException {
-        Object raw = method.invoke(constraintValidation.getAnnotation());
+    private void buildGroups(final Method method) throws IllegalAccessException, InvocationTargetException {
+        final Object raw = method.invoke(constraintValidation.getAnnotation());
         Class<?>[] garr;
         if (raw instanceof Class<?>) {
             garr = new Class[] { (Class<?>) raw };
@@ -189,9 +196,9 @@ final class AnnotationConstraintBuilder<
         }
 
         if (garr == null || garr.length == 0) {
-            garr = GroupsComputer.getDefaultGroupArray();
+            garr = GroupsComputer.DEFAULT_GROUP;
         }
-        constraintValidation.setGroups(new HashSet<Class<?>>(Arrays.asList(garr)));
+        constraintValidation.setGroups(garr);
     }
 
     @SuppressWarnings("unchecked")
@@ -203,7 +210,7 @@ final class AnnotationConstraintBuilder<
             payloadSet = Collections.<Class<? extends Payload>> emptySet();
         } else {
             payloadSet = new HashSet<Class<? extends Payload>>(payload_raw.length);
-            payloadSet.addAll(Arrays.asList(payload_raw));
+            Collections.addAll(payloadSet, payload_raw);
         }
         constraintValidation.setPayload(payloadSet);
     }
@@ -344,14 +351,6 @@ final class AnnotationConstraintBuilder<
         }
     }
 
-    private static <T> T run(PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
-        }
-    }
-
     private static class Pair {
         private int a;
         private int b;

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationProcessor.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationProcessor.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationProcessor.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/AnnotationProcessor.java Tue Aug 13 20:26:51 2013
@@ -18,15 +18,12 @@
  */
 package org.apache.bval.jsr303;
 
-import org.apache.bval.jsr303.groups.Group;
-import org.apache.bval.jsr303.groups.GroupConversionDescriptorImpl;
 import org.apache.bval.jsr303.util.ConstraintDefinitionValidator;
-import org.apache.bval.jsr303.util.SecureActions;
 import org.apache.bval.model.Features;
 import org.apache.bval.model.Meta;
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.util.AccessStrategy;
-import org.apache.bval.util.PropertyAccess;
+import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.ClassUtils;
 import org.apache.commons.lang3.reflect.TypeUtils;
@@ -95,33 +92,17 @@ public final class AnnotationProcessor {
         AccessStrategy access, AppendValidation appender) throws IllegalAccessException, InvocationTargetException {
 
         boolean changed = false;
-        for (Annotation annotation : element.getDeclaredAnnotations()) {
+        for (final Annotation annotation : element.getDeclaredAnnotations()) {
+            final Class<?> type = annotation.annotationType();
+            if (type.getName().startsWith("java.lang.annotation")) {
+                continue;
+            }
             changed |= processAnnotation(annotation, prop, owner, access, appender, true);
         }
         return changed;
     }
 
     /**
-     * Convenience method to process a single class-level annotation.
-     * 
-     * @param <A>
-     *            annotation type
-     * @param annotation
-     *            to process
-     * @param owner
-     *            bean type
-     * @param appender
-     *            handling accumulation
-     * @return whether any processing took place
-     * @throws IllegalAccessException
-     * @throws InvocationTargetException
-     */
-    public final <A extends Annotation> boolean processAnnotation(A annotation, Class<?> owner, AppendValidation appender)
-        throws IllegalAccessException, InvocationTargetException {
-        return processAnnotation(annotation, null, owner, null, appender, true);
-    }
-
-    /**
      * Process a single annotation.
      * 
      * @param <A>
@@ -176,7 +157,7 @@ public final class AnnotationProcessor {
          * annotated by @Constraint) whose value element has a return type of an
          * array of constraint annotations in a special way.
          */
-        final Object result = SecureActions.getAnnotationValue(annotation, ConstraintAnnotationAttributes.VALUE.getAttributeName());
+        final Object result = Reflection.INSTANCE.getAnnotationValue(annotation, ConstraintAnnotationAttributes.VALUE.getAttributeName());
         if (result instanceof Annotation[]) {
             boolean changed = false;
             for (final Annotation each : (Annotation[]) result) {

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheFactoryContext.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheFactoryContext.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheFactoryContext.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheFactoryContext.java Tue Aug 13 20:26:51 2013
@@ -18,32 +18,31 @@
  */
 package org.apache.bval.jsr303;
 
-import java.lang.reflect.Constructor;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.ConstraintValidatorFactory;
-import javax.validation.MessageInterpolator;
-import javax.validation.ParameterNameProvider;
-import javax.validation.TraversableResolver;
-import javax.validation.ValidationException;
-import javax.validation.Validator;
-import javax.validation.ValidatorContext;
-
 import org.apache.bval.IntrospectorMetaBeanFactory;
 import org.apache.bval.MetaBeanBuilder;
 import org.apache.bval.MetaBeanFactory;
 import org.apache.bval.MetaBeanFinder;
 import org.apache.bval.MetaBeanManager;
-import org.apache.bval.jsr303.util.SecureActions;
+import org.apache.bval.util.reflection.Reflection;
 import org.apache.bval.xml.XMLMetaBeanBuilder;
 import org.apache.bval.xml.XMLMetaBeanFactory;
 import org.apache.bval.xml.XMLMetaBeanManager;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.reflect.ConstructorUtils;
 
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.ParameterNameProvider;
+import javax.validation.TraversableResolver;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
+import java.lang.reflect.Constructor;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * Description: Represents the context that is used to create
  * <code>ClassValidator</code> instances.<br/>
@@ -60,7 +59,7 @@ public class ApacheFactoryContext implem
     /**
      * Create a new ApacheFactoryContext instance.
      * 
-     * @param factory
+     * @param factory validator factory
      */
     public ApacheFactoryContext(ApacheValidatorFactory factory) {
         this.factory = factory;
@@ -70,8 +69,8 @@ public class ApacheFactoryContext implem
     /**
      * Create a new ApacheFactoryContext instance.
      * 
-     * @param factory
-     * @param metaBeanFinder
+     * @param factory validator factory
+     * @param metaBeanFinder meta finder
      */
     protected ApacheFactoryContext(ApacheValidatorFactory factory, MetaBeanFinder metaBeanFinder) {
         this.factory = factory;
@@ -240,26 +239,32 @@ public class ApacheFactoryContext implem
     }
 
     private <F extends MetaBeanFactory> F createMetaBeanFactory(final Class<F> cls) {
-        return run(new PrivilegedAction<F>() {
-
+        if (System.getSecurityManager() == null) {
+            return doCreateMetaBeanFactory(cls);
+        }
+        return AccessController.doPrivileged(new PrivilegedAction<F>() {
             public F run() {
-                try {
-                    Constructor<F> c = ConstructorUtils.getMatchingAccessibleConstructor(cls, ApacheFactoryContext.this.getClass());
-                    if (c != null) {
-                        return c.newInstance(ApacheFactoryContext.this);
-                    }
-                    c = ConstructorUtils.getMatchingAccessibleConstructor(cls, getFactory().getClass());
-                    if (c != null) {
-                        return c.newInstance(getFactory());
-                    }
-                    return cls.newInstance();
-                } catch (Exception e) {
-                    throw new ValidationException(e);
-                }
+                return doCreateMetaBeanFactory(cls);
             }
         });
     }
 
+    private <F extends MetaBeanFactory> F doCreateMetaBeanFactory(final Class<F> cls) {
+        try {
+            Constructor<F> c = ConstructorUtils.getMatchingAccessibleConstructor(cls, ApacheFactoryContext.this.getClass());
+            if (c != null) {
+                return c.newInstance(ApacheFactoryContext.this);
+            }
+            c = ConstructorUtils.getMatchingAccessibleConstructor(cls, getFactory().getClass());
+            if (c != null) {
+                return c.newInstance(getFactory());
+            }
+            return cls.newInstance();
+        } catch (Exception e) {
+            throw new ValidationException(e);
+        }
+    }
+
     /**
      * separate class to prevent the classloader to immediately load optional
      * classes: XMLMetaBeanManager, XMLMetaBeanFactory, XMLMetaBeanBuilder that
@@ -275,7 +280,7 @@ public class ApacheFactoryContext implem
          * Create the {@link MetaBeanManager} to process JSR303 XML. Requires
          * bval-xstream at RT.
          * 
-         * @param builders
+         * @param builders meta bean builders
          * @return {@link MetaBeanManager}
          */
         // NOTE - We return MetaBeanManager instead of XMLMetaBeanManager to
@@ -287,31 +292,11 @@ public class ApacheFactoryContext implem
         }
     }
 
-    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 = getClass().getClassLoader();
-
         try {
-            return Class.forName(className, true, loader);
+            return Class.forName(className, true, Reflection.INSTANCE.getClassLoader(ApacheFactoryContext.class));
         } catch (ClassNotFoundException ex) {
             throw new ValidationException("Unable to load class: " + className, ex);
         }
     }
-
-    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/ApacheValidatorFactory.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java Tue Aug 13 20:26:51 2013
@@ -22,6 +22,7 @@ import org.apache.bval.jsr303.xml.Annota
 import org.apache.bval.jsr303.xml.MetaConstraint;
 import org.apache.bval.jsr303.xml.ValidationMappingParser;
 import org.apache.bval.util.AccessStrategy;
+import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.ClassUtils;
 
@@ -298,15 +299,11 @@ public class ApacheValidatorFactory impl
     }
 
     private <T> T newInstance(final Class<T> cls) {
-        return AccessController.doPrivileged(new PrivilegedAction<T>() {
-            public T run() {
-                try {
-                    return cls.newInstance();
-                } catch (final Exception ex) {
-                    throw new ValidationException("Cannot instantiate : " + cls, ex);
-                }
-            }
-        });
+        try {
+            return Reflection.INSTANCE.newInstance(cls);
+        } catch (final RuntimeException e) {
+            throw new ValidationException(e.getCause());
+        }
     }
 
     /**

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/BeanDescriptorImpl.java Tue Aug 13 20:26:51 2013
@@ -22,7 +22,7 @@ import org.apache.bval.Validate;
 import org.apache.bval.jsr303.groups.Group;
 import org.apache.bval.jsr303.groups.GroupConversionDescriptorImpl;
 import org.apache.bval.jsr303.util.ClassHelper;
-import org.apache.bval.jsr303.util.SecureActions;
+import org.apache.bval.jsr303.xml.AnnotationIgnores;
 import org.apache.bval.model.Features;
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.model.MetaConstructor;
@@ -31,6 +31,7 @@ import org.apache.bval.model.MetaParamet
 import org.apache.bval.model.MetaProperty;
 import org.apache.bval.model.Validation;
 import org.apache.bval.util.AccessStrategy;
+import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.ClassUtils;
 
 import javax.validation.Constraint;
@@ -72,6 +73,8 @@ import java.util.concurrent.CopyOnWriteA
  */
 public class BeanDescriptorImpl extends ElementDescriptorImpl implements BeanDescriptor {
     private static final CopyOnWriteArraySet<ConstraintValidation<?>> NO_CONSTRAINTS = new CopyOnWriteArraySet<ConstraintValidation<?>>();
+    private static final Validation[] EMPTY_VALIDATION = new Validation[0];
+
     /**
      * The {@link ApacheFactoryContext} (not) used by this
      * {@link BeanDescriptorImpl}
@@ -97,7 +100,7 @@ public class BeanDescriptorImpl extends 
         Class<?> current = prop.getParentMetaBean().getBeanClass();
         while (current != null && current != Object.class && (!methodFound || !fieldFound)) {
             if (!fieldFound) {
-                final Field field = SecureActions.getDeclaredField(current, prop.getName()).run();
+                final Field field = Reflection.INSTANCE.getDeclaredField(current, prop.getName());
                 if (field != null) {
                     final ConvertGroup.List convertGroupList = field.getAnnotation(ConvertGroup.List.class);
                     if (convertGroupList != null) {
@@ -117,8 +120,8 @@ public class BeanDescriptorImpl extends 
             if (!methodFound) {
                 final String name = Character.toUpperCase(prop.getName().charAt(0)) + prop.getName().substring(1);
                 for (final Method method : Arrays.asList(
-                        SecureActions.getDeclaredMethod(current, "is" + name).run(),
-                        SecureActions.getDeclaredMethod(current, "get" + name).run())) {
+                                    Reflection.INSTANCE.getDeclaredMethod(current, "is" + name),
+                                    Reflection.INSTANCE.getDeclaredMethod(current, "get" + name))) {
 
                     if (method != null) {
                         final ConvertGroup.List convertGroupList = method.getAnnotation(ConvertGroup.List.class);
@@ -378,26 +381,28 @@ public class BeanDescriptorImpl extends 
     }
 
     private void buildConstructorConstraints() throws InvocationTargetException, IllegalAccessException {
-        for (final Constructor<?> cons : SecureActions.getDeclaredConstructors(getMetaBean().getBeanClass()).run()) {
+        for (final Constructor<?> cons : Reflection.INSTANCE.getDeclaredConstructors(getMetaBean().getBeanClass())) {
             final ConstructorDescriptorImpl consDesc = new ConstructorDescriptorImpl(getMetaBean(), new Validation[0]);
             contructorConstraints.put(cons, consDesc);
 
             final List<String> names = factoryContext.getParameterNameProvider().getParameterNames(cons);
             final boolean isInnerClass = cons.getDeclaringClass().getEnclosingClass() != null && !Modifier.isStatic(cons.getDeclaringClass().getModifiers());
 
+            final AnnotationIgnores annotationIgnores = factoryContext.getFactory().getAnnotationIgnores();
+
             {
                 final Annotation[][] paramsAnnos = cons.getParameterAnnotations();
 
                 int idx = 0;
                 if (isInnerClass) { // paramsAnnos.length = parameterTypes.length - 1 in this case
-                    final ParameterDescriptorImpl paramDesc = new ParameterDescriptorImpl(getMetaBean(), new Validation[0], names.get(idx));
+                    final ParameterDescriptorImpl paramDesc = new ParameterDescriptorImpl(getMetaBean(), EMPTY_VALIDATION, names.get(idx));
                     consDesc.getParameterDescriptors().add(paramDesc);
                     idx++;
                 }
 
                 for (final Annotation[] paramAnnos : paramsAnnos) {
-                    if (factoryContext.getFactory().getAnnotationIgnores().isIgnoreAnnotationOnParameter(cons, idx)) {
-                        consDesc.getParameterDescriptors().add(new ParameterDescriptorImpl(metaBean, new Validation[0], names.get(idx)));
+                    if (annotationIgnores.isIgnoreAnnotationOnParameter(cons, idx)) {
+                        consDesc.getParameterDescriptors().add(new ParameterDescriptorImpl(metaBean, EMPTY_VALIDATION, names.get(idx)));
                     } else if (cons.getParameterTypes().length > idx) {
                         ParameterAccess access = new ParameterAccess(cons.getParameterTypes()[idx], idx);
                         consDesc.addValidations(processAnnotations(consDesc, paramAnnos, access, idx, names.get(idx)).getValidations());
@@ -405,7 +410,7 @@ public class BeanDescriptorImpl extends 
                     idx++;
                 }
 
-                if (!factoryContext.getFactory().getAnnotationIgnores().isIgnoreAnnotations(cons)) {
+                if (!annotationIgnores.isIgnoreAnnotations(cons)) {
                     for (final Annotation anno : cons.getAnnotations()) {
                         if (!Valid.class.isInstance(anno)) {
                             processAnnotations(null, consDesc, cons.getDeclaringClass(), anno);
@@ -416,10 +421,10 @@ public class BeanDescriptorImpl extends 
                 }
             }
 
-            if (factoryContext.getFactory().getAnnotationIgnores().isIgnoreAnnotationOnCrossParameter(cons) && consDesc.getCrossParameterDescriptor() != null) {
+            if (annotationIgnores.isIgnoreAnnotationOnCrossParameter(cons) && consDesc.getCrossParameterDescriptor() != null) {
                 consDesc.setCrossParameterDescriptor(null);
             }
-            if (factoryContext.getFactory().getAnnotationIgnores().isIgnoreAnnotationOnReturn(cons) && consDesc.getReturnValueDescriptor() != null) {
+            if (annotationIgnores.isIgnoreAnnotationOnReturn(cons) && consDesc.getReturnValueDescriptor() != null) {
                 consDesc.setReturnValueDescriptor(null);
             }
 
@@ -514,20 +519,20 @@ public class BeanDescriptorImpl extends 
     private void buildMethodConstraints() throws InvocationTargetException, IllegalAccessException {
 
         Class<?> current = getMetaBean().getBeanClass();
+
+        final List<Class<?>> classHierarchy = ClassHelper.fillFullClassHierarchyAsList(new ArrayList<Class<?>>(), current);
+
         do {
-            for (final Method method : current.getDeclaredMethods()) {
+            classHierarchy.remove(current);
+            for (final Method method : Reflection.INSTANCE.getDeclaredMethods(current)) {
                 final boolean getter = (method.getName().startsWith("get") || method.getName().startsWith("is")) && method.getParameterTypes().length == 0 && method.getReturnType() != Void.TYPE;
 
                 final MethodDescriptorImpl methodDesc = new MethodDescriptorImpl(getMetaBean(), new Validation[0], method);
                 methodConstraints.put(method, methodDesc);
 
-                final List<Class<?>> classHierarchy = new ArrayList<Class<?>>();
-                ClassHelper.fillFullClassHierarchyAsList(classHierarchy, current);
-                classHierarchy.remove(current);
-
                 final Collection<Method> parents = new ArrayList<Method>();
                 for (final Class<?> clazz : classHierarchy) {
-                    final Method overriden = SecureActions.getDeclaredMethod(clazz, method.getName(), method.getParameterTypes()).run();
+                    final Method overriden = Reflection.INSTANCE.getDeclaredMethod(clazz, method.getName(), method.getParameterTypes());
                     if (overriden != null) {
                         processMethod(overriden, methodDesc);
                         parents.add(overriden);
@@ -541,19 +546,19 @@ public class BeanDescriptorImpl extends 
                 if (parents != null) {
                     if (parents.size() > 1) {
                         for (final Method parent : parents) {
-                            final InvocableElementDescriptor elementDescriptor = InvocableElementDescriptor.class.cast(factoryContext.getValidator().getConstraintsForClass(parent.getDeclaringClass()).getConstraintsForMethod(parent.getName(), parent.getParameterTypes()));
-                            if (elementDescriptor != null) {
-                                ensureNoParameterConstraint(elementDescriptor, "Parameter constraints can't be defined for parallel interfaces/parents");
+                            final MethodDescriptor parentDec = factoryContext.getValidator().getConstraintsForClass(parent.getDeclaringClass()).getConstraintsForMethod(parent.getName(), parent.getParameterTypes());
+                            if (parentDec != null) {
+                                ensureNoParameterConstraint(InvocableElementDescriptor.class.cast(parentDec), "Parameter constraints can't be defined for parallel interfaces/parents");
                             } else {
                                 ensureMethodDoesntDefineParameterConstraint(methodDesc);
                             }
-                            ensureNoReturnValueAddedInChild(methodDesc.getReturnValueDescriptor(), parent, "Return value constraints should be the same for parent and children");
+                            ensureNoReturnValueAddedInChild(methodDesc.getReturnValueDescriptor(), parentDec, "Return value constraints should be the same for parent and children");
                         }
                     } else if (!parents.isEmpty()) {
                         final Method parent = parents.iterator().next();
-                        ensureNoReturnValueAddedInChild(methodDesc.getReturnValueDescriptor(), parent, "Return value constraints should be at least the same for parent and children");
-
                         final MethodDescriptor parentDesc = factoryContext.getValidator().getConstraintsForClass(parent.getDeclaringClass()).getConstraintsForMethod(parent.getName(), parent.getParameterTypes());
+                        ensureNoReturnValueAddedInChild(methodDesc.getReturnValueDescriptor(), parentDesc, "Return value constraints should be at least the same for parent and children");
+
                         if (parentDesc != null) {
                             final Iterator<ParameterDescriptor> parentPd = parentDesc.getParameterDescriptors().iterator();
                             for (final ParameterDescriptor pd : methodDesc.getParameterDescriptors()) {
@@ -573,7 +578,7 @@ public class BeanDescriptorImpl extends 
                     final Class<?>[] interfaces = method.getDeclaringClass().getInterfaces();
                     final Collection<Method> itfWithThisMethod = new ArrayList<Method>();
                     for (final Class<?> i : interfaces) {
-                        final Method m = SecureActions.getDeclaredMethod(i, method.getName(), method.getParameterTypes()).run();
+                        final Method m = Reflection.INSTANCE.getDeclaredMethod(i, method.getName(), method.getParameterTypes());
                         if (m != null) {
                             itfWithThisMethod.add(m);
                         }
@@ -591,7 +596,7 @@ public class BeanDescriptorImpl extends 
                         returnValid++;
                     }
                     for (final Class<?> clazz : classHierarchy) {
-                        final Method overriden = SecureActions.getDeclaredMethod(clazz, method.getName(), method.getParameterTypes()).run();
+                        final Method overriden = Reflection.INSTANCE.getDeclaredMethod(clazz, method.getName(), method.getParameterTypes());
                         if (overriden != null) {
                             if (overriden.getAnnotation(Valid.class) != null) {
                                 returnValid++;
@@ -629,13 +634,12 @@ public class BeanDescriptorImpl extends 
         }
     }
 
-    private void ensureNoReturnValueAddedInChild(final ReturnValueDescriptor returnValueDescriptor, final Method parent, final String msg) {
-        final MethodDescriptor parentDesc = factoryContext.getValidator().getConstraintsForClass(parent.getDeclaringClass()).getConstraintsForMethod(parent.getName(), parent.getParameterTypes());
-        if (parentDesc == null) {
+    private void ensureNoReturnValueAddedInChild(final ReturnValueDescriptor returnValueDescriptor, final MethodDescriptor parentMtdDesc, final String msg) {
+        if (parentMtdDesc == null) {
             return;
         }
 
-        final ReturnValueDescriptor parentReturnDesc = parentDesc.getReturnValueDescriptor();
+        final ReturnValueDescriptor parentReturnDesc = parentMtdDesc.getReturnValueDescriptor();
         if (parentReturnDesc.isCascaded() && !returnValueDescriptor.isCascaded() || parentReturnDesc.getConstraintDescriptors().size() > returnValueDescriptor.getConstraintDescriptors().size()) {
             throw new ConstraintDeclarationException(msg);
         }
@@ -662,9 +666,11 @@ public class BeanDescriptorImpl extends 
         }
     }
 
-    private void processMethod(Method method, MethodDescriptorImpl methodDesc) throws InvocationTargetException, IllegalAccessException {
+    private void processMethod(final Method method, final MethodDescriptorImpl methodDesc) throws InvocationTargetException, IllegalAccessException {
+        final AnnotationIgnores annotationIgnores = factoryContext.getFactory().getAnnotationIgnores();
+
         { // reflection
-            if (!factoryContext.getFactory().getAnnotationIgnores().isIgnoreAnnotations(method)) {
+            if (!annotationIgnores.isIgnoreAnnotations(method)) {
                 // return value validations and/or cross-parameter validation
                 for (Annotation anno : method.getAnnotations()) {
                     if (anno instanceof Valid || anno instanceof Validate) {
@@ -680,7 +686,7 @@ public class BeanDescriptorImpl extends 
             int idx = 0;
             final List<String> names = factoryContext.getParameterNameProvider().getParameterNames(method);
             for (final Annotation[] paramAnnos : paramsAnnos) {
-                if (!factoryContext.getFactory().getAnnotationIgnores().isIgnoreAnnotationOnParameter(method, idx)) {
+                if (!annotationIgnores.isIgnoreAnnotationOnParameter(method, idx)) {
                     final ParameterAccess access = new ParameterAccess(method.getParameterTypes()[idx], idx);
                     processAnnotations(methodDesc, paramAnnos, access, idx, names.get(idx));
                 } else {
@@ -692,10 +698,10 @@ public class BeanDescriptorImpl extends 
             }
         }
 
-        if (factoryContext.getFactory().getAnnotationIgnores().isIgnoreAnnotationOnCrossParameter(method) && methodDesc.getCrossParameterDescriptor() != null) {
+        if (annotationIgnores.isIgnoreAnnotationOnCrossParameter(method) && methodDesc.getCrossParameterDescriptor() != null) {
             methodDesc.setCrossParameterDescriptor(null);
         }
-        if (factoryContext.getFactory().getAnnotationIgnores().isIgnoreAnnotationOnReturn(method) && methodDesc.getReturnValueDescriptor() != null) {
+        if (annotationIgnores.isIgnoreAnnotationOnReturn(method) && methodDesc.getReturnValueDescriptor() != null) {
             methodDesc.setReturnValueDescriptor(null);
         }
 
@@ -819,8 +825,9 @@ public class BeanDescriptorImpl extends 
                 /**
                  * Multi-valued constraints
                  */
-                if (ConstraintAnnotationAttributes.VALUE.isDeclaredOn(annotation.annotationType())) {
-                    Annotation[] children = ConstraintAnnotationAttributes.VALUE.getValue(annotation);
+                final ConstraintAnnotationAttributes.Worker<? extends Annotation> worker = ConstraintAnnotationAttributes.VALUE.analyze(annotation.annotationType());
+                if (worker.isValid()) {
+                    Annotation[] children = Annotation[].class.cast(worker.read(annotation));
                     if (children != null) {
                         for (Annotation child : children) {
                             processAnnotation(child, desc, access, validations); // recursion

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java Tue Aug 13 20:26:51 2013
@@ -110,16 +110,6 @@ public class ClassValidator implements C
     }
 
     /**
-     * Create a new ClassValidator instance.
-     *
-     * @param factory
-     * @deprecated provided for backward compatibility
-     */
-    public ClassValidator(ApacheValidatorFactory factory) {
-        this(factory.usingContext());
-    }
-
-    /**
      * Get the metabean finder associated with this validator.
      *
      * @return a MetaBeanFinder
@@ -331,21 +321,28 @@ public class ClassValidator implements C
     }
 
     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 {
-                    Constructor<T> cons = cls.getConstructor(ApacheFactoryContext.class);
-                    if (!cons.isAccessible()) {
-                        cons.setAccessible(true);
-                    }
-                    return cons.newInstance(factoryContext);
-                } catch (final Exception ex) {
-                    throw new ValidationException("Cannot instantiate : " + cls, ex);
-                }
+                return doNewInstance(cls);
             }
         });
     }
 
+    private <T> T doNewInstance(final Class<T> cls) {
+        try {
+            Constructor<T> cons = cls.getConstructor(ApacheFactoryContext.class);
+            if (!cons.isAccessible()) {
+                cons.setAccessible(true);
+            }
+            return cons.newInstance(factoryContext);
+        } catch (final Exception ex) {
+            throw new ValidationException("Cannot instantiate : " + cls, ex);
+        }
+    }
+
     // Helpers
     // -------------------------------------------------------------------
 

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConfigurationImpl.java?rev=1513638&r1=1513637&r2=1513638&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConfigurationImpl.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConfigurationImpl.java Tue Aug 13 20:26:51 2013
@@ -22,7 +22,6 @@ package org.apache.bval.jsr303;
 import org.apache.bval.jsr303.parameter.DefaultParameterNameProvider;
 import org.apache.bval.jsr303.resolver.DefaultTraversableResolver;
 import org.apache.bval.jsr303.util.IOs;
-import org.apache.bval.jsr303.util.SecureActions;
 import org.apache.bval.jsr303.xml.ValidationParser;
 
 import javax.validation.BootstrapConfiguration;
@@ -270,16 +269,23 @@ public class ConfigurationImpl implement
      * @throws ValidationException if the ValidatorFactory cannot be built
      */
     public ValidatorFactory buildValidatorFactory() {
-        return run(SecureActions.doPrivBuildValidatorFactory(this));
+        if (System.getSecurityManager() == null) {
+            return doPrivBuildValidatorFactory(this);
+        }
+        return AccessController.doPrivileged(new PrivilegedAction<ValidatorFactory>() {
+            public ValidatorFactory run() {
+                return doPrivBuildValidatorFactory(ConfigurationImpl.this);
+            }
+        });
     }
 
-    public ValidatorFactory doPrivBuildValidatorFactory() {
+    public ValidatorFactory doPrivBuildValidatorFactory(final ConfigurationImpl impl) {
         prepare();
         parser.ensureValidatorFactoryCanBeBuilt();
         if (provider != null) {
-            return provider.buildValidatorFactory(this);
+            return provider.buildValidatorFactory(impl);
         } else {
-            return findProvider().buildValidatorFactory(this);
+            return findProvider().buildValidatorFactory(impl);
         }
     }
 
@@ -363,14 +369,6 @@ public class ConfigurationImpl implement
         this.providerClass = providerClass;
     }
 
-    private static <T> T run(PrivilegedAction<T> action) {
-        if (System.getSecurityManager() != null) {
-            return AccessController.doPrivileged(action);
-        } else {
-            return action.run();
-        }
-    }
-
     public void setExecutableValidation(final Collection<ExecutableType> executableValidation) {
         this.executableValidation = executableValidation;
     }