openejb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1333205 - in /openejb/trunk/openejb: arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/ container/openejb-core/src/main/java/org/apache/openejb/config/
Date Wed, 02 May 2012 20:58:45 GMT
Author: rmannibucau
Date: Wed May  2 20:58:44 2012
New Revision: 1333205

URL: http://svn.apache.org/viewvc?rev=1333205&view=rev
Log:
TOMEE-183 some refactoring to avoid duplication of persistence.xml read code

Modified:
    openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java?rev=1333205&r1=1333204&r2=1333205&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
(original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-openejb-container/src/main/java/org/apache/openejb/arquillian/openejb/OpenEJBArchiveProcessor.java
Wed May  2 20:58:44 2012
@@ -3,6 +3,7 @@ package org.apache.openejb.arquillian.op
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -12,17 +13,13 @@ import org.apache.openejb.OpenEJBExcepti
 import org.apache.openejb.OpenEJBRuntimeException;
 import org.apache.openejb.config.AppModule;
 import org.apache.openejb.config.EjbModule;
-import org.apache.openejb.config.PersistenceModule;
 import org.apache.openejb.config.ReadDescriptors;
 import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.jee.ManagedBean;
 import org.apache.openejb.jee.TransactionType;
-import org.apache.openejb.jee.jpa.unit.JaxbPersistenceFactory;
-import org.apache.openejb.jee.jpa.unit.Persistence;
 import org.apache.openejb.jee.oejb3.EjbDeployment;
 import org.apache.openejb.jee.oejb3.OpenejbJar;
 import org.apache.openejb.loader.IO;
-import org.apache.openejb.util.LengthInputStream;
 import org.apache.xbean.finder.AnnotationFinder;
 import org.apache.xbean.finder.archive.ClassesArchive;
 import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
@@ -96,23 +93,7 @@ public class OpenEJBArchiveProcessor imp
         {
             final Node persistenceXml = archive.get(META_INF.concat(PERSISTENCE_XML));
             if (persistenceXml != null) {
-                String rootUrl = persistenceXml.getPath().getParent().getParent().get();
-                if ("/".equals(rootUrl)) {
-                    rootUrl = ""; // "/" is too bad for a rootUrl and it can't be null
-                }
-
-                LengthInputStream lis = null;
-                try {
-                    lis = new LengthInputStream(persistenceXml.getAsset().openStream());
-                    final Persistence persistence = JaxbPersistenceFactory.getPersistence(Persistence.class,
lis);
-                    final PersistenceModule persistenceModule = new PersistenceModule(rootUrl,
persistence);
-                    persistenceModule.getWatchedResources().add(rootUrl);
-                    appModule.getPersistenceModules().add(persistenceModule);
-                } catch (Exception e) {
-                    LOGGER.log(Level.SEVERE, "can't read persistence.xml", e);
-                } finally {
-                    IO.close(lis);
-                }
+                appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset())));
             }
         }
 

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=1333205&r1=1333204&r2=1333205&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
Wed May  2 20:58:44 2012
@@ -111,32 +111,46 @@ public class ReadDescriptors implements 
             readResourcesXml(webModule);
         }
 
-        List<URL> persistenceUrls = (List<URL>) appModule.getAltDDs().get("persistence.xml");
+        List<Object> persistenceUrls = (List<Object>) appModule.getAltDDs().get("persistence.xml");
         if (persistenceUrls != null) {
-            for (URL persistenceUrl : persistenceUrls) {
-                File file = URLs.toFile(persistenceUrl);
-                String path = file.getAbsolutePath();
+            for (Object persistenceUrl : persistenceUrls) {
+                final boolean url = persistenceUrl instanceof URL;
+                final Source source = getSource(persistenceUrl);
+
+                final String moduleName;
+                final String path;
+                final String rootUrl;
+                if (url) {
+                    final URL pUrl = (URL) persistenceUrl;
+                    File file = URLs.toFile(pUrl);
+                    path = file.getAbsolutePath();
 
-                if (file.getName().endsWith("persistence.xml")) {
-                    file = file.getParentFile().getParentFile();
-                }
-                String  moduleName = file.toURI().toString();
+                    if (file.getName().endsWith("persistence.xml")) {
+                        file = file.getParentFile().getParentFile();
+                    }
+                    moduleName = file.toURI().toString();
 
-                String rootUrl = moduleName;
+                    String tmpRootUrl = moduleName;
 
-                String extForm = persistenceUrl.toExternalForm();
-                if (extForm.contains("WEB-INF/classes/META-INF/")) {
-                    rootUrl = extForm.substring(0, extForm.indexOf("/META-INF"));
-                }
-                if (rootUrl.endsWith(".war")) {
-                    rootUrl = rootUrl.substring(0, rootUrl.length() - ".war".length());
+                    String extForm = pUrl.toExternalForm();
+                    if (extForm.contains("WEB-INF/classes/META-INF/")) {
+                        tmpRootUrl = extForm.substring(0, extForm.indexOf("/META-INF"));
+                    }
+                    if (tmpRootUrl.endsWith(".war")) {
+                        tmpRootUrl = tmpRootUrl.substring(0, tmpRootUrl.length() - ".war".length());
+                    }
+                    rootUrl = tmpRootUrl;
+                } else {
+                    moduleName = "";
+                    rootUrl = "";
+                    path = null;
                 }
 
                 try {
-                    Persistence persistence = JaxbPersistenceFactory.getPersistence(Persistence.class,
persistenceUrl);
+                    Persistence persistence = JaxbPersistenceFactory.getPersistence(Persistence.class,
source.get());
                     PersistenceModule persistenceModule = new PersistenceModule(rootUrl,
persistence);
                     persistenceModule.getWatchedResources().add(moduleName);
-                    if ("file".equals(persistenceUrl.getProtocol())) {
+                    if (url && "file".equals(((URL) persistenceUrl).getProtocol()))
{
                         persistenceModule.getWatchedResources().add(path);
                     }
                     appModule.getPersistenceModules().add(persistenceModule);



Mime
View raw message