geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r504104 - in /geronimo/server/trunk/modules: geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/
Date Tue, 06 Feb 2007 12:26:00 GMT
Author: dblevins
Date: Tue Feb  6 04:25:59 2007
New Revision: 504104

URL: http://svn.apache.org/viewvc?view=rev&rev=504104
Log:
Overhaul of integration leveraging the new descriptor parsing and conversion code in openejb

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/XmlUtil.java
    geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.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=504104&r1=504103&r2=504104
==============================================================================
--- 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 Feb  6 04:25:59 2007
@@ -20,8 +20,6 @@
 import java.io.IOException;
 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;
@@ -30,17 +28,16 @@
 import java.util.List;
 import java.util.ArrayList;
 import java.util.jar.JarFile;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.lang.reflect.Field;
 
 import javax.ejb.SessionContext;
 import javax.ejb.EntityContext;
+import javax.xml.namespace.QName;
 
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.ModuleIDBuilder;
 import org.apache.geronimo.deployment.NamespaceDrivenBuilder;
 import org.apache.geronimo.deployment.NamespaceDrivenBuilderCollection;
+import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
 import org.apache.geronimo.deployment.service.EnvironmentBuilder;
 import org.apache.geronimo.deployment.service.GBeanBuilder;
 import org.apache.geronimo.deployment.xbeans.EnvironmentType;
@@ -69,9 +66,11 @@
 import org.apache.geronimo.xbeans.javaee.AssemblyDescriptorType;
 import org.apache.geronimo.xbeans.javaee.EjbJarType;
 import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.apache.openejb.config.DeploymentLoader;
+import org.apache.openejb.config.ReadDescriptors;
+import org.apache.openejb.config.AppModule;
 import org.apache.openejb.assembler.classic.EjbJarInfo;
-import org.apache.openejb.assembler.classic.Cmp2Builder;
+import org.apache.openejb.assembler.classic.CmpJarBuilder;
 import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.jee.EnterpriseBean;
@@ -81,9 +80,11 @@
 import org.apache.openejb.jee.ResourceEnvRef;
 import org.apache.openejb.jee.ResourceRef;
 import org.apache.openejb.jee.ServiceRef;
-import org.apache.xmlbeans.XmlCursor;
+import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.apache.openejb.jee.oejb2.GeronimoEjbJarType;
 import org.apache.xmlbeans.XmlObject;
-import org.apache.xbean.finder.ClassFinder;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlCursor;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -145,38 +146,68 @@
             throw new IllegalArgumentException("targetPath must not end with a '/'");
         }
 
-        // load the ejb-jar.xml
-        String ejbJarXml = XmlUtil.loadEjbJarXml(specDDUrl, moduleFile);
-        // 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();
+        DeploymentLoader loader = new DeploymentLoader();
+        File file = new File(moduleFile.getName());
+
+        AppModule appModule = null;
+        try {
+            appModule = loader.load(file);
+        } catch (OpenEJBException e) {
+            throw new DeploymentException(e);
         }
+        org.apache.openejb.config.EjbModule ejbModule = appModule.getEjbModules().get(0);
 
