geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r499274 - in /geronimo/server/trunk/modules: geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/ geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ geronimo-openejb-builder/src/main/java/org/...
Date Wed, 24 Jan 2007 06:15:16 GMT
Author: dain
Date: Tue Jan 23 22:15:15 2007
New Revision: 499274

URL: http://svn.apache.org/viewvc?view=rev&rev=499274
Log:
Deployments without an ejb-jar.xml file now work

Modified:
    geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARContext.java
    geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
    geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/AbstractEjbRefBuilder.java

Modified: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARContext.java?view=diff&rev=499274&r1=499273&r2=499274
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARContext.java
Tue Jan 23 22:15:15 2007
@@ -48,7 +48,7 @@
 
     private final Map  messageDestinations = new HashMap();
 
-    private final Map generalData = new HashMap();
+    private final Map<Object,Object> generalData = new HashMap<Object,Object>();
 
     public EARContext(File baseDir,
             File inPlaceConfigurationDir,
@@ -172,7 +172,7 @@
         return messageDestinations;
     }
 
-    public Map getGeneralData() {
+    public Map<Object,Object> getGeneralData() {
         return generalData;
     }
 }

Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java?view=diff&rev=499274&r1=499273&r2=499274
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
Tue Jan 23 22:15:15 2007
@@ -21,6 +21,7 @@
 import java.net.URI;
 import java.net.URL;
 import java.net.MalformedURLException;
