[jboss-cvs] JBossAS SVN: r86168 - in projects/ejb3/trunk: annotation-finder and 20 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Mar 20 12:58:15 EDT 2009


Author: wolfc
Date: 2009-03-20 12:58:15 -0400 (Fri, 20 Mar 2009)
New Revision: 86168

Added:
   projects/ejb3/trunk/annotation-finder/
   projects/ejb3/trunk/annotation-finder/.classpath
   projects/ejb3/trunk/annotation-finder/.project
   projects/ejb3/trunk/annotation-finder/.settings/
   projects/ejb3/trunk/annotation-finder/.settings/org.eclipse.jdt.core.prefs
   projects/ejb3/trunk/annotation-finder/.settings/org.maven.ide.eclipse.prefs
   projects/ejb3/trunk/annotation-finder/pom.xml
   projects/ejb3/trunk/annotation-finder/src/
   projects/ejb3/trunk/annotation-finder/src/main/
   projects/ejb3/trunk/annotation-finder/src/main/java/
   projects/ejb3/trunk/annotation-finder/src/main/java/org/
   projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/
   projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/
   projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/
   projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/
   projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/AnnotationFinderEnvironmentBridge.java
   projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/MyHashMap.java
   projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/MyMap.java
   projects/ejb3/trunk/annotation-finder/src/test/
   projects/ejb3/trunk/annotation-finder/src/test/java/
   projects/ejb3/trunk/annotation-finder/src/test/java/org/
   projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/
   projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/
   projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/
   projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/
   projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/
   projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/
   projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/MyStatefulBean.java
   projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/MyStatelessBean.java
   projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/unit/
   projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/unit/SimpleTestCase.java
   projects/ejb3/trunk/annotation-finder/src/test/resources/
   projects/ejb3/trunk/annotation-finder/src/test/resources/log4j.xml
Log:
initial setup of a annotation finder bridge onto annotation environment


Property changes on: projects/ejb3/trunk/annotation-finder
___________________________________________________________________
Name: svn:ignore
   + eclipse-target
target


Added: projects/ejb3/trunk/annotation-finder/.classpath
===================================================================
--- projects/ejb3/trunk/annotation-finder/.classpath	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/.classpath	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,8 @@
+<classpath>
+  <classpathentry kind="src" path="src/main/java"/>
+  <classpathentry kind="src" path="src/test/java" output="eclipse-target/tests-classes"/>
+  <classpathentry kind="src" path="src/test/resources" output="eclipse-target/tests-classes" excluding="**/*.java"/>
+  <classpathentry kind="output" path="eclipse-target/classes"/>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+  <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+</classpath>
\ No newline at end of file

Added: projects/ejb3/trunk/annotation-finder/.project
===================================================================
--- projects/ejb3/trunk/annotation-finder/.project	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/.project	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,18 @@
+<projectDescription>
+  <name>jboss-ejb3-annotation-finder</name>
+  <comment>The JBoss Annotation Finder component defines the bridge
+    between AnnotationFinder and AnnotationEnvironment.</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+    <buildCommand>
+      <name>org.maven.ide.eclipse.maven2Builder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+    <nature>org.maven.ide.eclipse.maven2Nature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Added: projects/ejb3/trunk/annotation-finder/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/ejb3/trunk/annotation-finder/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/.settings/org.eclipse.jdt.core.prefs	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,5 @@
+#Fri Mar 20 14:29:41 CET 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5

Added: projects/ejb3/trunk/annotation-finder/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- projects/ejb3/trunk/annotation-finder/.settings/org.maven.ide.eclipse.prefs	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/.settings/org.maven.ide.eclipse.prefs	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,8 @@
+#Fri Mar 20 14:29:38 CET 2009
+activeProfiles=eclipse
+eclipse.preferences.version=1
+fullBuildGoals=
+includeModules=false
+resolveWorkspaceProjects=false
+resourceFilterGoals=
+version=1

