geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r518044 - in /geronimo/server/trunk/modules: geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ geronimo-transaction/src/main/java/org/apache/geronimo/t...
Date Wed, 14 Mar 2007 07:23:32 GMT
Author: dain
Date: Wed Mar 14 00:23:31 2007
New Revision: 518044

URL: http://svn.apache.org/viewvc?view=rev&rev=518044
Log:
Added container matching logic for MDBs

Modified:
    geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
    geronimo/server/trunk/modules/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
    geronimo/server/trunk/modules/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.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=518044&r1=518043&r2=518044
==============================================================================
--- 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
Wed Mar 14 00:23:31 2007
@@ -27,6 +27,8 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
 import java.util.jar.JarFile;
 
 import javax.ejb.EntityContext;
@@ -55,13 +57,14 @@
 import org.apache.geronimo.j2ee.deployment.ModuleBuilder;
 import org.apache.geronimo.j2ee.deployment.ModuleBuilderExtension;
 import org.apache.geronimo.j2ee.deployment.NamingBuilder;
-import org.apache.geronimo.j2ee.deployment.WebServiceBuilder;
 import org.apache.geronimo.j2ee.deployment.annotation.AnnotatedEjbJar;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.Naming;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.config.ConfigurationModuleType;
 import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.naming.deployment.ResourceEnvironmentSetter;
 import org.apache.geronimo.openejb.EjbDeployment;
 import org.apache.geronimo.openejb.EjbModuleImplGBean;
@@ -74,6 +77,8 @@
 import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.assembler.classic.CmpJarBuilder;
 import org.apache.openejb.assembler.classic.EjbJarInfo;
+import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
+import org.apache.openejb.assembler.classic.MessageDrivenBeanInfo;
 import org.apache.openejb.config.AppModule;
 import org.apache.openejb.config.DeploymentLoader;
 import org.apache.openejb.config.ReadDescriptors;
@@ -91,6 +96,10 @@
 import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
 import org.apache.openejb.jee.jpa.unit.TransactionType;
 import org.apache.openejb.jee.oejb2.GeronimoEjbJarType;
+import org.apache.openejb.jee.oejb2.ResourceLocatorType;
+import org.apache.openejb.jee.oejb2.PatternType;
+import org.apache.openejb.jee.oejb2.OpenejbJarType;
+import org.apache.openejb.jee.oejb2.MessageDrivenBeanType;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
 
@@ -129,7 +138,7 @@
         this.resourceEnvironmentSetter = resourceEnvironmentSetter;
 
         if (moduleBuilderExtensions == null) {
-            moduleBuilderExtensions = Collections.EMPTY_LIST;
+            moduleBuilderExtensions = Collections.emptyList();
         }
         this.moduleBuilderExtensions = moduleBuilderExtensions;
     }
@@ -440,7 +449,7 @@
         // add the cmp persistence unit if needed
         GeronimoEjbJarType geronimoEjbJarType = (GeronimoEjbJarType) ejbModule.getEjbModule().getAltDDs().get("geronimo-openejb.xml");
         if (appInfo.cmpMappingsXml != null) {
-            addGeronimmoOpenEJBPersistenceUnit(ejbModule, geronimoEjbJarType);
+            addGeronimmoOpenEJBPersistenceUnit(geronimoEjbJarType);
         }
 
         // convert the plan to xmlbeans since geronimo naming is coupled on xmlbeans objects
@@ -478,7 +487,7 @@
         }
     }
 