+import java.net.URLClassLoader;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -83,6 +84,8 @@
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xbean.finder.ClassFinder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Master builder for processing EJB JAR deployments and creating the
@@ -91,6 +94,7 @@
  * @version $Revision: 479481 $ $Date: 2006-11-26 16:52:20 -0800 (Sun, 26 Nov 2006) $
  */
 public class EjbModuleBuilder implements ModuleBuilder {
+    private static final Log log = LogFactory.getLog(EjbModuleBuilder.class);
     private static final String OPENEJBJAR_NAMESPACE = XmlUtil.OPENEJBJAR_QNAME.getNamespaceURI();
 
     private final Environment defaultEnvironment;
@@ -143,46 +147,12 @@
 
         // load the ejb-jar.xml
         String ejbJarXml = XmlUtil.loadEjbJarXml(specDDUrl, moduleFile);
-        if (ejbJarXml == null) {
-            // this is not an ejb module
-            URL moduleUrl = null;
-            try {
-                File file = new File(moduleFile.getName());
-                moduleUrl = file.toURL();
-            } catch (MalformedURLException e) {
-                return null;
-            }
-
-            try {
-                final ClassFinder classFinder = new ClassFinder(Thread.currentThread().getContextClassLoader(),
moduleUrl);
-
-                // DMB: getting this via reflection is a temporary fix.  Just want to avoid
having to
-                // make Geronimo dependent on an xbean snapshot right before we do the release.
-                // afterwards we can clean this up.
-                Map<String, List> annotated = (Map<String, List>) AccessController.doPrivileged(new
PrivilegedAction() {
-                    public Object run() {
-                        try {
-                            Field field = ClassFinder.class.getDeclaredField("annotated");
-                            field.setAccessible(true);
-                            return field.get(classFinder);
-                        } catch (Exception e2) {
-                        }
-                        return null;
-                    }
-                });
-
-                List<String> beans = new ArrayList<String>();
-                beans.addAll(annotated.get(javax.ejb.Stateless.class.getName()));
-                beans.addAll(annotated.get(javax.ejb.Stateful.class.getName()));
-                beans.addAll(annotated.get(javax.ejb.MessageDriven.class.getName()));
-                if (beans.size() <= 0){
-                    return null;
-                }
-            } catch (Throwable e) {
-                // how does one log this?
-                return null;
-            }
+        // if there is no ejb-jar.xml and the module does not contain any
+        // classes annotated with ejb annotations, it is not an ejb module
+        if (ejbJarXml == null && !isEjbAnnotatedModule(moduleFile)) {
+            return null;
         }
+
         EjbJar ejbJar = XmlUtil.unmarshal(EjbJar.class, ejbJarXml);
         if (ejbJar == null){
             ejbJar = new EjbJar();
@@ -258,6 +228,48 @@
         }
 
         return new EjbModule(standAlone, moduleName, environment, moduleFile, targetPath,
ejbJar, openejbJar, geronimoOpenejb, ejbJarXml, sharedContext);
+    }
+
+    private boolean isEjbAnnotatedModule(JarFile moduleFile) {
+        // this is not an ejb module
+        URL moduleUrl = null;
+        try {
+            File file = new File(moduleFile.getName());
+            moduleUrl = file.toURL();
+        } catch (MalformedURLException e) {
+            return false;
+        }
+
+        try {
+            URLClassLoader tempClassLoader = new URLClassLoader(new URL[]{moduleUrl}, Thread.currentThread().getContextClassLoader());
+            final ClassFinder classFinder = new ClassFinder(tempClassLoader, moduleUrl);
+
+            // DMB: getting this via reflection is a temporary fix.  Just want to avoid having
to
+            // make Geronimo dependent on an xbean snapshot right before we do the release.
+            // afterwards we can clean this up.
+            Map<String, List> annotated = AccessController.doPrivileged(new PrivilegedAction<Map<String,
List>>() {
+                public Map<String, List> run() {
+                    try {
+                        Field field = ClassFinder.class.getDeclaredField("annotated");
+                        field.setAccessible(true);
+                        return (Map<String, List>) field.get(classFinder);
+                    } catch (Exception e2) {
+                    }
+                    return null;
+                }
+            });
+
+            if (!isEmpty(annotated.get(javax.ejb.Stateless.class.getName()))) return true;
+            if (!isEmpty(annotated.get(javax.ejb.Stateful.class.getName()))) return true;
+            if (!isEmpty(annotated.get(javax.ejb.MessageDriven.class.getName()))) return
true;
+        } catch (Throwable e) {
+            log.warn("Error while attempting to determine if a module is an EJB moduel",
e);
+        }
+        return false;
+    }
+
+    private static boolean isEmpty(List l) {
+        return l == null || l.isEmpty();
     }
 
     protected static void unmapReferences(EjbJar ejbJar) {

Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/AbstractEjbRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/AbstractEjbRefBuilder.java?view=diff&rev=499274&r1=499273&r2=499274
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/AbstractEjbRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/AbstractEjbRefBuilder.java
Tue Jan 23 22:15:15 2007
@@ -47,6 +47,7 @@
 import org.apache.openejb.alt.config.JndiEncInfoBuilder;
 import org.apache.openejb.assembler.classic.JndiEncInfo;
 import org.apache.openejb.assembler.classic.JndiEncBuilder;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
 import org.apache.openejb.OpenEJBException;
 
 /**
@@ -61,8 +62,12 @@
     protected void bindContext(Module module, JndiConsumer jndiConsumer, Map componentContext)
throws DeploymentException {
         Map<String, Object> map = null;
         try {
-            EjbModuleBuilder.EarData earData = (EjbModuleBuilder.EarData) module.getEarContext().getGeneralData().get(EjbModuleBuilder.EarData.class);
-            JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(earData.getEjbJars());
+            EjbModuleBuilder.EarData earData = (EjbModuleBuilder.EarData) module.getRootEarContext().getGeneralData().get(EjbModuleBuilder.EarData.class);
+            Collection<EjbJarInfo> ejbJars = Collections.emptySet();
+            if (earData != null) {
+                ejbJars = earData.getEjbJars();
+            }
+            JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(ejbJars);
             JndiEncInfo jndiEncInfo = jndiEncInfoBuilder.build(jndiConsumer, "GeronimoEnc");
             JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(jndiEncInfo);
             map = jndiEncBuilder.buildMap();



Mime
View raw message