incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlosv...@apache.org
Subject svn commit: r955667 [1/2] - in /incubator/bval/sandbox/jsr303-impl-bench: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/bval/ src/main/java/org/apache/bval/bench/ src/main/java/org/apache/bval/be...
Date Thu, 17 Jun 2010 16:30:59 GMT
Author: carlosvara
Date: Thu Jun 17 16:30:57 2010
New Revision: 955667

URL: http://svn.apache.org/viewvc?rev=955667&view=rev
Log:
Performance tester: initial commit

Added:
    incubator/bval/sandbox/jsr303-impl-bench/   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/pom.xml   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/
    incubator/bval/sandbox/jsr303-impl-bench/src/main/
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Annotable.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotationType.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotatorVisitor.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/BasicType.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Config.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Generator.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanBasicField.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanRefField.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Util.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303Annotator.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303MetaAnnotationSet.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/MetaGroup.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractBaseMetaClass.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaField.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaInterface.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaAnnotation.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaJavaBean.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/main/resources/
    incubator/bval/sandbox/jsr303-impl-bench/src/main/resources/generator.default.properties   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/test/
    incubator/bval/sandbox/jsr303-impl-bench/src/test/java/
    incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/
    incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/
    incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/
    incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/
    incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/AbstractBenchTest.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/ApacheTest.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/HibernateTest.java   (with props)
    incubator/bval/sandbox/jsr303-impl-bench/src/test/resources/
    incubator/bval/sandbox/jsr303-impl-bench/src/test/resources/logback-test.xml   (with props)

Propchange: incubator/bval/sandbox/jsr303-impl-bench/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jun 17 16:30:57 2010
@@ -0,0 +1 @@
+target