Added: projects/ejb3/trunk/annotation-finder/pom.xml
===================================================================
--- projects/ejb3/trunk/annotation-finder/pom.xml	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/pom.xml	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,45 @@
+<!-- 
+  vi:ts=2:sw=2:expandtab 
+-->
+<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">
+  <parent>
+    <groupId>org.jboss.ejb3</groupId>
+    <artifactId>jboss-ejb3-build</artifactId>
+    <version>1.0.1</version>
+    <relativePath>../build/pom.xml</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jboss-ejb3-annotation-finder</artifactId>
+  <version>0.1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <name>JBoss Annotation Finder</name>
+  <url>http://www.jboss.org</url>
+  <description>
+    The JBoss Annotation Finder component defines the bridge
+    between AnnotationFinder and AnnotationEnvironment.
+  </description>
+  
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.deployers</groupId>
+      <artifactId>jboss-deployers-impl</artifactId>
+      <version>2.0.5.GA</version>
+      <scope>test</scope>
+    </dependency>    
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-log4j</artifactId>
+      <scope>test</scope>
+    </dependency>    
+    <dependency>
+      <groupId>org.jboss.metadata</groupId>
+      <artifactId>jboss-metadata</artifactId>
+      <version>1.0.0.CR17</version>
+    </dependency>    
+  </dependencies>
+</project>

Added: projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/AnnotationFinderEnvironmentBridge.java
===================================================================
--- projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/AnnotationFinderEnvironmentBridge.java	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/AnnotationFinderEnvironmentBridge.java	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.annotation.finder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
+import org.jboss.deployers.spi.annotations.Element;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class AnnotationFinderEnvironmentBridge<E extends AnnotatedElement> implements AnnotationFinder<E>
+{
+   private static final Logger log = Logger.getLogger(AnnotationFinderEnvironmentBridge.class);
+   
+   private static final Annotation NONE = new Annotation() {
+      public Class<? extends Annotation> annotationType()
+      {
+         return Annotation.class;
+      }
+   };
+   
+   private AnnotationEnvironment env;
+   
+   private Map<AnnotatedElement, MyMap<? extends Annotation>> cache = new HashMap<AnnotatedElement, MyMap<? extends Annotation>>();
+   
+   public AnnotationFinderEnvironmentBridge(AnnotationEnvironment env)
+   {
+      assert env != null : "env is null";
+      this.env = env;
+   }
+   
+   public <T extends Annotation> T getAnnotation(E element, Class<T> annotationType)
+   {
+      MyMap<? extends Annotation> cached = cache.get(element);
+      if(cached == null)
+      {
+         synchronized(cache)
+         {
+            cached = cache.get(element);
+            if(cached == null)
+            {
+               cached = new MyHashMap<T>();
+               cache.put(element, cached);
+            }
+         }
+      }
+      
+      Annotation annotation = cached.get(annotationType);
+      if(annotation == null)
+      {
+         synchronized(cached)
+         {
+            annotation = cached.get(annotationType);
+            if(annotation == null)
+            {
+               Set<Element<T, ?>> elements;
+               if(element instanceof Class)
+                  elements = (Set) env.classIsAnnotatedWith(annotationType);
+               else if(element instanceof Field)
+                  elements = (Set) env.classHasFieldAnnotatedWith(annotationType);
+               else if(element instanceof Method)
+                  elements = (Set) env.classHasMethodAnnotatedWith(annotationType);
+               else
+                  throw new UnsupportedOperationException("AnnotationEnvironment has no support for " + element);
+               for(Element<T, ?> e : elements)
+               {
+                  MyMap<? extends Annotation> m = cache.get(e.getAnnotatedElement());
+                  if(m == null)
+                  {
+                     MyMap<T> newEntry = (MyMap<T>) cached;
+                     newEntry.put(annotationType, e.getAnnotation());
+                     cache.put(e.getAnnotatedElement(), newEntry);
+                     m = newEntry;
+                  }
+                  else
+                  {
+                     MyMap<T> newEntry = (MyMap<T>) m;
+                     newEntry.put(annotationType, e.getAnnotation());
+                  }
+               }
+            }
+            annotation = cached.get(annotationType);
+            if(annotation == null)
+            {
+               annotation = NONE;
+            }
+            assert annotation != null;
+         }
+      }
+      if(annotation == NONE)
+         return null;
+      return (T) annotation;
+   }
+
+   public Annotation[] getAnnotations(E element)
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public Annotation[] getDeclaredAnnotations(E element)
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public boolean isAnnotationPresent(E element, Class<? extends Annotation> annotationType)
+   {
+      return getAnnotation(element, annotationType) != null;
+   }
+}

Added: projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/MyHashMap.java
===================================================================
--- projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/MyHashMap.java	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/MyHashMap.java	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.annotation.finder;
+
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MyHashMap<C> extends HashMap<Class<C>, C> 
+   implements MyMap<C>
+{
+   private static final long serialVersionUID = 1L;
+}

Added: projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/MyMap.java
===================================================================
--- projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/MyMap.java	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/src/main/java/org/jboss/ejb3/annotation/finder/MyMap.java	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.annotation.finder;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface MyMap<C> extends Map<Class<C>, C>
+{
+
+}

