tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r502472 - in /incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config: ConfigurationFactory.java DeploymentLoader.java ReadDescriptors.java
Date Fri, 02 Feb 2007 04:05:41 GMT
Author: dblevins
Date: Thu Feb  1 20:05:39 2007
New Revision: 502472

URL: http://svn.apache.org/viewvc?view=rev&rev=502472
Log:
Refactored out the parsing of descriptors into a DynamicDeployer.
It has bug in that it will always overwrite the EjbJar and OpenejbJar originally in EjbModule.
 Need to fix that.

Added:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?view=diff&rev=502472&r1=502471&r2=502472
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
(original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
Thu Feb  1 20:05:39 2007
@@ -118,6 +118,8 @@
 
         Chain chain = new Chain();
 
+        chain.add(new ReadDescriptors());
+        
         chain.add(new AnnotationDeployer());
 
         if (System.getProperty("duct tape") != null){

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?view=diff&rev=502472&r1=502471&r2=502472
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
(original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
Thu Feb  1 20:05:39 2007
@@ -19,14 +19,9 @@
 
 import org.apache.openejb.OpenEJB;
 import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.jee.oejb3.OpenejbJar;
 import org.apache.openejb.core.TemporaryClassLoader;
 import org.apache.openejb.jee.Application;
-import org.apache.openejb.jee.ApplicationClient;
-import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.jee.Module;
-import org.apache.openejb.jee.jpa.unit.Persistence;
-import org.apache.openejb.jee.jpa.unit.JaxbPersistenceFactory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.Messages;
 import org.apache.xbean.finder.ClassFinder;
@@ -63,63 +58,6 @@
 
 
     public AppModule load(File jarFile) throws OpenEJBException {
-        AppModule appModule = load1(jarFile);
-
-        for (EjbModule ejbModule : appModule.getEjbModules()) {
-
-            Object data = ejbModule.getAltDDs().get("ejb-jar.xml");
-            if (data instanceof URL) {
-                URL url = (URL) data;
-                EjbJar ejbJar = unmarshal(EjbJar.class, "META-INF/ejb-jar.xml", url);
-                ejbModule.setEjbJar(ejbJar);
-            } else {
-                logger.warning("No ejb-jar.xml found assuming annotated beans present: "
+ appModule.getJarLocation() + ", module: " + ejbModule.getModuleId());
-                ejbModule.setEjbJar(new EjbJar());
-            }
-
-            data = ejbModule.getAltDDs().get("openejb-jar.xml");
-            if (data instanceof URL) {
-                URL url = (URL) data;
-                OpenejbJar openejbJar = unmarshal(OpenejbJar.class, "META-INF/openejb-jar.xml",
url);
-                ejbModule.setOpenejbJar(openejbJar);
-            }
-
-        }
-
-        for (ClientModule clientModule : appModule.getClientModules()) {
-
-            Object data = clientModule.getAltDDs().get("ejb-jar.xml");
-            if (data instanceof URL) {
-                URL url = (URL) data;
-                ApplicationClient applicationClient = unmarshal(ApplicationClient.class,
"META-INF/application-client.xml", url);
-                clientModule.setApplicationClient(applicationClient);
-            } else {
-                logger.warning("No application-client.xml found assuming annotations present:
" + appModule.getJarLocation() + ", module: " + clientModule.getModuleId());
-                clientModule.setApplicationClient(new ApplicationClient());
-            }
-
-        }
-
-        List<URL> persistenceUrls = (List<URL>) appModule.getAltDDs().get("persistence.xml");
-        for (URL url1 : persistenceUrls) {
-            String moduleName1 = url1.toExternalForm().replaceFirst("!?/?META-INF/persistence.xml$",
"");
-            if (moduleName1.startsWith("jar:")) moduleName1 = moduleName1.substring("jar:".length());
-            if (moduleName1.startsWith("file:")) moduleName1 = moduleName1.substring("file:".length());
-            if (moduleName1.endsWith("/")) moduleName1 = moduleName1.substring(0, moduleName1.length()
-1);
-            try {
-                Persistence persistence = JaxbPersistenceFactory.getPersistence(url1);
-                PersistenceModule persistenceModule = new PersistenceModule(moduleName1,
persistence);
-                appModule.getPersistenceModules().add(persistenceModule);
-
-            } catch (Exception e1) {
-                logger.error("Unable to load Persistence Unit from EAR: " + appModule.getJarLocation()
+ ", module: " + moduleName1 + ". Exception: " + e1.getMessage(), e1);
-            }
-        }
-
-        return appModule;
-    }
-
-    private AppModule load1(File jarFile) throws OpenEJBException {
         ClassLoader classLoader = getClassLoader(jarFile);
 
         URL baseUrl = getFileUrl(jarFile);
@@ -321,6 +259,16 @@
         }
     }
 
+    @SuppressWarnings({"unchecked"})
+    public static <T>T unmarshal(Class<T> type, String descriptor, URL descriptorUrl)
throws OpenEJBException {
+        JaxbUnmarshaller unmarshaller = unmarshallers.get(type);
+        if (unmarshaller == null) {
+            unmarshaller = new JaxbUnmarshaller(type, descriptor);
+            unmarshallers.put(type, unmarshaller);
+        }
+        return (T) unmarshaller.unmarshal(descriptorUrl);
+    }
+
     public static void scanDir(File dir, Map<String, URL> files, String path) {
         for (File file : dir.listFiles()) {
             if (file.isDirectory()) {
@@ -378,16 +326,6 @@
         }
 
         throw new UnsupportedOperationException("Unknown module type");
-    }
-
-    @SuppressWarnings({"unchecked"})
-    private <T>T unmarshal(Class<T> type, String descriptor, URL descriptorUrl)
throws OpenEJBException {
-        JaxbUnmarshaller unmarshaller = unmarshallers.get(type);
-        if (unmarshaller == null) {
-            unmarshaller = new JaxbUnmarshaller(type, descriptor);
-            unmarshallers.put(type, unmarshaller);
-        }
-        return (T) unmarshaller.unmarshal(descriptorUrl);
     }
 
     private File unpack(File jarFile) throws OpenEJBException {

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?view=auto&rev=502472
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
(added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
Thu Feb  1 20:05:39 2007
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.config;
+
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.ApplicationClient;
+import org.apache.openejb.jee.jpa.unit.Persistence;
+import org.apache.openejb.jee.jpa.unit.JaxbPersistenceFactory;
+import org.apache.openejb.jee.oejb3.OpenejbJar;
+
+import java.net.URL;
+import java.util.List;
+
+/**
+ * @version $Rev$ $Date$
+ */
+class ReadDescriptors implements DynamicDeployer {
+    public AppModule deploy(AppModule appModule) throws OpenEJBException {
+        for (EjbModule ejbModule : appModule.getEjbModules()) {
+
+            Object data = ejbModule.getAltDDs().get("ejb-jar.xml");
+            if (data instanceof URL) {
+                URL url = (URL) data;
+                EjbJar ejbJar = DeploymentLoader.unmarshal(EjbJar.class, "META-INF/ejb-jar.xml",
url);
+                ejbModule.setEjbJar(ejbJar);
+            } else {
+                DeploymentLoader.logger.warning("No ejb-jar.xml found assuming annotated
beans present: " + appModule.getJarLocation() + ", module: " + ejbModule.getModuleId());
+                ejbModule.setEjbJar(new EjbJar());
+            }
+
+            data = ejbModule.getAltDDs().get("openejb-jar.xml");
+            if (data instanceof URL) {
+                URL url = (URL) data;
+                OpenejbJar openejbJar = DeploymentLoader.unmarshal(OpenejbJar.class, "META-INF/openejb-jar.xml",
url);
+                ejbModule.setOpenejbJar(openejbJar);
+            }
+
+        }
+
+        for (ClientModule clientModule : appModule.getClientModules()) {
+
+            Object data = clientModule.getAltDDs().get("ejb-jar.xml");
+            if (data instanceof URL) {
+                URL url = (URL) data;
+                ApplicationClient applicationClient = DeploymentLoader.unmarshal(ApplicationClient.class,
"META-INF/application-client.xml", url);
+                clientModule.setApplicationClient(applicationClient);
+            } else {
+                DeploymentLoader.logger.warning("No application-client.xml found assuming
annotations present: " + appModule.getJarLocation() + ", module: " + clientModule.getModuleId());
+                clientModule.setApplicationClient(new ApplicationClient());
+            }
+
+        }
+
+        List<URL> persistenceUrls = (List<URL>) appModule.getAltDDs().get("persistence.xml");
+        for (URL url1 : persistenceUrls) {
+            String moduleName1 = url1.toExternalForm().replaceFirst("!?/?META-INF/persistence.xml$",
"");
+            if (moduleName1.startsWith("jar:")) moduleName1 = moduleName1.substring("jar:".length());
+            if (moduleName1.startsWith("file:")) moduleName1 = moduleName1.substring("file:".length());
+            if (moduleName1.endsWith("/")) moduleName1 = moduleName1.substring(0, moduleName1.length()
-1);
+            try {
+                Persistence persistence = JaxbPersistenceFactory.getPersistence(url1);
+                PersistenceModule persistenceModule = new PersistenceModule(moduleName1,
persistence);
+                appModule.getPersistenceModules().add(persistenceModule);
+
+            } catch (Exception e1) {
+                DeploymentLoader.logger.error("Unable to load Persistence Unit from EAR:
" + appModule.getJarLocation() + ", module: " + moduleName1 + ". Exception: " + e1.getMessage(),
e1);
+            }
+        }
+
+        return appModule;
+
+    }
+}



Mime
View raw message