-        // load the geronimo-openejb.xml
-        boolean standAlone = earEnvironment == null;
-        OpenejbGeronimoEjbJarType geronimoOpenejb = XmlUtil.loadGeronimOpenejbJar(plan, moduleFile,
standAlone, targetPath, ejbJar);
-        if (geronimoOpenejb == null) {
-            // Avoid NPE GERONIMO-1220; todo: remove this if we can work around the requirement
for a plan
-            throw new DeploymentException("Currently a Geronimo deployment plan is required
for an EJB module.  Please provide a plan as a deployer argument or packaged in the EJB JAR
at META-INF/openejb-jar.xml");
+
+        XmlObject unknownXmlObject = null;
+
+        if (plan instanceof XmlObject) {
+            unknownXmlObject = (XmlObject) plan;
+        } else if (plan != null) {
+            try {
+                unknownXmlObject = XmlBeansUtil.parse(((File) plan).toURL(), XmlUtil.class.getClassLoader());
+            } catch (Exception e) {
+                throw new DeploymentException(e);
+            }
         }
 
-        // load the openejb-jar.xml
-        XmlObject object = null;
-        if (geronimoOpenejb.isSetOpenejbJar()) {
-            XmlCursor xmlCursor = geronimoOpenejb.getOpenejbJar().newCursor();
+        if (unknownXmlObject != null) {
+            XmlCursor xmlCursor = unknownXmlObject.newCursor();
             xmlCursor.toFirstChild();
-            object = xmlCursor.getObject();
+            QName qname = xmlCursor.getName();
+            if (qname.getLocalPart().equals("openejb-jar")){
+                ejbModule.getAltDDs().put("openejb-jar.xml", unknownXmlObject.xmlText());
+            } else if (qname.getLocalPart().equals("ejb-jar") && qname.getNamespaceURI().equals("http://geronimo.apache.org/xml/ns/j2ee/ejb/openejb-2.0")){
+                ejbModule.getAltDDs().put("geronimo-openejb.xml", unknownXmlObject.xmlText());
+            }
+        }
+
+        if (specDDUrl != null) {
+            ejbModule.getAltDDs().put("ejb-jar.xml", specDDUrl);
+        }
+
+        ReadDescriptors readDescriptors = new ReadDescriptors();
+
+        try {
+            readDescriptors.deploy(appModule);
+        } catch (OpenEJBException e) {
+            throw new DeploymentException("Failed parsing descriptors for module: "+moduleFile.getName(),
e);
         }
-        String openejbJarXml = XmlUtil.loadOpenejbJarXml(object, moduleFile);
-        OpenejbJar openejbJar = XmlUtil.unmarshal(OpenejbJar.class, openejbJarXml);
-        if (openejbJar == null){
-            openejbJar = new OpenejbJar();
+
+        EjbJar ejbJar = ejbModule.getEjbJar();
+        OpenejbJar openejbJar = ejbModule.getOpenejbJar();
+
+        OpenejbGeronimoEjbJarType geronimoOpenejb;
+
+
+        boolean standAlone = earEnvironment == null;
+
+        GeronimoEjbJarType jaxbGeronimoOpenejb = (GeronimoEjbJarType) ejbModule.getAltDDs().get("geronimo-openejb.xml");
+        if (jaxbGeronimoOpenejb != null) {
+            geronimoOpenejb = XmlUtil.convertToXmlbeans(jaxbGeronimoOpenejb);
+        } else {
+            String path = (standAlone)? new File(moduleFile.getName()).getName(): targetPath;
+            geronimoOpenejb = XmlUtil.createDefaultPlan(path, ejbJar);
         }
 
         // initialize the geronimo environment
@@ -227,49 +258,7 @@
             moduleName = naming.createChildName(earName, targetPath, NameFactory.EJB_MODULE);
         }
 
-        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();
+        return new EjbModule(standAlone, moduleName, environment, moduleFile, targetPath,
ejbJar, openejbJar, geronimoOpenejb, "", sharedContext);
     }
 
     protected static void unmapReferences(EjbJar ejbJar) {
@@ -356,7 +345,7 @@
         // Generate the cmp2 concrete subclasses
         AppInfo appInfo = new AppInfo();
         appInfo.ejbJars.add(ejbJarInfo);
-        Cmp2Builder cmp2Builder = new Cmp2Builder(appInfo, classLoader);
+        CmpJarBuilder cmp2Builder = new CmpJarBuilder(appInfo, classLoader);
         try {
             File generatedJar = cmp2Builder.getJarFile();
             if (generatedJar != null) {

Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/XmlUtil.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/XmlUtil.java?view=diff&rev=504104&r1=504103&r2=504104
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/XmlUtil.java
(original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/XmlUtil.java
Tue Feb  6 04:25:59 2007
@@ -19,7 +19,6 @@
 
 import java.net.URL;
 import java.util.jar.JarFile;
-import java.util.Iterator;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
@@ -29,12 +28,11 @@
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
+import javax.xml.bind.JAXBElement;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.parsers.SAXParser;
 import javax.xml.transform.sax.SAXSource;
-import javax.ejb.SessionContext;
-import javax.ejb.EntityContext;
 
 import org.apache.geronimo.openejb.xbeans.ejbjar.OpenejbEjbJarDocument;
 import org.apache.geronimo.openejb.xbeans.ejbjar.OpenejbGeronimoEjbJarType;
@@ -52,13 +50,9 @@
 import org.apache.xmlbeans.XmlDocumentProperties;
 import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.jee.EnterpriseBean;
-import org.apache.openejb.jee.MessageDestinationRef;
 import org.apache.openejb.jee.PersistenceContextRef;
-import org.apache.openejb.jee.PersistenceUnitRef;
-import org.apache.openejb.jee.ResourceRef;
-import org.apache.openejb.jee.ResourceEnvRef;
-import org.apache.openejb.jee.ServiceRef;
 import org.apache.openejb.jee.PersistenceContextType;
+import org.apache.openejb.jee.oejb2.GeronimoEjbJarType;
 import org.xml.sax.helpers.XMLFilterImpl;
 import org.xml.sax.XMLReader;
 import org.xml.sax.Attributes;
@@ -141,9 +135,15 @@
 
     public static <T> String marshal(T object) throws DeploymentException {
         try {
-            JAXBContext ctx = JAXBContext.newInstance(object.getClass());
+            Class type = object.getClass();
+
+            if (object instanceof JAXBElement) {
+                JAXBElement element = (JAXBElement) object;
+                type = element.getValue().getClass();
+            }
+
+            JAXBContext ctx = JAXBContext.newInstance(type);
             Marshaller marshaller = ctx.createMarshaller();
-            marshaller.setProperty("jaxb.formatted.output", true);
 
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             marshaller.marshal(object, baos);
@@ -208,6 +208,28 @@
         }
 
     }
+
+    public static OpenejbGeronimoEjbJarType convertToXmlbeans(GeronimoEjbJarType geronimoEjbJarType)
throws DeploymentException {
+        //
+        // it would be nice if Jaxb had a way to convert the object to a
+        // sax reader that could be fed directly into xmlbeans
+        //
+        JAXBElement root = new JAXBElement(new QName("http://geronimo.apache.org/xml/ns/j2ee/ejb/openejb-2.0","ejb-jar"),
GeronimoEjbJarType.class, geronimoEjbJarType);
+
+        // marshal to xml
+
+        String xml = marshal(root);
+
+        try {
+            XmlObject xmlObject = XmlBeansUtil.parse(xml);
+
+            OpenejbGeronimoEjbJarType geronimoOpenejb = (OpenejbGeronimoEjbJarType) SchemaConversionUtils.fixGeronimoSchema(xmlObject,
OPENEJBJAR_QNAME, OpenejbGeronimoEjbJarType.type);
+            return geronimoOpenejb;
+        } catch (XmlException e) {
+            throw new DeploymentException("Error parsing geronimo-openejb.xml", e);
+        }
+    }
+
     public static OpenejbGeronimoEjbJarType loadGeronimOpenejbJar(Object plan, JarFile moduleFile,
boolean standAlone, String targetPath, EjbJar ejbJar) throws DeploymentException {
         OpenejbGeronimoEjbJarType openejbJar;
         XmlObject rawPlan = null;

Modified: geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java?view=diff&rev=504104&r1=504103&r2=504104
==============================================================================
--- geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
Tue Feb  6 04:25:59 2007
@@ -112,7 +112,8 @@
 
         for (GerPersistenceContextRefType gerPersistenceContextRef : gerPersistenceContextRefsUntyped.values())
{
             String persistenceContextRefName = gerPersistenceContextRef.getPersistenceContextRefName();
-            boolean transactionScoped = !gerPersistenceContextRef.getPersistenceContextType().equals(GerPersistenceContextTypeType.EXTENDED);
+            GerPersistenceContextTypeType.Enum persistenceContextType = gerPersistenceContextRef.getPersistenceContextType();
+            boolean transactionScoped = persistenceContextType == null || !persistenceContextType.equals(GerPersistenceContextTypeType.EXTENDED);
             Map properties = new HashMap();
             addProperties(gerPersistenceContextRef, properties);
 



Mime
View raw message