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/04/17 10:26:45 UTC

svn commit: r1326989 - /openejb/branches/openejb-4.0.0/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java

Author: rmannibucau
Date: Tue Apr 17 08:26:45 2012
New Revision: 1326989

URL: http://svn.apache.org/viewvc?rev=1326989&view=rev
Log:
scanning Applicationpath since link is not automatically called on finder

Modified:
    openejb/branches/openejb-4.0.0/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java

Modified: openejb/branches/openejb-4.0.0/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-4.0.0/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1326989&r1=1326988&r2=1326989&view=diff
==============================================================================
--- openejb/branches/openejb-4.0.0/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/branches/openejb-4.0.0/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Tue Apr 17 08:26:45 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.openejb.config;
 
+import javax.ws.rs.ApplicationPath;
 import org.apache.openejb.BeanContext;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.api.LocalClient;
@@ -1037,19 +1038,28 @@ public class AnnotationDeployer implemen
             */
             // get by annotations
             webModule.getRestClasses().addAll(findRestClasses(webModule, finder));
+
             // Applications with a default constructor
+            // findSubclasses will not work by default to gain a lot of time
+            // look FinderFactory for the flag to activate it or
+            // use @ApplicationPath("/")
             List<Class<? extends Application>> applications = finder.findSubclasses(Application.class);
             for (Class<? extends Application> app : applications) {
-                if (app.getConstructors().length == 0) {
-                    webModule.getRestApplications().add(app.getName());
-                } else {
-                    for (Constructor<?> ctr : app.getConstructors()) {
-                        if (ctr.getParameterTypes().length == 0) {
-                            webModule.getRestApplications().add(app.getName());
-                            break;
-                        }
-                    }
+                addRestApplicationIfPossible(webModule, app);
+            }
+
+            // look for ApplicationPath, it will often return the same than the previous one
+            // but without finder.link() invocation it still works
+            // so it can save a lot of startup time
+            List<Annotated<Class<?>>> applicationsByAnnotation = finder.findMetaAnnotatedClasses(ApplicationPath.class);
+            for (Annotated<Class<?>> annotatedApp : applicationsByAnnotation) {
+                final Class<?> app = annotatedApp.get();
+                if (!Application.class.isAssignableFrom(app)) {
+                    logger.error("class '" + app.getName() + "' is annotated with @ApplicationPath but doesn't implement " + Application.class.getName());
+                    continue;
                 }
+
+                addRestApplicationIfPossible(webModule, (Class<? extends Application>) app);
             }
 
             /*
@@ -1092,6 +1102,19 @@ public class AnnotationDeployer implemen
             return webModule;
         }
 
+        private static void addRestApplicationIfPossible(final WebModule webModule, final Class<? extends Application> app) {
+            if (app.getConstructors().length == 0) {
+                webModule.getRestApplications().add(app.getName());
+            } else {
+                for (Constructor<?> ctr : app.getConstructors()) {
+                    if (ctr.getParameterTypes().length == 0) {
+                        webModule.getRestApplications().add(app.getName());
+                        break;
+                    }
+                }
+            }
+        }
+
         public EjbModule deploy(EjbModule ejbModule) throws OpenEJBException {
             if (ejbModule.getEjbJar() != null && ejbModule.getEjbJar().isMetadataComplete()) return ejbModule;