-    private void addGeronimmoOpenEJBPersistenceUnit(EjbModule ejbModule, GeronimoEjbJarType
geronimoEjbJarType) {
+    private void addGeronimmoOpenEJBPersistenceUnit(GeronimoEjbJarType geronimoEjbJarType)
{
         // search for the cmp persistence unit
         PersistenceUnit persistenceUnit = null;
         for (Persistence persistence : geronimoEjbJarType.getPersistence()) {
@@ -561,6 +570,8 @@
         ComponentPermissions componentPermissions = ejbDeploymentBuilder.buildComponentPermissions();
         earContext.addSecurityContext(ejbModule.getEjbJarInfo().moduleId, componentPermissions);
 
+        setMdbContainerIds(earContext, ejbModule);
+
         for (ModuleBuilderExtension builder : moduleBuilderExtensions) {
             try {
                 builder.addGBeans(earContext, module, cl, repositories);
@@ -569,6 +580,81 @@
                 log.error(builderName + ".addGBeans() failed: " + t.getMessage(), t);
             }
         }
+    }
+
+    private void setMdbContainerIds(EARContext earContext, EjbModule ejbModule) throws DeploymentException
{
+        Object altDD = ejbModule.getEjbModule().getAltDDs().get("openejb-jar.xml");
+        if (!(altDD instanceof OpenejbJarType)) {
+            return;
+        }
+        OpenejbJarType openejbJarType = (OpenejbJarType) altDD;
+        EjbJarInfo ejbJarInfo = ejbModule.getEjbJarInfo();
+
+        Map<String, MessageDrivenBeanInfo> mdbs =  new TreeMap<String, MessageDrivenBeanInfo>();
+        for (EnterpriseBeanInfo enterpriseBean : ejbJarInfo.enterpriseBeans) {
+            if (enterpriseBean instanceof MessageDrivenBeanInfo) {
+                mdbs.put(enterpriseBean.ejbName, (MessageDrivenBeanInfo) enterpriseBean);
+            }
+        }
+        for (org.apache.openejb.jee.oejb2.EnterpriseBean enterpriseBean : openejbJarType.getEnterpriseBeans())
{
+            if (!(enterpriseBean instanceof MessageDrivenBeanType)) {
+                continue;
+            }
+            MessageDrivenBeanType bean = (MessageDrivenBeanType) enterpriseBean;
+            MessageDrivenBeanInfo messageDrivenBeanInfo = mdbs.get(bean.getEjbName());
+            if (messageDrivenBeanInfo == null) {
+                continue;
+            }
+            if (messageDrivenBeanInfo.containerId != null) {
+                // containerId already set
+                continue;
+            }
+
+            if (bean.getResourceAdapter() == null) {
+                throw new DeploymentException("Resource Adapter defined for MDB '" + bean.getEjbName()
+ "'");
+            }
+
+            AbstractNameQuery resourceAdapterNameQuery = getResourceAdapterNameQuery(bean.getResourceAdapter());
+            AbstractName resourceAdapterAbstractName = null;
+            try {
+                resourceAdapterAbstractName = earContext.findGBean(resourceAdapterNameQuery);
+            } catch (GBeanNotFoundException e) {
+                throw new DeploymentException("Resource Adapter for MDB '" + bean.getEjbName()
+ "'not found: " + resourceAdapterNameQuery);
+            }
+
+            Map properties = resourceAdapterAbstractName.getName();
+            String shortName = (String) properties.get("name");
+            String moduleName = (String) properties.get("ResourceAdapterModule");
+            if (shortName != null && moduleName != null) {
+                messageDrivenBeanInfo.containerId = moduleName + "." + shortName + "-" +
messageDrivenBeanInfo.mdbInterface;
+            } else {
+                messageDrivenBeanInfo.containerId = resourceAdapterAbstractName.getObjectName().toString()
+ "-" + messageDrivenBeanInfo.mdbInterface;
+            }
+        }
+    }
+
+    private static AbstractNameQuery getResourceAdapterNameQuery(ResourceLocatorType resourceLocator)
{
+        if (resourceLocator.getResourceLink() != null) {
+            Map<String, String> nameMap = new HashMap<String, String>();
+            nameMap.put("name", resourceLocator.getResourceLink());
+            nameMap.put("j2eeType", NameFactory.JCA_RESOURCE_ADAPTER);
+            return new AbstractNameQuery(null, nameMap);
+        }
+
+        //construct name from components
+        PatternType pattern = resourceLocator.getPattern();
+        Artifact artifact = null;
+        if (pattern.getArtifactId() != null) {
+            artifact = new Artifact(pattern.getGroupId(), pattern.getArtifactId(), pattern.getVersion(),
"car");
+        }
+
+        Map<String, String> nameMap = new HashMap<String, String>();
+        nameMap.put("name", pattern.getName());
+        nameMap.put("j2eeType", NameFactory.JCA_RESOURCE_ADAPTER);
+        if (pattern.getModule() != null) {
+            nameMap.put(NameFactory.RESOURCE_ADAPTER_MODULE, pattern.getModule());
+        }
+        return new AbstractNameQuery(artifact, nameMap, (Set)null);
     }
 
     public static class EarData {

Modified: geronimo/server/trunk/modules/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java?view=diff&rev=518044&r1=518043&r2=518044
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
(original)
+++ geronimo/server/trunk/modules/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
Wed Mar 14 00:23:31 2007
@@ -56,7 +56,6 @@
 import javax.resource.spi.ResourceAdapter;
 import javax.transaction.TransactionManager;
 import javax.management.ObjectName;
-import javax.management.MalformedObjectNameException;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.Map;
@@ -198,13 +197,15 @@
                         containerInfo.displayName = containerName;
 
                         // set ra specific properties
-                        containerInfo.properties.setProperty("MessageListenerInterface",
messageListenerInterface);
-                        containerInfo.properties.setProperty("ActivationSpecClass", activationSpecClass);
+                        containerInfo.properties.put("MessageListenerInterface",
+                                resourceAdapter.getClass().getClassLoader().loadClass(messageListenerInterface));
+                        containerInfo.properties.put("ActivationSpecClass",
+                                resourceAdapter.getClass().getClassLoader().loadClass(activationSpecClass));
                         containerInfo.properties.put("ResourceAdapter", resourceAdapter);
 
                         // create the container
                         assembler.createContainer(containerInfo);
-                    } catch (OpenEJBException e) {
+                    } catch (Exception e) {
                         log.error("Unable to deploy mdb container " + containerName, e);
                     }
                 }
@@ -213,7 +214,6 @@
             Thread.currentThread().setContextClassLoader(oldClassLoader);
         }
     }
-
 
     private void removeResourceAdapter(ResourceAdapterWrapper resourceAdapterWrapper) {
         for (String messageListenerInterface : resourceAdapterWrapper.getMessageListenerToActivationSpecMap().keySet())
{

Modified: geronimo/server/trunk/modules/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java?view=diff&rev=518044&r1=518043&r2=518044
==============================================================================
--- geronimo/server/trunk/modules/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
(original)
+++ geronimo/server/trunk/modules/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
Wed Mar 14 00:23:31 2007
@@ -706,7 +706,10 @@
             if (committer instanceof NamedXAResource) {
                 return ((NamedXAResource) committer).getName();
             } else {
-                throw new IllegalStateException("Cannot log transactions unles XAResources
are named! " + committer);
+                // if it isn't a named resource should we really stop all processing here!
+                // Maybe this would be better to handle else where and do we really want
to prevent all processing of transactions?
+                new IllegalStateException("Cannot log transactions unles XAResources are
named! " + committer).printStackTrace();
+                return committer.toString();
             }
         }
 



Mime
View raw message