Added: projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/MyStatefulBean.java
===================================================================
--- projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/MyStatefulBean.java	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/MyStatefulBean.java	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.annotation.finder.test.simple;
+
+import javax.annotation.Resource;
+import javax.ejb.Stateful;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+public class MyStatefulBean
+{
+   @Resource
+   private String s;
+}

Added: projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/MyStatelessBean.java
===================================================================
--- projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/MyStatelessBean.java	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/MyStatelessBean.java	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.annotation.finder.test.simple;
+
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+public class MyStatelessBean
+{
+   @TransactionAttribute(TransactionAttributeType.MANDATORY)
+   public void mandatory()
+   {
+      
+   }
+}

Added: projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/unit/SimpleTestCase.java
===================================================================
--- projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/unit/SimpleTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/src/test/java/org/jboss/ejb3/annotation/finder/test/simple/unit/SimpleTestCase.java	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,136 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.annotation.finder.test.simple.unit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.lang.reflect.AnnotatedElement;
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.jboss.classloading.plugins.visitor.DefaultResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.deployers.plugins.annotations.GenericAnnotationResourceVisitor;
+import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
+import org.jboss.ejb3.annotation.finder.AnnotationFinderEnvironmentBridge;
+import org.jboss.ejb3.annotation.finder.test.simple.MyStatefulBean;
+import org.jboss.ejb3.annotation.finder.test.simple.MyStatelessBean;
+import org.jboss.metadata.annotation.creator.ejb.jboss.JBoss50Creator;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleTestCase
+{
+   private static ResourceContext createResourceContext(String resourceName)
+   {
+      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+      URL url = classLoader.getResource(resourceName);
+      return new DefaultResourceContext(url, resourceName, classLoader);
+   }
+   
+   private void runTest(JBoss50Creator creator, Collection<Class<?>> classes)
+   {
+      JBoss50MetaData metaData = creator.create(classes);
+      
+      assertEquals(2, metaData.getEnterpriseBeans().size());
+      assertNotNull(metaData.getEnterpriseBean("MyStatefulBean"));
+      assertNotNull(metaData.getEnterpriseBean("MyStatelessBean"));
+      
+      assertNotNull(metaData.getEnterpriseBean("MyStatefulBean").getEnvironmentEntryByName("org.jboss.ejb3.annotation.finder.test.simple.MyStatefulBean/s"));      
+   }
+   
+   @Test
+   public void test1()
+   {
+      Collection<Class<?>> classes = new HashSet<Class<?>>();
+      classes.add(MyStatefulBean.class);
+      classes.add(MyStatelessBean.class);
+      
+      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+      GenericAnnotationResourceVisitor visitor = new GenericAnnotationResourceVisitor(classLoader);
+      for(Class<?> cls : classes)
+      {
+         visitor.visit(createResourceContext(cls.getName().replace('.', '/') + ".class"));
+      }
+      AnnotationEnvironment env = visitor.getEnv();
+      AnnotationFinder<AnnotatedElement> finder = new AnnotationFinderEnvironmentBridge<AnnotatedElement>(env);
+      JBoss50Creator creator = new JBoss50Creator(finder);
+      runTest(creator, classes);
+   }
+
+   @Test
+   public void testSpeedAnnotationEnvironment()
+   {
+      Collection<Class<?>> classes = new HashSet<Class<?>>();
+      classes.add(MyStatefulBean.class);
+      classes.add(MyStatelessBean.class);
+      
+      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+      GenericAnnotationResourceVisitor visitor = new GenericAnnotationResourceVisitor(classLoader);
+      for(Class<?> cls : classes)
+      {
+         visitor.visit(createResourceContext(cls.getName().replace('.', '/') + ".class"));
+      }
+      AnnotationEnvironment env = visitor.getEnv();
+      AnnotationFinder<AnnotatedElement> finder = new AnnotationFinderEnvironmentBridge<AnnotatedElement>(env);
+      
+      JBoss50Creator creator = new JBoss50Creator(finder);
+      long end = System.currentTimeMillis() + 5000;
+      long count = 0;
+      while(System.currentTimeMillis() < end)
+      {
+         runTest(creator, classes);
+         count++;
+      }
+      long delta = System.currentTimeMillis() - end + 5000;
+      System.out.println("AnnotationFinderEnvironmentBridge does " + count + " passes in " + delta + " ms");
+   }
+
+   @Test
+   public void testSpeedDefaultAnnotationFinder()
+   {
+      Collection<Class<?>> classes = new HashSet<Class<?>>();
+      classes.add(MyStatefulBean.class);
+      classes.add(MyStatelessBean.class);
+      
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+      
+      JBoss50Creator creator = new JBoss50Creator(finder);
+      long end = System.currentTimeMillis() + 5000;
+      long count = 0;
+      while(System.currentTimeMillis() < end)
+      {
+         runTest(creator, classes);
+         count++;
+      }
+      long delta = System.currentTimeMillis() - end + 5000;
+      System.out.println("DefaultAnnotationFinder does " + count + " passes in " + delta + " ms");
+   }
+}