Added: incubator/bval/sandbox/jsr303-impl-bench/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/pom.xml?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/pom.xml (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/pom.xml Thu Jun 17 16:30:57 2010
@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<!--
+    Maven release plugin requires the project tag to be on a single
+    line.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.bval</groupId>
+        <artifactId>bval-parent</artifactId>
+        <version>0.2-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>jsr303-impl-bench</artifactId>
+    <packaging>jar</packaging>
+    <name>Apache Bean Validation :: jsr303-impl-bench (optional)</name>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>com.sun.codemodel</groupId>
+            <artifactId>codemodel</artifactId>
+            <version>2.2</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.collections</groupId>
+            <artifactId>google-collections</artifactId>
+            <version>1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.validation</groupId>
+            <artifactId>validation-api</artifactId>
+            <version>1.0.0.GA</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.bval</groupId>
+            <artifactId>org.apache.bval.bundle</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.hibernate</groupId>
+            <artifactId>hibernate-validator</artifactId>
+            <version>4.1.0.Beta1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.5.8</version>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>0.9.18</version>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.7</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <!-- TODO: Config JAXB (CodeModel) for JDK 1.5 -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>1.5</version>
+                <executions>
+                    <execution>
+                        <id>add-source</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>target/generated-sources/beangraph</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <repositories>
+
+        <repository>
+            <id>Temp snapshots</id>
+            <url>https://repository.apache.org/content/groups/public</url>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>
+        </repository>
+
+        <repository>
+            <id>Java.net Maven 2 Repository</id>
+            <url>http://download.java.net/maven/2/</url>
+        </repository>
+
+    </repositories>
+
+</project>

Propchange: incubator/bval/sandbox/jsr303-impl-bench/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Annotable.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Annotable.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Annotable.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Annotable.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,45 @@
+/*
+ * 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.bench;
+
+import org.apache.bval.bench.metatree.MetaAnnotation;
+
+
+/**
+ * Defines the operations needed by an element that can be annotated.
+ * 
+ * @author Carlos Vara
+ */
+public interface Annotable {
+
+    /**
+     * Visitor method to accept an annotator.
+     * 
+     * @param annotator
+     */
+    void accept(AnnotatorVisitor annotator);
+    
+    /**
+     * Adds an annotation to this element.
+     * 
+     * @param annot The annotation to add.
+     */
+    void addAnnotation(MetaAnnotation annot);
+    
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Annotable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotationType.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotationType.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotationType.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotationType.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,31 @@
+/*
+ * 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.bench;
+
+/**
+ * The types of supported annotations by the generator.
+ * 
+ * @author Carlos Vara
+ */
+public enum AnnotationType {
+
+    JSR_303,
+    OTHER;
+    
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotationType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotatorVisitor.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotatorVisitor.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotatorVisitor.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotatorVisitor.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,40 @@
+/*
+ * 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.bench;
+
+import org.apache.bval.bench.metatree.MetaJavaBean;
+
+
+// TODO: Classes must be processed by visiting, same as fields
+
+/**
+ * All the methods that an annotator must implement to be able to visit and
+ * annotate all the meta tree.
+ * 
+ * @author Carlos Vara
+ */
+public interface AnnotatorVisitor {
+
+    void annotate(JavaBeanRefField jbrf);
+    
+    void annotate(JavaBeanBasicField jbbf);
+    
+    void annotate(MetaJavaBean mjb);
+    
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/AnnotatorVisitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/BasicType.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/BasicType.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/BasicType.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/BasicType.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,56 @@
+/*
+ * 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.bench;
+
+
+/**
+ * Basic type property types.
+ * 
+ * @author Carlos Vara
+ */
+public enum BasicType {
+
+    STRING {
+        @Override
+        public Class<?> getTypeClass() {
+            return String.class;
+        }
+    },
+    INTEGER {
+        @Override
+        public Class<?> getTypeClass() {
+            return Integer.class;
+        }
+    }/*,
+    INT {
+        @Override
+        public Class<?> getTypeClass() {
+            return int.class;
+        }
+    }*/;
+    
+    
+    public abstract Class<?> getTypeClass();
+    
+    public static BasicType getRandom() {
+        BasicType[] values = BasicType.values();
+        return values[Config.CFG.getRandomGen().nextInt(values.length)];
+    }
+    
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/BasicType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Config.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Config.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Config.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Config.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,155 @@
+/*
+ * 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.bench;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.Random;
+
+
+// TODO
+// % of valid basic fields values
+// % of ref fields annotated with @NotNull
+// % of ref beans that reference already existing beans (circular deps)
+
+
+/**
+ * Stores the generator configuration parameters and provides an easy way of
+ * accessing those parameters and the random values they can generate.
+ * 
+ * @author Carlos Vara
+ */
+public enum Config {
+
+    CFG();
+    
+    private static final String DEFAULT_PROPERTIES_RES = "generator.default.properties";
+    private static final String USER_PROPERTIES_RES = "generator.properties";
+    
+    private final Random r;
+    private final Properties p;
+    
+    private Config() {
+        
+        // Read the config
+        p = readConfigProperties();
+        
+        // Init random generator
+        r = new Random(new Long(p.getProperty("generator.rnd.seed")));
+    }
+    
+    public String getOutputDir() {
+        return p.getProperty("generator.outputdir");
+    }
+    
+    public String getBasePackageName() {
+        return p.getProperty("generator.pkg.base");
+    }
+    
+    public String getBeansPackageName() {
+        return p.getProperty("generator.pkg.beans");
+    }
+    
+    public String getGroupsPackageName() {
+        return p.getProperty("generator.pkg.groups");
+    }
+    
+    public int getNumBeans() {
+        return new Integer(p.getProperty("generator.numbeans"));
+    }
+    
+    public int getNumGroups() {
+        return new Integer(p.getProperty("generator.numgroups"));
+    }
+    
+    public Random getRandomGen() {
+        return r;
+    }
+    
+    public int rndNumFields() {
+        int min = new Integer(p.getProperty("generator.basicfields.min"));
+        int dif = new Integer(p.getProperty("generator.basicfields.max")) - min;
+        return min + r.nextInt(dif);
+    }
+    
+    public int rndNumInterralations() {
+        int min = new Integer(p.getProperty("generator.reffields.min"));
+        int dif = new Integer(p.getProperty("generator.reffields.max")) - min;
+        return min + r.nextInt(dif);
+    }
+    
+    public boolean shouldAddNestedBean(int level) {
+        if ( level == 0 ) {
+            return r.nextDouble() < new Double(p.getProperty("generator.level1.fillrate"));
+        }
+        else if ( level == 1 ) {
+            return r.nextDouble() < new Double(p.getProperty("generator.level2.fillrate"));
+        }
+        else if ( level == 2 ) {
+            return r.nextDouble() < new Double(p.getProperty("generator.level3.fillrate"));
+        }
+        else {
+            return false;
+        }
+    }
+    
+    
+    private Properties readConfigProperties() {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        if ( cl == null ) {
+            throw new RuntimeException("Could not obtain a class loader.");
+        }
+        Properties tmp = loadDefaultProperties(cl);
+        tmp = overrideDefaultProperties(cl, tmp);
+        return tmp;
+    }
+    
+    private Properties loadDefaultProperties(ClassLoader cl) {
+        Properties defaultProperties = new Properties();
+        InputStream dpStream = cl.getResourceAsStream(DEFAULT_PROPERTIES_RES);
+        if ( dpStream == null ) {
+            throw new RuntimeException("Could not locate default properties file: " + DEFAULT_PROPERTIES_RES + " in the classpath.");
+        }
+        try {
+            defaultProperties.load(dpStream);
+            dpStream.close(); // No finally, an exception here terminates the program
+        } catch (IOException e) {
+            throw new RuntimeException("Error while reading default properties file.", e);
+        }
+        return defaultProperties;
+    }
+    
+    private Properties overrideDefaultProperties(ClassLoader cl, Properties defaultProperties) {
+        InputStream upStream = cl.getResourceAsStream(USER_PROPERTIES_RES);
+        if ( upStream == null ) {
+            return defaultProperties;
+        }
+        
+        Properties userProperties = new Properties(defaultProperties);
+        try {
+            userProperties.load(upStream);
+            upStream.close(); // No finally, an exception here terminates the program
+        } catch (IOException e) {
+            throw new RuntimeException("Error while reading user properties file.", e);
+        }
+        return userProperties;
+    }
+    
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Config.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Generator.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Generator.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Generator.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Generator.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,148 @@
+/*
+ * 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.bench;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.bval.bench.jsr303.Jsr303Annotator;
+import org.apache.bval.bench.jsr303.MetaGroup;
+import org.apache.bval.bench.metatree.AbstractMetaField;
+import org.apache.bval.bench.metatree.MetaJavaBean;
+import com.google.common.collect.Lists;
+import com.sun.codemodel.JBlock;
+import com.sun.codemodel.JClass;
+import com.sun.codemodel.JClassAlreadyExistsException;
+import com.sun.codemodel.JCodeModel;
+import com.sun.codemodel.JDefinedClass;
+import com.sun.codemodel.JExpr;
+import com.sun.codemodel.JFieldVar;
+import com.sun.codemodel.JMethod;
+import com.sun.codemodel.JMod;
+import com.sun.codemodel.JVar;
+
+
+/**
+ * Temporal entry point for bean graph generation.
+ * 
+ * @author Carlos Vara
+ */
+public class Generator {
+
+    public static void generateBeans() throws IOException, JClassAlreadyExistsException {
+
+        // Code model root
+        JCodeModel cm = new JCodeModel();
+
+        // And the lists of beans
+        List<MetaJavaBean> beans = Lists.newArrayListWithExpectedSize(Config.CFG.getNumBeans());
+
+
+        // PHASE 1: Basic beans with basic type fields
+        for (int i = 0; i < Config.CFG.getNumBeans(); ++i) {
+            MetaJavaBean mjb = new MetaJavaBean(cm, Config.CFG.getBeansPackageName() + ".Bean" + i, Config.CFG.rndNumFields());
+            beans.add(mjb);
+        }
+
+        // PHASE 2: Enrich beans with references to other beans
+        for (MetaJavaBean mjb : beans) {
+            mjb.interrelate(beans);
+        }
+
+        // PHASE 3: Annotate the beans with the JSR-303 annotator (other
+        // annotators can be added)
+        Jsr303Annotator annotator = new Jsr303Annotator(cm);
+        for (MetaJavaBean mjb : beans) {
+            mjb.accept(annotator);
+        }
+
+        // PHASE 4: Generate population code
+        generateHolderClass(cm, beans);
+
+
+        // Create the .java files
+        File file = new File(Config.CFG.getOutputDir());
+        file.mkdirs();
+        cm.build(file);
+
+    }
+
+
+    // The tests will have code that loads the class and instantiates it
+    public static void generateHolderClass(JCodeModel cm, List<MetaJavaBean> beans) throws JClassAlreadyExistsException {
+
+        JDefinedClass holderClass = cm._class(Config.CFG.getBasePackageName() + ".Holder");
+        JClass alObject = (JClass) cm._ref(ArrayList.class);
+        alObject = alObject.narrow(Object.class);
+        JFieldVar beansField = holderClass.field(JMod.PUBLIC, alObject, "beans", JExpr._new(alObject));
+        JMethod defConstructor = holderClass.constructor(JMod.PUBLIC);
+        JBlock body = defConstructor.body();
+
+        for (MetaJavaBean mjb : beans) {
+            JVar beanDecl = generateBeanInitCode(mjb, body, 0);
+            body.add(beansField.invoke("add").arg(beanDecl));
+        }
+    }
+
+    public static int uniqueCounter = 0;
+
+    public static JVar generateBeanInitCode(MetaJavaBean mjb, JBlock body, int level) {
+
+        JVar beanDecl = body.decl(mjb.getGeneratedClass(), "lvl" + level + mjb.getName() + uniqueCounter++);
+        body.assign(beanDecl, JExpr._new(mjb.getGeneratedClass()));
+
+        for (AbstractMetaField amf : mjb.getFields()) {
+            if ((amf instanceof JavaBeanBasicField) && level == 0) {
+                
+                JavaBeanBasicField jbbf = (JavaBeanBasicField) amf;
+                Object value;
+                if (Config.CFG.getRandomGen().nextBoolean()) {
+                    int validIdx = Config.CFG.getRandomGen().nextInt(jbbf.getValidValues().size());
+                    value = jbbf.getValidValues().get(validIdx);
+                } else {
+                    int invalidIdx = Config.CFG.getRandomGen().nextInt(jbbf.getInvalidValues().size());
+                    value = jbbf.getInvalidValues().get(invalidIdx);
+                }
+                jbbf.generateAssignCode(value);
+                
+            } else if (amf instanceof JavaBeanRefField) {
+
+                JavaBeanRefField jbrf = (JavaBeanRefField) amf;
+
+                // Should a nested bean be created?
+                if (Config.CFG.shouldAddNestedBean(level)) {
+                    JVar nestedBeanDecl = generateBeanInitCode(jbrf.getRefBean(), body, level + 1);
+                    jbrf.generateAssignCode(body, beanDecl, nestedBeanDecl);
+                }
+            }
+
+        }
+
+        return beanDecl;
+    }
+
+
+    public static void main(String[] args) throws IOException, JClassAlreadyExistsException {
+        System.out.println("Starting generation...");
+        generateBeans();
+        System.out.println("Beans generated!");
+    }
+
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Generator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanBasicField.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanBasicField.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanBasicField.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanBasicField.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,123 @@
+/*
+ * 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.bench;
+
+import java.util.List;
+import org.apache.bval.bench.metatree.AbstractMetaField;
+import org.apache.bval.bench.metatree.MetaAnnotation;
+import org.apache.bval.bench.metatree.MetaJavaBean;
+import com.sun.codemodel.JAnnotationUse;
+import com.sun.codemodel.JBlock;
+import com.sun.codemodel.JDefinedClass;
+import com.sun.codemodel.JExpr;
+import com.sun.codemodel.JMethod;
+import com.sun.codemodel.JMod;
+import com.sun.codemodel.JVar;
+
+
+/**
+ * A field with getter/setter methods for a basic type.
+ * 
+ * @author Carlos Vara
+ */
+public class JavaBeanBasicField extends AbstractMetaField implements Annotable {
+
+    // The singleType of the field
+    private final BasicType basicType;
+
+    private JMethod getter;
+    private JMethod setter;
+
+    // The value to which the field is initialized (may be a valid or invalid value)
+    private List<Object> validValues;
+    private List<Object> invalidValues;
+
+
+    /**
+     * Creates a random MetaField
+     * 
+     * @param owner
+     *            The class that owns this field.
+     * @param name
+     *            The name of the meta field.
+     */
+    public JavaBeanBasicField(MetaJavaBean owner, String name) {
+
+        this.name = name;
+        this.basicType = BasicType.getRandom();
+
+        // Generate the field declaration
+        JDefinedClass ownerClass = owner.getGeneratedClass();
+        this.generatedField = ownerClass.field(JMod.PRIVATE, basicType.getTypeClass(), name);
+        
+        // The getter
+        getter = ownerClass.method(JMod.PUBLIC, basicType.getTypeClass(), "get" + name.substring(0, 1).toUpperCase() + name.substring(1));
+        getter.body()._return(this.generatedField);
+        
+        // And the setter
+        setter = ownerClass.method(JMod.PUBLIC, void.class, "set" + name.substring(0, 1).toUpperCase() + name.substring(1));
+        JVar setterParam = setter.param(basicType.getTypeClass(), name);
+        setter.body().assign(JExpr._this().ref(this.generatedField), setterParam);
+    }
+
+
+    // statically assign the code in the field
+    public void generateAssignCode(Object value) {
+        this.generatedField.init(Util.literalExpr(value));
+    }
+
+
+    public BasicType getBasicType() {
+        return basicType;
+    }
+
+    public void setValidValues(List<Object> validValues) {
+        this.validValues = validValues;
+    }
+
+    public List<Object> getValidValues() {
+        return validValues;
+    }
+
+    public void setInvalidValues(List<Object> invalidValues) {
+        this.invalidValues = invalidValues;
+    }
+
+    public List<Object> getInvalidValues() {
+        return invalidValues;
+    }
+
+    @Override
+    public void accept(AnnotatorVisitor annotator) {
+        annotator.annotate(this);
+    }
+
+    @Override
+    public void addAnnotation(MetaAnnotation annot) {
+        // Add the annotation to the set of annotations
+        if ( this.annotations.add(annot) ) {
+            // Generate the source
+            JAnnotationUse genAnnot = getter.annotate(annot.getAnnotationClass());
+            for (String paramKey : annot.getParameters().keySet()) {
+                Util.addAnnotParam(genAnnot, paramKey, annot.getParameters().get(paramKey));
+            }
+        }
+    }
+
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanBasicField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanRefField.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanRefField.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanRefField.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanRefField.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,89 @@
+/*
+ * 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.bench;
+
+import org.apache.bval.bench.metatree.AbstractMetaField;
+import org.apache.bval.bench.metatree.MetaAnnotation;
+import org.apache.bval.bench.metatree.MetaJavaBean;
+import com.sun.codemodel.JAnnotationUse;
+import com.sun.codemodel.JBlock;
+import com.sun.codemodel.JDefinedClass;
+import com.sun.codemodel.JExpr;
+import com.sun.codemodel.JMethod;
+import com.sun.codemodel.JMod;
+import com.sun.codemodel.JVar;
+
+
+/**
+ * A field with getter/setter methods that references another bean.
+ * 
+ * @author Carlos Vara
+ */
+public class JavaBeanRefField extends AbstractMetaField implements Annotable {
+
+    // Referenced bean
+    private final MetaJavaBean refBean;
+    
+    private JMethod getter;
+    private JMethod setter;
+    
+    public JavaBeanRefField(MetaJavaBean owner, String name, MetaJavaBean refBean) {
+        this.name = name;
+        this.refBean = refBean;
+        
+        // Generate the field declaration
+        JDefinedClass ownerClass = owner.getGeneratedClass();
+        this.generatedField = ownerClass.field(JMod.PRIVATE, refBean.getGeneratedClass(), name);
+        
+        // The getter
+        getter = ownerClass.method(JMod.PUBLIC, refBean.getGeneratedClass(), "get"+name.substring(0, 1).toUpperCase()+name.substring(1));
+        getter.body()._return(this.generatedField);
+        
+        // The setter
+        setter = ownerClass.method(JMod.PUBLIC, void.class, "set"+name.substring(0, 1).toUpperCase()+name.substring(1));
+        JVar setterParam = setter.param(refBean.getGeneratedClass(), name);
+        setter.body().assign(JExpr._this().ref(this.generatedField), setterParam);
+    }
+
+    @Override
+    public void accept(AnnotatorVisitor annotator) {
+        annotator.annotate(this);
+    }
+    
+    @Override
+    public void addAnnotation(MetaAnnotation annot) {
+        // Add the annotation to the set of annotations
+        if ( this.annotations.add(annot) ) {
+            // Generate the source
+            JAnnotationUse genAnnot = getter.annotate(annot.getAnnotationClass());
+            for (String paramKey : annot.getParameters().keySet()) {
+                Util.addAnnotParam(genAnnot, paramKey, annot.getParameters().get(paramKey));
+            }
+        }
+    }    
+    
+    public void generateAssignCode(JBlock body, JVar var, JVar value) {
+        body.add(var.invoke(this.setter).arg(value));
+    }
+
+    public MetaJavaBean getRefBean() {
+        return refBean;
+    }
+    
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/JavaBeanRefField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Util.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Util.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Util.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Util.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.bench;
+
+import com.sun.codemodel.JAnnotationUse;
+import com.sun.codemodel.JExpr;
+import com.sun.codemodel.JExpression;
+
+public final class Util {
+
+    private Util() {
+        // No instances please
+    }
+    
+    // Not very clean, but as there is a fixed amount of types...
+    public static JExpression literalExpr(Object value) {
+        if ( value == null ) {
+            return JExpr._null();
+        } else if ( value instanceof String ) {
+            return JExpr.lit((String)value);
+        } else if ( value instanceof Integer ) {
+            return JExpr.lit((Integer)value);
+        }
+        
+        throw new RuntimeException("Impossible to construct initial value for: " + value);
+    }
+
+    // Not very clean, but as there is a fixed amount of types...
+    public static void addAnnotParam(JAnnotationUse annot, String key, Object value) {
+        // TODO: Remove comparisons with primitive type class?
+        if ( value == null ) {
+            // Null values not accepted
+            throw new RuntimeException("Null values not supported as annotation parameters");
+        }
+        else if ( value instanceof Boolean || value.getClass() == boolean.class ) {
+            annot.param(key, (Boolean)value);
+        }
+        else if (value instanceof Integer ) {
+            annot.param(key, (Integer)value);
+        }
+        else if ( value instanceof String ) {
+            annot.param(key, (String)value);
+        }
+        else if ( value instanceof Class<?> ) {
+            annot.param(key, (Class<?>)value);
+        }
+        else {
+            throw new RuntimeException("Impossible to construct annotation param for: " + value);
+        }
+    }
+    
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/Util.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303Annotator.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303Annotator.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303Annotator.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303Annotator.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,304 @@
+/*
+ * 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.bench.jsr303;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.Payload;
+import javax.validation.Valid;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Null;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+import org.apache.bval.bench.AnnotationType;
+import org.apache.bval.bench.AnnotatorVisitor;
+import org.apache.bval.bench.BasicType;
+import org.apache.bval.bench.Config;
+import org.apache.bval.bench.JavaBeanBasicField;
+import org.apache.bval.bench.JavaBeanRefField;
+import org.apache.bval.bench.metatree.AbstractMetaField;
+import org.apache.bval.bench.metatree.MetaAnnotation;
+import org.apache.bval.bench.metatree.MetaJavaBean;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.sun.codemodel.ClassType;
+import com.sun.codemodel.JClass;
+import com.sun.codemodel.JClassAlreadyExistsException;
+import com.sun.codemodel.JCodeModel;
+import com.sun.codemodel.JDefinedClass;
+import com.sun.codemodel.JExpr;
+import com.sun.codemodel.JExpressionImpl;
+import com.sun.codemodel.JFormatter;
+import com.sun.codemodel.JMethod;
+import com.sun.codemodel.JMod;
+import com.sun.codemodel.JVar;
+
+
+/**
+ * A class / field annotator that produces JSR-303 annotations.
+ * 
+ * @author Carlos Vara
+ */
+public class Jsr303Annotator implements AnnotatorVisitor {
+
+    // TODO: Add groups to the annotations
+    // TODO: So the beans know how many groups are used, and they can create a
+    // good @GroupSequence
+
+    private final JCodeModel codeModel;
+
+    private final List<MetaGroup> groups;
+    private final ListMultimap<BasicType, Jsr303MetaAnnotationSet> basicTypeAnnotations;
+    private final List<MetaAnnotation> classAnnotations;
+
+
+
+    // Receive a codemodel, and use it to:
+    // - Create the groups
+    // - Create the class constraints
+    // - Create the complex nested constraints
+
+    public Jsr303Annotator(JCodeModel cm) {
+        this.codeModel = cm;
+        this.groups = generateGroups();
+        this.basicTypeAnnotations = buildBasicTypeAnnotations();
+        this.classAnnotations = buildClassAnnotations();
+    }
+
+
+    // Specific annotation methods ---------------------------------------------
+
+    @Override
+    public void annotate(JavaBeanRefField jbrf) {
+        // Always annotate with @Valid
+        MetaAnnotation valid = new MetaAnnotation(codeModel, Valid.class, AnnotationType.JSR_303, new HashMap<String, Object>());
+        jbrf.addAnnotation(valid);
+
+        if (Config.CFG.getRandomGen().nextBoolean()) { // Annotate with @NotNull
+                                                       // 50% of the time
+            Map<String, Object> notNullParams = Maps.newHashMap();
+            // TODO: Group for null
+            MetaAnnotation notNull = new MetaAnnotation(codeModel, NotNull.class, AnnotationType.JSR_303, notNullParams);
+            jbrf.addAnnotation(notNull);
+        } else { // The other 50%, annotate with @Null
+            Map<String, Object> nullParams = Maps.newHashMap();
+            MetaAnnotation mustBeNull = new MetaAnnotation(codeModel, Null.class, AnnotationType.JSR_303, nullParams);
+            jbrf.addAnnotation(mustBeNull);
+        }
+
+    }
+
+    @Override
+    public void annotate(JavaBeanBasicField jbbf) {
+        // Select a random set of annotations for the field's type
+        BasicType type = jbbf.getBasicType();
+        int rndIdx = Config.CFG.getRandomGen().nextInt(basicTypeAnnotations.get(type).size());
+        Jsr303MetaAnnotationSet mas = basicTypeAnnotations.get(type).get(rndIdx);
+
+        // Annotate the field
+        // TODO: Groups
+        for (MetaAnnotation ma : mas.getAnnotations()) {
+            jbbf.addAnnotation(ma);
+        }
+
+        jbbf.setValidValues(mas.getValidValues());
+        jbbf.setInvalidValues(mas.getInvalidValues());
+    }
+
+    @Override
+    public void annotate(MetaJavaBean mjb) {
+        // Annotate the fields
+        for (AbstractMetaField amf : mjb.getFields()) {
+            amf.accept(this);
+        }
+
+        // Annotate the java bean
+        mjb.addAnnotation(classAnnotations.get(0));
+    }
+
+
+    // Init methods ------------------------------------------------------------
+
+    private List<MetaGroup> generateGroups() {
+        List<MetaGroup> groups = Lists.newArrayList();
+        for (int i = 0; i < Config.CFG.getNumGroups(); ++i) {
+            MetaGroup mg = new MetaGroup(codeModel, Config.CFG.getGroupsPackageName() + ".Group" + i);
+            groups.add(mg);
+        }
+        return groups;
+    }
+
+    private ListMultimap<BasicType, Jsr303MetaAnnotationSet> buildBasicTypeAnnotations() {
+
+        ListMultimap<BasicType, Jsr303MetaAnnotationSet> anns = ArrayListMultimap.create();
+
+        HashSet<MetaAnnotation> annotationsSet;
+        HashMap<String, Object> annotParams;
+
+        // ### STRING ----------------------------------------------------------
+
+        // @NotNull / "good" / null
+        annotationsSet = Sets.newHashSet();
+        annotParams = Maps.newHashMap();
+        annotParams.put("message", "cannot be null");
+        annotationsSet.add(new MetaAnnotation(codeModel, NotNull.class, AnnotationType.JSR_303, annotParams));
+        anns.put(BasicType.STRING, new Jsr303MetaAnnotationSet(annotationsSet, Lists.newArrayList((Object) "good"), Lists.newArrayList((Object) null)));
+
+        // [@NotNull, @Size(min=6,max=12)] / [ "goodgood" ] / [ null, "bad" ]
+        annotationsSet = Sets.newHashSet();
+        annotParams = Maps.newHashMap();
+        annotParams.put("message", "cannot be null");
+        annotationsSet.add(new MetaAnnotation(codeModel, NotNull.class, AnnotationType.JSR_303, annotParams));
+        annotParams = Maps.newHashMap();
+        annotParams.put("min", 6);
+        annotParams.put("max", 12);
+        annotationsSet.add(new MetaAnnotation(codeModel, Size.class, AnnotationType.JSR_303, annotParams));
+        anns.put(BasicType.STRING, new Jsr303MetaAnnotationSet(annotationsSet, Lists.newArrayList((Object) "goodgood"), Lists.newArrayList((Object) null, "bad")));
+
+
+        // ### INTEGER ---------------------------------------------------------
+
+        // @NotNull / 3 / null
+        annotationsSet = Sets.newHashSet();
+        annotParams = Maps.newHashMap();
+        annotParams.put("message", "cannot be null");
+        annotationsSet.add(new MetaAnnotation(codeModel, NotNull.class, AnnotationType.JSR_303, annotParams));
+        anns.put(BasicType.INTEGER, new Jsr303MetaAnnotationSet(annotationsSet, Lists.newArrayList((Object) 3), Lists.newArrayList((Object) null)));
+
+        // @Min(100) @Max(200) / [ 155, null ] / [ -100, 4000 ]
+        annotationsSet = Sets.newHashSet();
+        annotParams = Maps.newHashMap();
+        annotParams.put("message", "must be bigger than {value}");
+        annotParams.put("value", 100);
+        annotationsSet.add(new MetaAnnotation(codeModel, Min.class, AnnotationType.JSR_303, annotParams));
+        annotParams = Maps.newHashMap();
+        annotParams.put("message", "must be less than {value}");
+        annotParams.put("value", 200);
+        annotationsSet.add(new MetaAnnotation(codeModel, Max.class, AnnotationType.JSR_303, annotParams));
+        anns.put(BasicType.INTEGER, new Jsr303MetaAnnotationSet(annotationsSet, Lists.newArrayList((Object) 155, null), Lists.newArrayList((Object) (-100), 4000)));
+
+        return anns;
+    }
+
+    private List<MetaAnnotation> buildClassAnnotations() {
+
+        List<MetaAnnotation> anns = Lists.newArrayList();
+
+        HashMap<String, Object> annotParams;
+
+
+        try {
+
+            // OddHashcode class constraint ------------------------------------
+
+            JDefinedClass oddHashCode = codeModel._class(Config.CFG.getBasePackageName() + ".annot.OddHashCode", ClassType.ANNOTATION_TYPE_DECL);
+            oddHashCode.annotate(Documented.class);
+            oddHashCode.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
+            oddHashCode.annotate(Target.class).paramArray("value").param(ElementType.TYPE).param(ElementType.ANNOTATION_TYPE);
+
+            // TODO: This part will very likely be added as a string
+            JMethod grpMethod = oddHashCode.method(JMod.NONE, Class[].class, "groups");
+            grpMethod.declareDefaultValue(new JExpressionImpl() {
+                @Override
+                public void generate(JFormatter f) {
+                    f.p("{ }");
+                }
+            });
+
+            // Create the validator
+            JClass cv = (JClass) codeModel._ref(ConstraintValidator.class);
+            cv = cv.narrow(oddHashCode, (JClass) codeModel._ref(Object.class));
+            JDefinedClass validator = oddHashCode._class(JMod.STATIC | JMod.PUBLIC, "OddValidator");
+            validator._implements(cv);
+            validator.method(JMod.PUBLIC, void.class, "initialize").param(oddHashCode, "parameters");
+            JMethod isValid = validator.method(JMod.PUBLIC, boolean.class, "isValid");
+            JVar value = isValid.param(Object.class, "value");
+            isValid.param(ConstraintValidatorContext.class, "context");
+            isValid.body()._return(value.invoke("hashCode").mod(JExpr.lit(2)).eq(JExpr.lit(1)));
+
+            oddHashCode.annotate(Constraint.class).param("validatedBy", validator);
+
+
+            // AlwaysValid class constraint ------------------------------------
+
+            JDefinedClass alwaysValid = codeModel._class(Config.CFG.getBasePackageName() + ".annot.AlwaysValid", ClassType.ANNOTATION_TYPE_DECL);
+            alwaysValid.annotate(Documented.class);
+            alwaysValid.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
+            alwaysValid.annotate(Target.class).paramArray("value").param(ElementType.TYPE).param(ElementType.ANNOTATION_TYPE);
+            alwaysValid.direct("\n" + "    Class<?>[] groups() default {};\n" + "    String message() default \"Invalid value\";\n" + "    Class<? extends Payload>[] payload() default {};\n");
+
+            alwaysValid.javadoc().addThrows((JClass) codeModel._ref(Payload.class)).add("Force import");
+
+            // Create the validator
+            cv = (JClass) codeModel._ref(ConstraintValidator.class);
+            cv = cv.narrow(alwaysValid, (JClass) codeModel._ref(Object.class));
+            validator = alwaysValid._class(JMod.STATIC | JMod.PUBLIC, "AlwaysValidValidator");
+            validator._implements(cv);
+            validator.method(JMod.PUBLIC, void.class, "initialize").param(alwaysValid, "parameters");
+            isValid = validator.method(JMod.PUBLIC, boolean.class, "isValid");
+            isValid.param(Object.class, "value");
+            isValid.param(ConstraintValidatorContext.class, "context");
+            isValid.body()._return(JExpr.TRUE);
+
+            alwaysValid.annotate(Constraint.class).param("validatedBy", validator);
+
+            annotParams = Maps.newHashMap();
+
+            anns.add(new MetaAnnotation(alwaysValid, AnnotationType.JSR_303, annotParams));
+
+        } catch (JClassAlreadyExistsException e) {
+            e.printStackTrace();
+        }
+
+        return anns;
+    }
+    
+    /*
+     * Nested constraint
+     * 
+@Documented
+@Pattern(regexp=".*")
+@Size.List( {@Size(min=5), @Size(max=8)} )
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })
+public @interface NestedConstraint1 {
+    
+    Class<?>[] groups() default {};
+    String message() default "Invalid value";
+    Class<? extends Payload>[] payload() default {};
+    
+}
+     */
+
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303Annotator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303MetaAnnotationSet.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303MetaAnnotationSet.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303MetaAnnotationSet.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303MetaAnnotationSet.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,63 @@
+/*
+ * 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.bench.jsr303;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.bval.bench.metatree.MetaAnnotation;
+
+/**
+ * This class groups a set of JSR-303 {@link MetaAnnotation} with a list of
+ * valid values and a list of invalid values.
+ * 
+ * @author Carlos Vara
+ */
+public class Jsr303MetaAnnotationSet {
+
+    // The annotations
+    private final Set<MetaAnnotation> annotations;
+    
+    // A set of valid values
+    private final List<Object> validValues;
+    
+    // A set of invalid values
+    private final List<Object> invalidValues;
+    
+    
+    public Jsr303MetaAnnotationSet(Set<MetaAnnotation> annotations, List<Object> validValues, List<Object> invalidValues) {
+        this.annotations = annotations;
+        this.validValues = validValues;
+        this.invalidValues = invalidValues;
+    }
+
+
+    public Set<MetaAnnotation> getAnnotations() {
+        return annotations;
+    }
+
+    public List<Object> getValidValues() {
+        return validValues;
+    }
+
+    public List<Object> getInvalidValues() {
+        return invalidValues;
+    }    
+    
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/Jsr303MetaAnnotationSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/MetaGroup.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/MetaGroup.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/MetaGroup.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/MetaGroup.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.bench.jsr303;
+
+import org.apache.bval.bench.metatree.AbstractMetaInterface;
+import com.sun.codemodel.JCodeModel;
+
+/**
+ * The declaration of a JSR-303 group.
+ * 
+ * @author Carlos Vara
+ */
+public class MetaGroup extends AbstractMetaInterface {
+
+    public MetaGroup(JCodeModel cm, String fqn) {
+        super(cm, fqn);
+    }
+    
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/jsr303/MetaGroup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractBaseMetaClass.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractBaseMetaClass.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractBaseMetaClass.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractBaseMetaClass.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,87 @@
+/*
+ * 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.bench.metatree;
+
+import com.sun.codemodel.ClassType;
+import com.sun.codemodel.JClassAlreadyExistsException;
+import com.sun.codemodel.JCodeModel;
+import com.sun.codemodel.JDefinedClass;
+
+
+/**
+ * Wraps a {@link JDefinedClass}. This class is extended to represent classes
+ * and interfaces (and may be extended to represent @interfaces and enums too).
+ * 
+ * @author Carlos Vara
+ */
+public abstract class AbstractBaseMetaClass {
+
+    // The wrapped JDefinedClass
+    private JDefinedClass generatedClass;
+    
+    public AbstractBaseMetaClass(JCodeModel cm, String fqn, ClassType ct) {
+        try {
+            this.generatedClass = cm._class(fqn, ct);
+        } catch (JClassAlreadyExistsException e) {
+            throw new IllegalStateException("Class: " + fqn + " already exists.", e);
+        }
+    }
+
+    /**
+     * @return The wrapped generated class.
+     */
+    public JDefinedClass getGeneratedClass() {
+        return generatedClass;
+    }
+
+    /**
+     * @return The unqualified name of the class.
+     */
+    public String getName() {
+        return generatedClass.name();
+    }
+    
+    /**
+     * @return The name of the package in which this class is placed.
+     */
+    public String getPackageName() {
+        return generatedClass.getPackage().name();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if ( (obj == null) || !(obj instanceof AbstractBaseMetaClass) ) {
+            return false;
+        }
+        AbstractBaseMetaClass otherAbmc = (AbstractBaseMetaClass)obj;
+        if ( this.generatedClass == null ) {
+            return otherAbmc.generatedClass == null;
+        }
+        else {
+            return this.generatedClass.equals(otherAbmc.generatedClass);
+        }
+    }
+
+    @Override
+    public int hashCode() {
+        // TODO Auto-generated method stub
+        return super.hashCode();
+    }
+
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractBaseMetaClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaField.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaField.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaField.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaField.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.bench.metatree;
+
+import java.util.Set;
+import org.apache.bval.bench.Annotable;
+import com.google.common.collect.Sets;
+import com.sun.codemodel.JFieldVar;
+
+
+/**
+ * Wraps a {@link JFieldVar}.
+ * 
+ * @author Carlos Vara
+ */
+public abstract class AbstractMetaField implements Annotable {
+
+    // The wrapped field
+    protected JFieldVar generatedField;
+
+    // The set of annotations for this field
+    protected Set<MetaAnnotation> annotations = Sets.newHashSet();
+
+    // The name of the field
+    protected String name;
+
+
+    public JFieldVar getGeneratedField() {
+        return generatedField;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaInterface.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaInterface.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaInterface.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaInterface.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,38 @@
+/*
+ * 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.bench.metatree;
+
+import com.sun.codemodel.ClassType;
+import com.sun.codemodel.JCodeModel;
+
+
+/**
+ * A simple interface, used now to hold a group.
+ * 
+ * @author Carlos Vara
+ */
+public abstract class AbstractMetaInterface extends AbstractBaseMetaClass {
+
+    public AbstractMetaInterface(JCodeModel cm, String fqn) {
+
+        super(cm, fqn, ClassType.INTERFACE);
+
+    }
+
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/AbstractMetaInterface.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaAnnotation.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaAnnotation.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaAnnotation.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaAnnotation.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,75 @@
+/*
+ * 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.bench.metatree;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.bval.bench.AnnotationType;
+import com.sun.codemodel.JClass;
+import com.sun.codemodel.JCodeModel;
+import com.sun.codemodel.JDefinedClass;
+
+/**
+ * Wraps a JClass that represents an annotation and its parameters.
+ * 
+ * @author Carlos Vara
+ */
+public class MetaAnnotation {
+
+    // An annotation type: JSR-303, OTHER
+    private final AnnotationType annotationType;
+    
+    // The class of the annotation, which is what it defines its equals()
+    private JClass annotationJClass;
+
+    // A HashMap of the attributes
+    private Map<String,Object> parameters;
+    
+    
+    public MetaAnnotation(JCodeModel cm, Class<? extends Annotation> annotationClass, AnnotationType annotationType, Map<String,Object> parameters) {
+        this.annotationJClass = (JClass) cm._ref(annotationClass);
+        this.annotationType = annotationType;
+        this.parameters = parameters;
+    }
+    
+    
+    public MetaAnnotation(JDefinedClass annotationJClass, AnnotationType annotationType, HashMap<String, Object> parameters) {
+        this.annotationJClass = annotationJClass;
+        this.annotationType = annotationType;
+        this.parameters = parameters;
+    }
+
+    
+    public JClass getAnnotationClass() {
+        return annotationJClass;
+    }
+    
+    public AnnotationType getAnnotationType() {
+        return this.annotationType;
+    }
+
+    public Map<String,Object> getParameters() {
+        return parameters;
+    }
+    
+    
+    // TODO: equals + hashCode
+    
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaAnnotation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaJavaBean.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaJavaBean.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaJavaBean.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaJavaBean.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,120 @@
+/*
+ * 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.bench.metatree;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.bval.bench.Annotable;
+import org.apache.bval.bench.AnnotatorVisitor;
+import org.apache.bval.bench.Config;
+import org.apache.bval.bench.JavaBeanBasicField;
+import org.apache.bval.bench.JavaBeanRefField;
+import org.apache.bval.bench.Util;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.sun.codemodel.ClassType;
+import com.sun.codemodel.JAnnotationUse;
+import com.sun.codemodel.JCodeModel;
+import com.sun.codemodel.JMod;
+
+
+/**
+ * Models a JavaBean class:
+ * <ul>
+ * <li>Empty constructor</li>
+ * <li>All of its fields are private and accessible via getter/setter methods.</li>
+ * </ul>
+ * 
+ * @author Carlos Vara
+ */
+public class MetaJavaBean extends AbstractBaseMetaClass implements Annotable {
+
+    // The fields in this bean, indexed by their name
+    private final Map<String, AbstractMetaField> fields;
+
+    // The set of annotations for this bean
+    protected Set<MetaAnnotation> annotations = Sets.newHashSet();
+
+
+    /**
+     * Creates a new MetaJavaBean with random fields.
+     * 
+     * @param fqn
+     *            The fully qualified name of the bean's class.
+     * @param numFields
+     *            Number of simple type fields that will be added.
+     */
+    public MetaJavaBean(JCodeModel cm, String fqn, int numFields) {
+
+        super(cm, fqn, ClassType.CLASS);
+
+        // Empty constructor
+        getGeneratedClass().constructor(JMod.PUBLIC);
+
+        // Init the simple fields
+        this.fields = Maps.newHashMapWithExpectedSize(numFields);
+        for (int i = 0; i < numFields; ++i) {
+            String fieldName = "field" + i;
+            JavaBeanBasicField field = new JavaBeanBasicField(this, fieldName);
+            fields.put(fieldName, field);
+        }
+
+    }
+
+    /**
+     * Adds random fields referencing other mjb's.
+     * 
+     * @param beans
+     *            The list of available beans.
+     */
+    public void interrelate(List<MetaJavaBean> beans) {
+
+        final int numInterrelations = Config.CFG.rndNumInterralations();
+
+        for (int i = 0; i < numInterrelations; ++i) {
+            int refIndex = Config.CFG.getRandomGen().nextInt(beans.size());
+            String fieldName = "beanRef" + i;
+            JavaBeanRefField field = new JavaBeanRefField(this, fieldName, beans.get(refIndex));
+            fields.put(fieldName, field);
+        }
+    }
+
+
+    public Collection<AbstractMetaField> getFields() {
+        return this.fields.values();
+    }
+
+    @Override
+    public void accept(AnnotatorVisitor annotator) {
+        annotator.annotate(this);
+    }
+
+    @Override
+    public void addAnnotation(MetaAnnotation annot) {
+        if ( this.annotations.add(annot) ) {
+            JAnnotationUse genAnnot = getGeneratedClass().annotate(annot.getAnnotationClass());
+            for (String paramKey : annot.getParameters().keySet()) {
+                Util.addAnnotParam(genAnnot, paramKey, annot.getParameters().get(paramKey));
+            }
+        }
+    }
+
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/java/org/apache/bval/bench/metatree/MetaJavaBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/main/resources/generator.default.properties
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/main/resources/generator.default.properties?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/main/resources/generator.default.properties (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/main/resources/generator.default.properties Thu Jun 17 16:30:57 2010
@@ -0,0 +1,36 @@
+#
+# 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.    
+#
+#
+# Default set of properties.
+# You can override any value by creating a generator.properties file
+#
+generator.rnd.seed=12
+generator.outputdir=./target/generated-sources/beangraph
+generator.pkg.base=org.apache.bval.bench.generated
+generator.pkg.beans=org.apache.bval.bench.generated.beans
+generator.pkg.groups=org.apache.bval.bench.generated.groups
+generator.numbeans=200
+generator.numgroups=5
+generator.basicfields.min=4
+generator.basicfields.max=7
+generator.reffields.min=1
+generator.reffields.max=3
+generator.level1.fillrate=0.80
+generator.level2.fillrate=0.40
+generator.level3.fillrate=0.20
\ No newline at end of file

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/main/resources/generator.default.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/AbstractBenchTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/AbstractBenchTest.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/AbstractBenchTest.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/AbstractBenchTest.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,145 @@
+/*
+ * 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.bench;
+
+
+import javax.validation.Validator;
+
+import org.apache.bval.bench.generated.Holder;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+/**
+ * A simple unit test that benchmarks a validator impl.
+ * 
+ * @author Carlos Vara
+ */
+public abstract class AbstractBenchTest {
+    
+    // Each tested validator must override this
+    public abstract Validator getValidatorInNewFactory();
+    
+    
+    private static int TEST_TIMES = 10;
+    
+    private static Holder holder;
+    
+    // Variables to hold the results
+    private static long fpavTime = 0l;
+    private static long fpavErrors = 0l;
+    private static long rvTime = 0l;
+    private static long rvErrors = 0l;
+    private static long rpTime = 0l;
+    private static long rpDescs = 0l;
+    
+    
+    /**
+     * Tests the speed of validating beans that are already parsed.
+     */
+    @Test
+    public void checkRawValidationSpeed() {
+        
+        Validator validator = getValidatorInNewFactory();
+        
+        // Initial parse
+        for ( Object o : holder.beans ) {
+            rvErrors += validator.validate(o).size();
+        }
+        
+        // Check validation speed
+        for ( int i=0; i<TEST_TIMES; ++i ) {
+            long initTime = System.currentTimeMillis();
+            for ( Object o : holder.beans ) {
+                rvErrors += validator.validate(o).size();
+            }
+            rvTime += System.currentTimeMillis() - initTime;
+        }
+        
+    }
+
+    
+    /**
+     * Tests the speed of parsing beans without performing any validation.
+     */
+    @Test
+    public void checkRawParsingSpeed() {
+        
+        for ( int i=0; i<TEST_TIMES; ++i ) {
+            
+            // Validator in new factory
+            Validator validator = getValidatorInNewFactory();
+            
+            // Validate all the classes in the holder
+            long initTime = System.currentTimeMillis();
+            
+            for ( Object o : holder.beans ) {
+                rpDescs += (validator.getConstraintsForClass(o.getClass()).isBeanConstrained())?1:0;
+            }
+            
+            rpTime += System.currentTimeMillis() - initTime;
+        }
+        
+    }
+    
+    
+    /**
+     * Tests the speed of parsing and doing one validation of all the beans.
+     */
+    @Test
+    public void checkFirstParseAndValidateSpeed() {
+        
+        for ( int i=0; i<TEST_TIMES; ++i ) {
+        
+            // Validator in new factory
+            Validator validator = getValidatorInNewFactory();
+            
+            long initTime = System.currentTimeMillis();
+            for ( Object o : holder.beans ) {
+                fpavErrors += validator.validate(o).size();
+            }
+            
+            fpavTime += System.currentTimeMillis() - initTime;
+            
+        }
+
+    }
+
+    
+    /**
+     * Only create the bean graph once.
+     */
+    @BeforeClass
+    public static void createBeans() {
+        holder = new Holder();
+    }
+    
+    
+    /**
+     * After all tests are run, print the results.
+     */
+    @AfterClass
+    public static void printResults() {
+        System.out.printf("  Raw validation time:      %6dms {%d}\n", rvTime, rvErrors);
+        System.out.printf("  Raw parsing time:         %6dms {%d}\n", rpTime, rpDescs);
+        System.out.printf("  First parse and validate: %6dms {%d}\n", fpavTime, fpavErrors);
+    }
+    
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/AbstractBenchTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/ApacheTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/ApacheTest.java?rev=955667&view=auto
==============================================================================
--- incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/ApacheTest.java (added)
+++ incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/ApacheTest.java Thu Jun 17 16:30:57 2010
@@ -0,0 +1,44 @@
+/*
+ * 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.bench;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.junit.AfterClass;
+
+/**
+ * Tests Apache Bean Validation performance.
+ * 
+ * @author Carlos Vara
+ */
+public class ApacheTest extends AbstractBenchTest {
+
+    @Override
+    public Validator getValidatorInNewFactory() {
+        return Validation.byProvider(ApacheValidationProvider.class).configure().buildValidatorFactory().getValidator();
+    }
+
+    @AfterClass
+    public static void printValidatorName() {
+        System.out.println("APACHE");
+    }
+
+}

Propchange: incubator/bval/sandbox/jsr303-impl-bench/src/test/java/org/apache/bval/bench/ApacheTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message