geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r498899 - in /geronimo/server/trunk/modules/geronimo-openejb-builder/src: main/java/org/apache/geronimo/openejb/deployment/ test/java/org/apache/geronimo/openejb/deployment/
Date Tue, 23 Jan 2007 02:53:23 GMT
Author: dblevins
Date: Mon Jan 22 18:53:17 2007
New Revision: 498899

URL: http://svn.apache.org/viewvc?view=rev&rev=498899
Log:
GERONIMO-2772: Support for EJB 3 descriptors and previous
GERONIMO-2770: Ejb Deployment with no ejb-jar.xml
As well as a fix for an issue that was preventing the @Resource and @EJB annotations from
working.
More null checks for when the OpenejbJar is null

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-openejb-builder/src/test/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilderTest.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=498899&r1=498898&r2=498899
==============================================================================
--- 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
Mon Jan 22 18:53:17 2007
@@ -20,12 +20,19 @@
 import java.io.IOException;
 import java.net.URI;
 import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.MalformedURLException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+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;
@@ -78,6 +85,7 @@
 import org.apache.openejb.jee.ServiceRef;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
+import org.apache.xbean.finder.ClassFinder;
 
 /**
  * Master builder for processing EJB JAR deployments and creating the
@@ -87,7 +95,6 @@
  */
 public class EjbModuleBuilder implements ModuleBuilder {
     private static final String OPENEJBJAR_NAMESPACE = XmlUtil.OPENEJBJAR_QNAME.getNamespaceURI();
-    private static final String MAPPED_NAME_PREFIX = "jndi:java:comp/geronimo/env/";
 
     private final Environment defaultEnvironment;
     private final Collection webServiceBuilders;
@@ -98,12 +105,12 @@
     private final OpenEjbSystem openEjbSystem;
 
     public EjbModuleBuilder(Environment defaultEnvironment,
-            OpenEjbSystem openEjbSystem,
-            Collection webServiceBuilder,
-            Collection securityBuilders,
-            Collection serviceBuilders,
-            NamingBuilder namingBuilders,
-            ResourceEnvironmentSetter resourceEnvironmentSetter) {
+                            OpenEjbSystem openEjbSystem,
+                            Collection webServiceBuilder,
+                            Collection securityBuilders,
+                            Collection serviceBuilders,
+                            NamingBuilder namingBuilders,
+                            ResourceEnvironmentSetter resourceEnvironmentSetter) {
 
         this.openEjbSystem = openEjbSystem;
         this.defaultEnvironment = defaultEnvironment;
@@ -135,7 +142,34 @@
         String ejbJarXml = XmlUtil.loadEjbJarXml(specDDUrl, moduleFile);
         if (ejbJarXml == null) {
             // this is not an ejb module
-            return null;
+            URL moduleUrl = null;
+            try {
+                File file = new File(moduleFile.getName());
+                moduleUrl = file.toURL();
+            } catch (MalformedURLException e) {
+                return null;
+            }
+
+            final ClassFinder classFinder = new ClassFinder(Thread.currentThread().getContextClassLoader(),
moduleUrl);
+            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 beans = new ArrayList();
+            beans.addAll(annotated.get(javax.ejb.Stateless.class));
+            beans.addAll(annotated.get(javax.ejb.Stateful.class));
+            beans.addAll(annotated.get(javax.ejb.MessageDriven.class));
+            if (beans.size() <= 0){
+                return null;
+            }
         }
         EjbJar ejbJar = XmlUtil.unmarshal(EjbJar.class, ejbJarXml);
 
@@ -179,9 +213,6 @@
             namingBuilder.buildEnvironment(assemblyDescriptor, geronimoOpenejb, environment);
         }
 
-        // set mapped name or all refs
-        mapReferences(ejbJar);
-
         //overridden web service locations
         Map correctedPortLocations = new HashMap();
 
@@ -209,43 +240,6 @@
         }
 
         return new EjbModule(standAlone, moduleName, environment, moduleFile, targetPath,
ejbJar, openejbJar, geronimoOpenejb, ejbJarXml, sharedContext);
-    }
-
-    protected static void mapReferences(EjbJar ejbJar) {
-        for (EnterpriseBean enterpriseBean : ejbJar.getEnterpriseBeans()) {
-            for (EjbRef ref : enterpriseBean.getEjbRef()) {
-                String refName = ref.getEjbRefName();
-                ref.setMappedName(MAPPED_NAME_PREFIX + refName);
-            }
-            for (EjbLocalRef ref : enterpriseBean.getEjbLocalRef()) {
-                String refName = ref.getEjbRefName();
-                ref.setMappedName(MAPPED_NAME_PREFIX + refName);
-            }
-            for (MessageDestinationRef ref : enterpriseBean.getMessageDestinationRef()) {
-                String refName = ref.getMessageDestinationRefName();
-                ref.setMappedName(MAPPED_NAME_PREFIX + refName);
-            }
-            for (PersistenceContextRef ref : enterpriseBean.getPersistenceContextRef()) {
-                String refName = ref.getPersistenceContextRefName();
-                ref.setMappedName(MAPPED_NAME_PREFIX + refName);
-            }
-            for (PersistenceUnitRef ref : enterpriseBean.getPersistenceUnitRef()) {
-                String refName = ref.getPersistenceUnitRefName();
-                ref.setMappedName(MAPPED_NAME_PREFIX + refName);
-            }
-            for (ResourceRef ref : enterpriseBean.getResourceRef()) {
-                String refName = ref.getResRefName();
-                ref.setMappedName(MAPPED_NAME_PREFIX + refName);
-            }
-            for (ResourceEnvRef ref : enterpriseBean.getResourceEnvRef()) {
-                String refName = ref.getResourceEnvRefName();
-                ref.setMappedName(MAPPED_NAME_PREFIX + refName);
-            }
-            for (ServiceRef ref : enterpriseBean.getServiceRef()) {
-                String refName = ref.getServiceRefName();
-                ref.setMappedName(MAPPED_NAME_PREFIX + refName);
-            }
-        }
     }
 
     protected static void unmapReferences(EjbJar ejbJar) {

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=498899&r1=498898&r2=498899
==============================================================================
--- 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
Mon Jan 22 18:53:17 2007
@@ -29,6 +29,9 @@
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.namespace.QName;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.SAXParser;
+import javax.xml.transform.sax.SAXSource;
 
 import org.apache.geronimo.openejb.xbeans.ejbjar.OpenejbEjbJarDocument;
 import org.apache.geronimo.openejb.xbeans.ejbjar.OpenejbGeronimoEjbJarType;
@@ -45,6 +48,11 @@
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlDocumentProperties;
 import org.apache.openejb.jee.EjbJar;
+import org.xml.sax.helpers.XMLFilterImpl;
+import org.xml.sax.XMLReader;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
 
 public final class XmlUtil {
     public static final QName OPENEJBJAR_QNAME = OpenejbEjbJarDocument.type.getDocumentElementName();
@@ -69,8 +77,45 @@
         }
     }
 
