geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r553942 - in /geronimo/sandbox/j2g: plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/ plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/ plugins/org.apa...
Date Fri, 06 Jul 2007 16:16:00 GMT
Author: dwoods
Date: Fri Jul  6 09:15:59 2007
New Revision: 553942

URL: http://svn.apache.org/viewvc?view=rev&rev=553942
Log:
GERONIMO-3302 J2G for persistence.xml

Added:
    geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb/
    geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb/persistence_differences.properties
  (with props)
Modified:
    geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/EJBDescriptorTool.java
    geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationTool.java
    geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.util/src/org/apache/geronimo/j2g/util/descriptors/Constants.java
    geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.util/src/org/apache/geronimo/j2g/util/descriptors/xml/XMLConversionHelper.java

Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/EJBDescriptorTool.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/EJBDescriptorTool.java?view=diff&rev=553942&r1=553941&r2=553942
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/EJBDescriptorTool.java
(original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/EJBDescriptorTool.java
Fri Jul  6 09:15:59 2007
@@ -19,8 +19,12 @@
 
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Properties;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -35,6 +39,7 @@
 import org.apache.geronimo.j2g.util.descriptors.naming.NamingElementProcessor;
 import org.apache.geronimo.j2g.util.descriptors.security.SecurityElementProcessor;
 import org.apache.geronimo.j2g.util.descriptors.xml.XMLConversionHelper;
+import org.dom4j.Attribute;
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
 import org.dom4j.Element;
@@ -55,6 +60,10 @@
     private NamingElementProcessor namingElementProcessor;
 
     private SecurityElementProcessor securityElementProcessor;
+        
+    // location of the properties file used to extract the differences
+    private final String PROP_PERSISTENCE_FILE = "../properties/org.apache.geronimo.j2g.descriptors.ejb/persistence_differences.properties";
+  
 
     public EJBDescriptorTool() {
     	
@@ -116,9 +125,89 @@
             } else if (jbossFileName.equals(Constants.EJB_JAR_XML_FILE)){
                 out.info("Converting ejb-jar.xml file in " + directoryName);
                 out.info("Nothing to convert. Keep the file as it is");
+            }  else if (jbossFileName.equals(Constants.PERSISTENCE_XML_FILE)) {
+	                out.info("Converting persistence.xml file in " + directoryName);
+                try {
+                    // get the dom4j representation from the persistence.xml files
+                    Document persistenceDoc = XMLConversionHelper.getPersistenceDocument(directoryName);
+                    // migrate from the jboss persistence.xml to geronimo's persistence.xml
+                    migratePersistence(persistenceDoc.getRootElement());
+                    // construct the path
+                    String geronimoPersistenceFileName = directoryName + File.separator
+                    + Constants.PERSISTENCE_XML_FILE;
+                    // save the file
+                    XMLConversionHelper.saveGeronimoDocument(geronimoPersistenceFileName,
persistenceDoc);
+                    migrated = true;
+                    out.info("Successfully migrated the persistence.xml file in "
+                                + directoryName + ", with the error and warning messages
as shown");
+                } catch(DocumentException e) {
+                    out.error("Errors occurs while reading xml descriptor "
+                        + file.getAbsolutePath()
+                        + ". It is possible that the migrator cannot download an xml schema
or xml file has a wrong syntax. Nested exception:"
+                        + e.getMessage());
+                } catch(IOException e) {
+                    out.error("IO exception " + e.getMessage());
+                }
+             }
+         return migrated;
+     }
+    private void migratePersistence(Element rootElement) {
+        // populate the differences
+        HashMap<String, String> diffs = populatePersistenceDifferences();
+        // iterate through all the elements and convert them accordingly
+        Element rootChildElement;
+        for(Iterator it = rootElement.elements().iterator(); it.hasNext(); ) {
+            rootChildElement = (Element) it.next();
+            if(rootChildElement.getName().equals("property")) {
+                // swap out the name attribute of each <property> element
+                Attribute nameAttr = rootChildElement.attribute("name");
+                String nameValue = nameAttr.getValue();
+                String replacementValue = null;
+                if(diffs.containsKey(nameValue)) {
+                    replacementValue = diffs.get(nameValue);
+                    if(replacementValue.startsWith("suggestion:")) {
+                        // warn the user that there is a possible solution, but requires
further configuration
+                        out.warn("persistence.xml SUGGESTION: " + nameValue + " should probably
be replaced by " + replacementValue +
+                                    " but further configuration may be needed.");
+                    } else {
+                        // replace the property.name element with the analogous
+                        nameAttr.setValue(replacementValue);
+                        // update the tree
+                        rootChildElement.addAttribute("name", replacementValue);
+                        // tell them
+                        out.info("persistence.xml: " + nameValue + " was replaced by " +
replacementValue);
+                    }
+                } else {
+                    out.warn("You should manually convert this property name: " + nameValue);
+                    continue;
+                }
+            } else {
+                // recurse until I get to the end of the tree or when I see the <property>
elements
+                migratePersistence(rootChildElement);
+            }
+        }
+    }
+	    
+    private HashMap<String, String> populatePersistenceDifferences() {
+        //  populate the hashmap with info from the properties file
+        HashMap<String, String> diffs = new HashMap<String, String>();
+        Properties mappingProps = new Properties();
+        try {
+            mappingProps.load(new FileInputStream( PROP_PERSISTENCE_FILE ));
+            // fetch all keys from the properties file
+            Enumeration keys = mappingProps.propertyNames();
+            // for each key, store the analogous into the hashmap
+            while(keys.hasMoreElements()) {
+                String key = (String)keys.nextElement();
+                String value = mappingProps.getProperty(key);
+                diffs.put(key, value);
             }
-        return migrated;
+        } catch(Exception e) {
+            out.error("Cannot find properties file: " + PROP_PERSISTENCE_FILE);
+        }
+        return diffs;
     }
+	  
 
     private void migrate(Element jbossRootElement, Element geronimoRootElement) {
 

Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationTool.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationTool.java?view=diff&rev=553942&r1=553941&r2=553942
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationTool.java
(original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationTool.java
Fri Jul  6 09:15:59 2007
@@ -34,7 +34,6 @@
 import org.apache.geronimo.j2g.common.IOutput;
 import org.apache.geronimo.j2g.common.XMLMigrationTool;
 import org.apache.geronimo.j2g.common.Tool;
-import org.apache.geronimo.j2g.descriptors.app.ApplicationDescriptorTool;
 
 public class AnnotationTool implements IFileMigration {
     private IOutput out;

Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.util/src/org/apache/geronimo/j2g/util/descriptors/Constants.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.util/src/org/apache/geronimo/j2g/util/descriptors/Constants.java?view=diff&rev=553942&r1=553941&r2=553942
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.util/src/org/apache/geronimo/j2g/util/descriptors/Constants.java
(original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.util/src/org/apache/geronimo/j2g/util/descriptors/Constants.java
Fri Jul  6 09:15:59 2007
@@ -33,6 +33,8 @@
     public static final String JBOSS_JBOSS_APPLICATION_XML_FILE = "jboss-app.xml";
 
     public static final String GERONIMO_APPLICATION_XML_FILE = "geronimo-application.xml";
+    
+    public static final String PERSISTENCE_XML_FILE = "persistence.xml";
 
     //standard j2ee files
     public static final String WEB_XML_FILE = "web.xml";

Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.util/src/org/apache/geronimo/j2g/util/descriptors/xml/XMLConversionHelper.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.util/src/org/apache/geronimo/j2g/util/descriptors/xml/XMLConversionHelper.java?view=diff&rev=553942&r1=553941&r2=553942
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.util/src/org/apache/geronimo/j2g/util/descriptors/xml/XMLConversionHelper.java
(original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.util/src/org/apache/geronimo/j2g/util/descriptors/xml/XMLConversionHelper.java
Fri Jul  6 09:15:59 2007
@@ -201,6 +201,17 @@
         return geronimoOpenEjbDocument;
 
     }
+    
+        
+    public static Document getPersistenceDocument(String directoryName) throws DocumentException
{
+        File persistenceFile = new File(directoryName + File.separator + Constants.PERSISTENCE_XML_FILE);
+        Document geronimoPersistenceDoc = null;
+        if(persistenceFile.exists()) {
+            SAXReader saxReader = new SAXReader();
+            geronimoPersistenceDoc = saxReader.read(persistenceFile);
+        }
+        return geronimoPersistenceDoc;
+    }
 
     /**
      * writes the dom4j document object to the file given in fileNmae

Added: geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb/persistence_differences.properties
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb/persistence_differences.properties?view=auto&rev=553942
==============================================================================
--- geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb/persistence_differences.properties
(added)
+++ geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb/persistence_differences.properties
Fri Jul  6 09:15:59 2007
@@ -0,0 +1,24 @@
+#
+#  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.
+#
+###########################################################################
+# Jboss persistence.xml property names and its analogies.
+###########################################################################
+hibernate.connection.url = openjpa.ConnectionURL
+hibernate.connection.driver_class = openjpa.ConnectionDriverName
+hibernate.connection.password = openjpa.ConnectionPassword
+hibernate.connection.username = openjpa.ConnectionUserName
+hibernate.hbm2ddl.auto = suggestion:openjpa.jdbc.SynchronizeMappings

Propchange: geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb/persistence_differences.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message