geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r522078 - in /geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment: EjbModuleBuilder.java EjbRefBuilder.java
Date Sat, 24 Mar 2007 18:15:21 GMT
Author: dain
Date: Sat Mar 24 11:15:20 2007
New Revision: 522078

URL: http://svn.apache.org/viewvc?view=rev&rev=522078
Log:
Fix cross module JNDI link refs

Modified:
    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/EjbRefBuilder.java

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=522078&r1=522077&r2=522078
==============================================================================
--- 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
Sat Mar 24 11:15:20 2007
@@ -20,7 +20,6 @@
 import java.io.IOException;
 import java.net.URI;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -364,6 +363,13 @@
     }
 
     private void installModule(Module module, EARContext earContext) throws DeploymentException
{
+        EarData earData = (EarData) earContext.getGeneralData().get(EarData.class);
+        if (earData == null) {
+            earData = new EarData();
+            earContext.getGeneralData().put(EarData.class, earData);
+        }
+        earData.addEjbModule((EjbModule) module);
+
         JarFile moduleFile = module.getModuleFile();
         try {
             // extract the ejbJar file into a standalone packed jar file and add the contents
to the output
@@ -393,45 +399,10 @@
     public void initContext(EARContext earContext, Module module, ClassLoader classLoader)
throws DeploymentException {
         EjbModule ejbModule = (EjbModule) module;
         ejbModule.setClassLoader(classLoader);
+        EjbJarInfo ejbJarInfo = getEjbJarInfo(earContext, ejbModule, classLoader);
 
-        // build the config info tree
-        // this method fills in the ejbJar jaxb tree based on the annotations
-        // (metadata complete) and it run the openejb verifier
-        AppModule appModule = new AppModule(ejbModule.getEjbModule().getClassLoader(), ejbModule.getEjbModule().getModuleId());
-        appModule.getEjbModules().add(ejbModule.getEjbModule());
-        AppInfo appInfo;
-        EjbJarInfo ejbJarInfo;
-        try {
-            appInfo = openEjbSystem.configureApplication(appModule);
-            ejbJarInfo = appInfo.ejbJars.get(0);
-            ejbModule.setEjbJarInfo(ejbJarInfo);
-        } catch (OpenEJBException e) {
-            e.printStackTrace();
-            throw new DeploymentException(e);
-        }
-        EarData earData = (EarData) earContext.getGeneralData().get(EarData.class);
-        if (earData == null) {
-            earData = new EarData();
-            earContext.getGeneralData().put(EarData.class, earData);
-        }
-        earData.getEjbJars().add(ejbJarInfo);
 
-        // generate the CMP2 implementation classes
-        // Generate the cmp2 concrete subclasses
-        CmpJarBuilder cmp2Builder = new CmpJarBuilder(appInfo, classLoader);
-        try {
-            File generatedJar = cmp2Builder.getJarFile();
-            if (generatedJar != null) {
-                String generatedPath = module.getTargetPath();
-                if (generatedPath.endsWith(".jar")) {
-                    generatedPath = generatedPath.substring(0, generatedPath.length() - 4);
-                }
-                generatedPath += "-cmp2.jar";
-                earContext.addInclude(URI.create(generatedPath), generatedJar);
-            }
-        } catch (IOException e) {
-            throw new DeploymentException(e);
-        }
+        ejbModule.setEjbJarInfo(ejbJarInfo);
 
         // update the original spec dd with the metadata complete dd
         EjbJar ejbJar = ejbModule.getEjbJar();
@@ -444,11 +415,6 @@
         EjbJarType ejbJarType = XmlUtil.convertToXmlbeans(ejbJar);
         ejbModule.setSpecDD(ejbJarType);
 
-        // add the cmp persistence unit if needed
-        if (appInfo.cmpMappingsXml != null) {
-            addGeronimmoOpenEJBPersistenceUnit(ejbModule);
-        }
-
         // convert the plan to xmlbeans since geronimo naming is coupled on xmlbeans objects
         GeronimoEjbJarType geronimoEjbJarType = (GeronimoEjbJarType) ejbModule.getEjbModule().getAltDDs().get("geronimo-openejb.xml");
         OpenejbGeronimoEjbJarType geronimoOpenejb = XmlUtil.convertToXmlbeans(geronimoEjbJarType);
@@ -485,6 +451,58 @@
         }
     }
 
+    private EjbJarInfo getEjbJarInfo(EARContext earContext, EjbModule ejbModule, ClassLoader
classLoader) throws DeploymentException {
+        EarData earData = (EarData) earContext.getGeneralData().get(EarData.class);
+        if (earData.getEjbJars().isEmpty()) {
+            // create an openejb app module for the ear containing all ejb modules
+            AppModule appModule = new AppModule(ejbModule.getEjbModule().getClassLoader(),
ejbModule.getEjbModule().getModuleId());
+            for (EjbModule module : earData.getEjbModuels()) {
+                appModule.getEjbModules().add(module.getEjbModule());
+            }
+
+            // build the config info tree
+            // this method fills in the ejbJar jaxb tree based on the annotations
+            // (metadata complete) and it run the openejb verifier
+            AppInfo appInfo;
+            try {
+                appInfo = openEjbSystem.configureApplication(appModule);
+            } catch (OpenEJBException e) {
+                e.printStackTrace();
+                throw new DeploymentException(e);
+            }
+
+            // add all of the modules to the ear data
+            for (EjbJarInfo ejbJar : appInfo.ejbJars) {
+                earData.addEjbJar(ejbJar);
+            }
+
+            // add the cmp jar
+            CmpJarBuilder cmp2Builder = new CmpJarBuilder(appInfo, classLoader);
+            try {
+                File generatedJar = cmp2Builder.getJarFile();
+                if (generatedJar != null) {
+                    String generatedPath = ejbModule.getTargetPath();
+                    if (generatedPath.endsWith(".jar")) {
+                        generatedPath = generatedPath.substring(0, generatedPath.length()
- 4);
+                    }
+                    generatedPath += "-cmp2.jar";
+                    earContext.addInclude(URI.create(generatedPath), generatedJar);
+                }
+            } catch (IOException e) {
+                throw new DeploymentException(e);
+            }
+
+            // add the cmp persistence unit if needed
+            if (appInfo.cmpMappingsXml != null) {
+                addGeronimmoOpenEJBPersistenceUnit(ejbModule);
+            }
+        }
+
+        // find our module
+        EjbJarInfo ejbJarInfo = earData.getEjbJar(ejbModule.getEjbModule().getModuleId());
+        return ejbJarInfo;
+    }
+
     private void addGeronimmoOpenEJBPersistenceUnit(EjbModule ejbModule) {
         GeronimoEjbJarType geronimoEjbJarType = (GeronimoEjbJarType) ejbModule.getEjbModule().getAltDDs().get("geronimo-openejb.xml");
 
@@ -496,7 +514,6 @@
                     persistenceUnit = unit;
                     break;
                 }
-
             }
         }
 