Added: projects/ejb3/trunk/annotation-finder/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/annotation-finder/src/test/resources/log4j.xml	                        (rev 0)
+++ projects/ejb3/trunk/annotation-finder/src/test/resources/log4j.xml	2009-03-20 16:58:15 UTC (rev 86168)
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!--                                                                       -->
+<!--  Log4j Configuration                                                  -->
+<!--                                                                       -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml 68671 2008-01-08 10:04:25Z wolfc $ -->
+
+<!--
+   | For more configuration infromation and examples see the Jakarta Log4j
+   | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+  <!-- ================================= -->
+  <!-- Preserve messages in a local file -->
+  <!-- ================================= -->
+
+  <!-- A time/date based rolling appender -->
+  <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
+    <param name="File" value="target/test.log"/>
+    <param name="Append" value="false"/>
+
+    <!-- Rollover at midnight each day -->
+    <param name="DatePattern" value="'.'yyyy-MM-dd"/>
+
+    <!-- Rollover at the top of each hour
+    <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
+    -->
+
+    <layout class="org.apache.log4j.PatternLayout">
+      <!-- The default pattern: Date Priority [Category] Message\n -->
+      <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+
+      <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
+      <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+       -->
+    </layout>	    
+  </appender>
+
+  <!-- A size based file rolling appender
+  <appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
+    <param name="File" value="${jboss.server.home.dir}/log/server.log"/>
+    <param name="Append" value="false"/>
+    <param name="MaxFileSize" value="500KB"/>
+    <param name="MaxBackupIndex" value="1"/>
+
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+    </layout>	    
+  </appender>
+  -->
+
+  <!-- ============================== -->
+  <!-- Append messages to the console -->
+  <!-- ============================== -->
+
+  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out"/>
+    <param name="Threshold" value="DEBUG"/>
+
+    <layout class="org.apache.log4j.PatternLayout">
+      <!-- The default pattern: Date Priority [Category] Message\n -->
+      <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+    </layout>
+  </appender>
+
+
+  <!-- ================ -->
+  <!-- Limit categories -->
+  <!-- ================ -->
+
+  <!-- Limit JBoss categories to INFO
+  <category name="org.jboss">
+    <priority value="INFO" class="org.jboss.logging.XLevel"/>
+  </category>
+  -->
+
+  <!-- Increase the priority threshold for the DefaultDS category
+  <category name="DefaultDS">
+    <priority value="FATAL"/>
+  </category>
+  -->
+
+  <!-- Decrease the priority threshold for the org.jboss.varia category
+  <category name="org.jboss.varia">
+    <priority value="DEBUG"/>
+  </category>
+  -->
+
+  <!--
+     | An example of enabling the custom TRACE level priority that is used
+     | by the JBoss internals to diagnose low level details. This example
+     | turns on TRACE level msgs for the org.jboss.ejb.plugins package and its
+     | subpackages. This will produce A LOT of logging output.
+  <category name="org.jboss.system">
+    <priority value="TRACE" class="org.jboss.logging.XLevel"/>
+  </category>
+  -->
+
+  <category name="org.jboss.aop">
+    <priority value="WARN"/>
+  </category>
+  
+  <category name="org.jboss">
+    <priority value="ALL"/>
+  </category>
+  
+  <!-- 
+  Unnecessary, EJB3 is exposed as DEBUG
+  <category name="org.jboss.ejb3.interceptors.aop.DomainClassLoader">
+    <priority value="DEBUG"/>
+  </category>   -->
+  
+  <!-- ======================= -->
+  <!-- Setup the Root category -->
+  <!-- ======================= -->
+
+  <root>
+    <priority value="INFO" />
+    <appender-ref ref="CONSOLE"/>
+    <appender-ref ref="FILE"/>
+  </root>
+  
+</log4j:configuration>




More information about the jboss-cvs-commits mailing list