+    public static class EjbJarNamespaceFilter extends XMLFilterImpl {
+
+        public EjbJarNamespaceFilter(XMLReader xmlReader) {
+            super(xmlReader);
+        }
+
+        public void startElement(String uri, String localName, String qname, Attributes atts)
throws SAXException {
+            super.startElement("http://java.sun.com/xml/ns/javaee", localName, qname, atts);
+        }
+    }
+
     @SuppressWarnings({"unchecked"})
     public static <T> T unmarshal(Class<T> type, String xml) throws DeploymentException
{
+        if (xml == null){
+            return null;
+        }
+
+        if (type.equals(EjbJar.class)){
+            try {
+                SAXParserFactory factory = SAXParserFactory.newInstance();
+                factory.setNamespaceAware(true);
+                factory.setValidating(true);
+
+                SAXParser parser = factory.newSAXParser();
+
+                EjbJarNamespaceFilter xmlFilter = new EjbJarNamespaceFilter(parser.getXMLReader());
+
+                JAXBContext ctx = JAXBContext.newInstance(type);
+                Unmarshaller unmarshaller = ctx.createUnmarshaller();
+
+                xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
+                SAXSource source = new SAXSource(xmlFilter, new InputSource(new ByteArrayInputStream(xml.getBytes())));
+
+                return (T) unmarshaller.unmarshal(source);
+            } catch (Exception e) {
+                throw new DeploymentException(e);
+            }
+        }
+
         try {
             JAXBContext ctx = JAXBContext.newInstance(type);
             Unmarshaller unmarshaller = ctx.createUnmarshaller();

Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/test/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilderTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/test/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilderTest.java?view=diff&rev=498899&r1=498898&r2=498899
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/test/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilderTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/test/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilderTest.java
Mon Jan 22 18:53:17 2007
@@ -37,6 +37,8 @@
  */
 public class EjbModuleBuilderTest extends TestCase {
     public void test() throws Exception {
+        System.setProperty("duct tape","");
+
         // create reference to openejb itests
         File file = new File(System.getProperty("user.home") + "/.m2/repository/org/apache/openejb/openejb-itests-beans/3.0-incubating-SNAPSHOT/openejb-itests-beans-3.0-incubating-SNAPSHOT.jar");
         if (!file.canRead()) return;
@@ -63,7 +65,6 @@
         // create the module object
         ClassLoader classLoader = new URLClassLoader(new URL[] {file.toURL()}, getClass().getClassLoader());
         EjbModule ejbModule = new EjbModule(classLoader, moduleFile.getName(), ejbJar, openejbJar);
-        EjbModuleBuilder.mapReferences(ejbModule.getEjbJar());
         // configure the application
         EjbJarInfo ejbJarInfo = openEjbSystem.configureApplication(ejbModule);
         openEjbSystem.createEjbJar(ejbJarInfo, classLoader);



Mime
View raw message