You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/09/30 17:18:52 UTC

svn commit: r1392034 - in /openejb/trunk/openejb: container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java

Author: rmannibucau
Date: Sun Sep 30 15:18:51 2012
New Revision: 1392034

URL: http://svn.apache.org/viewvc?rev=1392034&view=rev
Log:
better integration for @WebXXX (tomcat call method we override too much for us so simply skip calls > 1 when processing is already done + fixing bad management of a map in core)

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
    openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1392034&r1=1392033&r2=1392034&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Sun Sep 30 15:18:51 2012
@@ -1127,7 +1127,7 @@ public class AnnotationDeployer implemen
                 }
 
                 final List<Annotated<Class<?>>> found = finder.findMetaAnnotatedClasses(clazz);
-                webModule.getWebAnnotatedClasses().putAll(metaToStr(found));
+                addWebAnnotatedClassInfo(webModule.getWebAnnotatedClasses(), found);
             }
 
             return webModule;
@@ -5174,22 +5174,21 @@ public class AnnotationDeployer implemen
         return classes;
     }
 
-    private static Map<String, Set<String>> metaToStr(final List<Annotated<Class<?>>> found) {
-        final Map<String, Set<String>> classes = new HashMap<String, Set<String>>(found.size());
+    private static Map<String, Set<String>> addWebAnnotatedClassInfo(final Map<String, Set<String>> classes, final List<Annotated<Class<?>>> found) {
         for (Annotated<Class<?>> clazz : found) {
             final Class<?> loadedClass = clazz.get();
 
             // url of the jar/folder containing the class
-            URL url;
+            String url;
             try {
-                url = JarLocation.jarLocation(loadedClass).toURI().toURL();
+                url = JarLocation.jarLocation(loadedClass).toURI().toURL().toExternalForm();
             } catch (MalformedURLException e) {
-                url = classLocation(loadedClass);
+                url = classLocation(loadedClass).toExternalForm();
             }
             Set<String> list = classes.get(url);
             if (list == null) {
                 list = new HashSet<String>();
-                classes.put(url.toExternalForm(), list);
+                classes.put(url, list);
             }
 
             // saving class url

Modified: openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java?rev=1392034&r1=1392033&r2=1392034&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java (original)
+++ openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java Sun Sep 30 15:18:51 2012
@@ -28,7 +28,6 @@ import org.apache.openejb.loader.SystemI
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.URLs;
-import org.xml.sax.InputSource;
 
 import javax.servlet.ServletContainerInitializer;
 import java.io.File;
@@ -50,6 +49,10 @@ public class OpenEJBContextConfig extend
 
     private TomcatWebAppBuilder.StandardContextInfo info;
 
+    // processAnnotationXXX is called for each folder of WEB-INF
+    // since we store all classes in WEB-INF we will do it only once so use this boolean to avoid multiple processing
+    private ThreadLocal<Boolean> webInfClassesAnnotationsProcessed = new ThreadLocal<Boolean>();
+
     public OpenEJBContextConfig(TomcatWebAppBuilder.StandardContextInfo standardContextInfo) {
         logger.debug("OpenEJBContextConfig({0})", standardContextInfo.toString());
         info = standardContextInfo;
@@ -123,8 +126,30 @@ public class OpenEJBContextConfig extend
         return classes;
     }
 
+    @Override // called before processAnnotationsFile so using it as hook to init webInfClassesAnnotationsProcessed
+    protected void processServletContainerInitializers(final Set<WebXml> fragments) {
+        webInfClassesAnnotationsProcessed.set(false);
+        try {
+            super.processServletContainerInitializers(fragments);
+        } catch (RuntimeException e) { // if exception occurs we have to clear the threadlocal
+            webInfClassesAnnotationsProcessed.remove();
+            throw e;
+        }
+    }
+
+    @Override // called after processAnnotationsXX so using it as hook to reset webInfClassesAnnotationsProcessed
+    protected void processAnnotations(final Set<WebXml> fragments, final boolean handlesTypesOnly) {
+        webInfClassesAnnotationsProcessed.remove();
+        super.processAnnotations(fragments, handlesTypesOnly);
+    }
+
+
     @Override
     protected void processAnnotationsFile(File file, WebXml fragment, boolean handlesTypesOnly) {
+        if (webInfClassesAnnotationsProcessed.get()) {
+            return;
+        }
+
         final WebAppInfo webAppInfo = info.get();
         if (webAppInfo == null) {
             super.processAnnotationsFile(file, fragment, handlesTypesOnly);
@@ -134,7 +159,7 @@ public class OpenEJBContextConfig extend
         for (ClassListInfo webAnnotated : webAppInfo.webAnnotatedClasses) {
             try {
                 final File classContainerAsFile = URLs.toFile(new URL(webAnnotated.name));
-                if (!isIncludedIn(file, classContainerAsFile)) {
+                if (!isIncludedIn(classContainerAsFile, file)) {
                     continue;
                 }
 
@@ -145,6 +170,7 @@ public class OpenEJBContextConfig extend
                 throw new IllegalArgumentException(e);
             }
         }
+        webInfClassesAnnotationsProcessed.set(true);
     }
 
     @Override
@@ -159,7 +185,7 @@ public class OpenEJBContextConfig extend
             try {
                 final File classContainerAsFile = URLs.toFile(new URL(webAnnotated.name));
                 final File currentUrlAsFile = URLs.toFile(currentUrl);
-                if (!isIncludedIn(currentUrlAsFile, classContainerAsFile)) {
+                if (!isIncludedIn(classContainerAsFile, currentUrlAsFile)) {
                     continue;
                 }