@@ -663,10 +680,40 @@
     }
 
     public static class EarData {
-        private final Collection<EjbJarInfo> ejbJars = new ArrayList<EjbJarInfo>();
+        private final Map<String, EjbModule> ejbModules = new TreeMap<String, EjbModule>();
+        private final Map<String, EjbJarInfo> ejbJars = new TreeMap<String, EjbJarInfo>();
+
+        public void addEjbModule(EjbModule ejbModule) {
+            ejbModules.put(ejbModule.getEjbModule().getModuleId(), ejbModule);
+        }
+
+        public EjbModule getEjbModule(String moduleId) throws DeploymentException {
+            EjbModule ejbModule = ejbModules.get(moduleId);
+            if (ejbModule == null) {
+                throw new DeploymentException("Ejb  module " + moduleId + " was not found
in configured module list " + ejbModules.keySet());
+            }
+            return ejbModule;
+        }
+
+        public Collection<EjbModule> getEjbModuels() {
+            return ejbModules.values();
+        }
+
+        public void addEjbJar(EjbJarInfo ejbJarInfo) {
+            ejbJars.put(ejbJarInfo.moduleId, ejbJarInfo);
+        }
+
+        public EjbJarInfo getEjbJar(String moduleId) throws DeploymentException {
+            EjbJarInfo ejbJarInfo = ejbJars.get(moduleId);
+            if (ejbJarInfo == null) {
+                throw new DeploymentException("Ejb jar configuration passed but expected
module " +
+                        moduleId + " was not found in configured module list " + ejbJars.keySet());
+            }
+            return ejbJarInfo;
+        }
 
         public Collection<EjbJarInfo> getEjbJars() {
-            return ejbJars;
+            return ejbJars.values();
         }
     }
 

Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbRefBuilder.java?view=diff&rev=522078&r1=522077&r2=522078
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbRefBuilder.java
Sat Mar 24 11:15:20 2007
@@ -114,8 +114,6 @@
             augmentJndiConsumer(module, consumer, componentContext);
         }
 
-//      processWebEjbAnnotations(module, consumer);
-
         Map<String, Object> map = null;
         try {
             EjbModuleBuilder.EarData earData = (EjbModuleBuilder.EarData) module.getRootEarContext().getGeneralData().get(EjbModuleBuilder.EarData.class);
@@ -404,44 +402,6 @@
                 }
                 //geronimo's handling of injection-target
                 addInjections(refName, xmlbeansRef.getInjectionTargetArray(), componentContext);
-            }
-        }
-    }
-
-    private void processWebEjbAnnotations(Module module, JndiConsumer consumer) throws DeploymentException
{
-        if (module instanceof WebModule) {
-            try {
-                ClassLoader classLoader = module.getEarContext().getClassLoader();
-                UrlSet urlSet = new UrlSet(classLoader);
-                if (classLoader instanceof MultiParentClassLoader) {
-                    MultiParentClassLoader multiParentClassLoader = (MultiParentClassLoader)
classLoader;
-                    for (ClassLoader parent : multiParentClassLoader.getParents()) {
-                        if (parent != null) {
-                            urlSet = urlSet.exclude(parent);
-                        }
-                    }
-                } else {
-                    ClassLoader parent = classLoader.getParent();
-                    if (parent != null) {
-                        urlSet = urlSet.exclude(parent);
-                    }
-                }
-                ClassFinder finder = new ClassFinder(classLoader, urlSet.getUrls());
-                for (Field field : finder.findAnnotatedFields(EJB.class)) {
-                    EJB ejb = field.getAnnotation(EJB.class);
-                    AnnotationDeployer.Member member = new AnnotationDeployer.FieldMember(field);
-                    buildEjbRef(consumer, ejb, member);
-                }
-
-                for (Method method : finder.findAnnotatedMethods(EJB.class)) {
-                    EJB ejb = method.getAnnotation(EJB.class);
-                    AnnotationDeployer.Member member = new AnnotationDeployer.MethodMember(method);
-                    buildEjbRef(consumer, ejb, member);
-                }
-
-            } catch (IOException e) {
-                // ignored... we tried
-                log.warn("Unable to process @EJB annotations web module" + module.getName(),
e);
             }
         }
     }



Mime
View raw message