bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1514597 - in /bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303: AnnotationConstraintBuilder.java xml/AnnotationProxyBuilder.java xml/ValidationMappingParser.java
Date Fri, 16 Aug 2013 07:15:05 GMT
Author: rmannibucau
Date: Fri Aug 16 07:15:05 2013
New Revision: 1514597

URL: http://svn.apache.org/r1514597
Log:
reusing cache of built in constraints in AnnotationConstraintBuilder

Modified:
    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/xml/AnnotationProxyBuilder.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationMappingParser.java

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=1514597&r1=1514596&r2=1514597&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
Fri Aug 16 07:15:05 2013
@@ -21,7 +21,6 @@ package org.apache.bval.jsr303;
 import org.apache.bval.jsr303.groups.GroupsComputer;
 import org.apache.bval.jsr303.xml.AnnotationProxyBuilder;
 import org.apache.bval.util.AccessStrategy;
-import org.apache.bval.util.reflection.Reflection;
 
 import javax.validation.Constraint;
 import javax.validation.ConstraintDeclarationException;
@@ -99,7 +98,7 @@ final class AnnotationConstraintBuilder<
     private void doBuildFromAnnotations() {
         final Class<? extends Annotation> annotationType = constraintValidation.getAnnotation().annotationType();
 
-        for (final Method method : Reflection.INSTANCE.getDeclaredMethods(annotationType))
{
+        for (final Method method : AnnotationProxyBuilder.findMethods(annotationType)) {
             // groups + payload must also appear in attributes (also
             // checked by TCK-Tests)
             if (method.getParameterTypes().length == 0) {

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=1514597&r1=1514596&r2=1514597&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
Fri Aug 16 07:15:05 2013
@@ -56,19 +56,22 @@ final public class AnnotationProxyBuilde
      */
     public AnnotationProxyBuilder(final Class<A> annotationType) {
         this.type = annotationType;
+        this.methods = findMethods(annotationType);
+    }
+
+    public static <A> Method[] findMethods(final Class<A> annotationType) {
         if (annotationType.getName().startsWith("javax.validation.constraints.")) { // cache
built-in constraints only to avoid mem leaks
             Method[] mtd = METHODS_CACHE.get(annotationType);
             if (mtd == null) {
-                final Method[] value = Reflection.INSTANCE.getDeclaredMethods(type);
+                final Method[] value = Reflection.INSTANCE.getDeclaredMethods(annotationType);
                 mtd = METHODS_CACHE.putIfAbsent(annotationType, value);
                 if (mtd == null) {
                     mtd = value;
                 }
             }
-            this.methods = mtd;
-        } else {
-            this.methods = Reflection.INSTANCE.getDeclaredMethods(type);
+            return mtd;
         }
+        return Reflection.INSTANCE.getDeclaredMethods(annotationType);
     }
 
     /**

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=1514597&r1=1514596&r2=1514597&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
Fri Aug 16 07:15:05 2013
@@ -111,17 +111,16 @@ public class ValidationMappingParser {
     }
 
     /** @param in XML stream to parse using the validation-mapping-1.0.xsd */
-    private ConstraintMappingsType parseXmlMappings(InputStream in) {
+    private ConstraintMappingsType parseXmlMappings(final InputStream in) {
         ConstraintMappingsType mappings;
         try {
-            JAXBContext jc = JAXBContext.newInstance(ConstraintMappingsType.class);
-            Unmarshaller unmarshaller = jc.createUnmarshaller();
+            final JAXBContext jc = JAXBContext.newInstance(ConstraintMappingsType.class);
+            final Unmarshaller unmarshaller = jc.createUnmarshaller();
             unmarshaller.setSchema(getSchema());
-            StreamSource stream = new StreamSource(in);
-            JAXBElement<ConstraintMappingsType> root =
-                  unmarshaller.unmarshal(stream, ConstraintMappingsType.class);
+            final StreamSource stream = new StreamSource(in);
+            final JAXBElement<ConstraintMappingsType> root = unmarshaller.unmarshal(stream,
ConstraintMappingsType.class);
             mappings = root.getValue();
-        } catch (JAXBException e) {
+        } catch (final JAXBException e) {
             throw new ValidationException("Failed to parse XML deployment descriptor file.",
e);
         } finally {
             IOUtils.closeQuietly(in);



Mime
View raw message