You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by xu...@apache.org on 2010/04/15 11:15:40 UTC

svn commit: r934336 - /geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/XmlUtil.java

Author: xuhaihong
Date: Thu Apr 15 09:15:38 2010
New Revision: 934336

URL: http://svn.apache.org/viewvc?rev=934336&view=rev
Log:
Only update version number for element named persistence, we might centralize those operations about updating namespace and version number in the future 

Modified:
    geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/XmlUtil.java

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/XmlUtil.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/XmlUtil.java?rev=934336&r1=934335&r2=934336&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/XmlUtil.java (original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/XmlUtil.java Thu Apr 15 09:15:38 2010
@@ -125,14 +125,10 @@ public final class XmlUtil {
         // marshal to xml
 
         String xml = marshal(root);
-        XmlCursor cursor = null;
         try {
             XmlObject xmlObject = XmlBeansUtil.parse(xml);
             //TODO Convert persistence version to 2.0, might be removed once OpenEJB begins to use latest JPA version
-            cursor = xmlObject.newCursor();
-            cursor.toStartDoc();
-            cursor.toFirstChild();
-            // SchemaConversionUtils.convertSchemaVersion(cursor, SchemaConversionUtils.JPA_PERSISTENCE_NAMESPACE, "http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd", "2.0");
+            convertPersistenceSchemaVersion(xmlObject);
             OpenejbGeronimoEjbJarType geronimoOpenejb = (OpenejbGeronimoEjbJarType) SchemaConversionUtils.fixGeronimoSchema(xmlObject, OPENEJBJAR_QNAME, OpenejbGeronimoEjbJarType.type);
             return geronimoOpenejb;
         } catch (Throwable e) {
@@ -142,21 +138,12 @@ public final class XmlUtil {
                 File tempFile = File.createTempFile("openejb-jar-", ".xml");
                 out = new FileOutputStream(tempFile);
                 out.write(xml.getBytes());
-                out.close();
                 filePath = tempFile.getAbsolutePath();
             } catch (Exception notImportant) {
             } finally {
                 IOUtils.close(out);
             }
-
-            throw new DeploymentException("Error parsing geronimo-openejb.xml with xmlbeans.  For debug purposes, XML content written to: "+filePath, e);
-        } finally {
-            if (cursor != null) {
-                try {
-                    cursor.dispose();
-                } catch (Exception e) {
-                }
-            }
+            throw new DeploymentException("Error parsing geronimo-openejb.xml with xmlbeans.  For debug purposes, XML content written to: " + filePath, e);
         }
     }
 
@@ -399,4 +386,32 @@ public final class XmlUtil {
         }
         return false;
     }
+
+    private static void convertPersistenceSchemaVersion(XmlObject xmlObject) {
+        XmlCursor cursor = null;
+        try {
+            cursor = xmlObject.newCursor();
+            cursor.toStartDoc();
+            if (cursor.toFirstChild()) {
+                do {
+                    QName name = cursor.getName();
+                    if (name.getLocalPart().equals("persistence")) {
+                        XmlCursor end = cursor.newCursor();
+                        end.toEndToken();
+                        cursor.push();
+                        SchemaConversionUtils.convertSchemaVersion(cursor, end, SchemaConversionUtils.JPA_PERSISTENCE_NAMESPACE, "http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd", "2.0");
+                        end.dispose();
+                        cursor.pop();
+                    }
+                } while (cursor.toNextSibling());
+            }
+        } finally {
+            if (cursor != null) {
+                try {
+                    cursor.dispose();
+                } catch (Exception e) {
+                }
+            }
+        }
+    }
 }