You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2005/02/04 07:59:51 UTC

svn commit: r151327 - in geronimo/trunk/modules/j2ee-schema/src: java/org/apache/geronimo/schema/SchemaConversionUtils.java test-data/j2ee_1_2dtd/ejb-1-11.xml test-data/j2ee_1_2dtd/ejb-1-21.xml test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java

Author: djencks
Date: Thu Feb  3 22:59:48 2005
New Revision: 151327

URL: http://svn.apache.org/viewcvs?view=rev&rev=151327
Log:
GERONIMO-567. Converted ejb 1.1 dds should get cmp-version 1.x for cmp entity beans

Added:
    geronimo/trunk/modules/j2ee-schema/src/test-data/j2ee_1_2dtd/ejb-1-11.xml
    geronimo/trunk/modules/j2ee-schema/src/test-data/j2ee_1_2dtd/ejb-1-21.xml
Modified:
    geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java
    geronimo/trunk/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java

Modified: geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java?view=diff&r1=151326&r2=151327
==============================================================================
--- geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java (original)
+++ geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java Thu Feb  3 22:59:48 2005
@@ -48,6 +48,7 @@
 
     private static final QName RESOURCE_ADAPTER_VERSION = new QName(J2EE_NAMESPACE, "resourceadapter-version");
     private static final QName TAGLIB = new QName(J2EE_NAMESPACE, "taglib");
+    private static final QName CMP_VERSION = new QName(J2EE_NAMESPACE, "cmp-version");
 
     private SchemaConversionUtils() {
     }
@@ -222,13 +223,29 @@
         }
         XmlCursor cursor = xmlObject.newCursor();
         XmlCursor moveable = xmlObject.newCursor();
-        String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";
-        String version = "2.1";
         try {
+            cursor.toFirstChild();
+            if ("http://java.sun.com/xml/ns/j2ee".equals(cursor.getName().getNamespaceURI())) {
+                XmlObject result = xmlObject.changeType(EjbJarDocument.type);
+                validateDD(result);
+                return (EjbJarDocument) result;
+            }
+            XmlDocumentProperties xmlDocumentProperties = cursor.documentProperties();
+            String publicId = xmlDocumentProperties.getDoctypePublicId();
+            String cmpVersion;
+            if ("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN".equals(publicId)) {
+                cmpVersion = "1.x";
+            } else if ("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN".equals(publicId)) {
+                cmpVersion = null;//2.x is the default "2.x";
+            } else {
+                throw new XmlException("Unrecognized document type: " + publicId);
+            }
+            String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";
+            String version = "2.1";
             convertToSchema(cursor, J2EE_NAMESPACE, schemaLocationURL, version);
             //play with message-driven
             cursor.toStartDoc();
-            convertBeans(cursor, moveable);
+            convertBeans(cursor, moveable, cmpVersion);
         } finally {
             cursor.dispose();
             moveable.dispose();
@@ -366,8 +383,8 @@
                 if (cursor.isStart()) {
                     String localName = cursor.getName().getLocalPart();
                     if (localName.equals("gbean")
-                    || localName.equals("dependency")
-                    || localName.equals("include")) {
+                            || localName.equals("dependency")
+                            || localName.equals("include")) {
                         convertElementToSchema(cursor, end, GERONIMO_SERVICE_NAMESPACE);
                     }
                 }
@@ -450,7 +467,7 @@
         return true;
     }
 
-    public static void convertBeans(XmlCursor cursor, XmlCursor moveable) {
+    public static void convertBeans(XmlCursor cursor, XmlCursor moveable, String cmpVersion) {
         cursor.toChild(J2EE_NAMESPACE, "ejb-jar");
         cursor.toChild(J2EE_NAMESPACE, "enterprise-beans");
         if (cursor.toFirstChild()) {
@@ -463,11 +480,17 @@
                     cursor.toNextSibling();
                     convertToJNDIEnvironmentRefsGroup(cursor, moveable);
                 } else if ("entity".equals(type)) {
+                    cursor.toChild(J2EE_NAMESPACE, "persistence-type");
+                    String persistenceType = cursor.getTextValue();
                     //reentrant is the last required tag before jndiEnvironmentRefsGroup
-                    cursor.toChild(J2EE_NAMESPACE, "reentrant");
+                    cursor.toNextSibling(J2EE_NAMESPACE, "reentrant");
                     //Convert 2.0 True/False to true/false for 2.1
                     cursor.setTextValue(cursor.getTextValue().toLowerCase());
-                    cursor.toNextSibling(J2EE_NAMESPACE, "cmp-version");
+                    if (cmpVersion != null && !cursor.toNextSibling(CMP_VERSION) && "Container".equals(persistenceType)) {
+                        cursor.toNextSibling();
+                        cursor.insertElementWithText(CMP_VERSION, cmpVersion);
+                    }
+
                     cursor.toNextSibling(J2EE_NAMESPACE, "abstract-schema-name");
                     while (cursor.toNextSibling(J2EE_NAMESPACE, "cmp-field")) {
                         ;

Added: geronimo/trunk/modules/j2ee-schema/src/test-data/j2ee_1_2dtd/ejb-1-11.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/j2ee-schema/src/test-data/j2ee_1_2dtd/ejb-1-11.xml?view=auto&rev=151327
==============================================================================
--- geronimo/trunk/modules/j2ee-schema/src/test-data/j2ee_1_2dtd/ejb-1-11.xml (added)
+++ geronimo/trunk/modules/j2ee-schema/src/test-data/j2ee_1_2dtd/ejb-1-11.xml Thu Feb  3 22:59:48 2005
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+    Copyright 2003-2004 The Apache Software Foundation
+
+    Licensed 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.
+-->
+
+<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN'
+ 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>
+
+<ejb-jar>
+    <description>description</description>
+    <display-name>My  Favorite Ejb</display-name>
+    <enterprise-beans>
+        <entity>
+            <description>description</description>
+            <display-name>Favorite Bean</display-name>
+            <ejb-name>FavoriteBean</ejb-name>
+            <home>org.apache.geronimo.FavoriteBeanHome</home>
+            <remote>org.apache.geronimo.FavoriteBean</remote>
+            <ejb-class>org.apache.geronimo.FavoriteBeanEJB</ejb-class>
+            <persistence-type>Container</persistence-type>
+            <prim-key-class>java.lang.Integer</prim-key-class>
+            <reentrant>False</reentrant>
+            <cmp-field>
+                <field-name>id</field-name>
+            </cmp-field>
+            <cmp-field>
+                <field-name>preference</field-name>
+            </cmp-field>
+            <cmp-field>
+                <field-name>color</field-name>
+            </cmp-field>
+            <primkey-field>id</primkey-field>
+        </entity>
+    </enterprise-beans>
+    <assembly-descriptor>
+        <container-transaction>
+            <method>
+                <ejb-name>FavoriteBean</ejb-name>
+                <method-intf>Home</method-intf>
+                <method-name>remove</method-name>
+                <method-params>
+                    <method-param>java.lang.Object</method-param>
+                </method-params>
+            </method>
+            <trans-attribute>Required</trans-attribute>
+        </container-transaction>
+        <container-transaction>
+            <method>
+                <ejb-name>FavoriteBean</ejb-name>
+                <method-intf>Home</method-intf>
+                <method-name>create</method-name>
+                <method-params>
+                    <method-param>int</method-param>
+                    <method-param>float</method-param>
+                    <method-param>java.lang.String</method-param>
+                </method-params>
+            </method>
+            <trans-attribute>Required</trans-attribute>
+        </container-transaction>
+        <container-transaction>
+            <method>
+                <ejb-name>FavoriteBean</ejb-name>
+                <method-intf>Remote</method-intf>
+                <method-name>getPreference</method-name>
+                <method-params/>
+            </method>
+            <trans-attribute>Required</trans-attribute>
+        </container-transaction>
+        <container-transaction>
+            <method>
+                <ejb-name>FavoriteBean</ejb-name>
+                <method-intf>Remote</method-intf>
+                <method-name>remove</method-name>
+                <method-params/>
+            </method>
+            <trans-attribute>Required</trans-attribute>
+        </container-transaction>
+        <container-transaction>
+            <method>
+                <ejb-name>FavoriteBean</ejb-name>
+                <method-intf>Home</method-intf>
+                <method-name>remove</method-name>
+                <method-params>
+                    <method-param>javax.ejb.Handle</method-param>
+                </method-params>
+            </method>
+            <trans-attribute>Required</trans-attribute>
+        </container-transaction>
+        <container-transaction>
+            <method>
+                <ejb-name>FavoriteBean</ejb-name>
+                <method-intf>Home</method-intf>
+                <method-name>findByPrimaryKey</method-name>
+                <method-params>
+                    <method-param>java.lang.Integer</method-param>
+                </method-params>
+            </method>
+            <trans-attribute>Required</trans-attribute>
+        </container-transaction>
+        <container-transaction>
+            <method>
+                <ejb-name>FavoriteBean</ejb-name>
+                <method-intf>Remote</method-intf>
+                <method-name>updatePreference</method-name>
+                <method-params>
+                    <method-param>float</method-param>
+                </method-params>
+            </method>
+            <trans-attribute>Required</trans-attribute>
+        </container-transaction>
+    </assembly-descriptor>
+</ejb-jar>
+

Added: geronimo/trunk/modules/j2ee-schema/src/test-data/j2ee_1_2dtd/ejb-1-21.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/j2ee-schema/src/test-data/j2ee_1_2dtd/ejb-1-21.xml?view=auto&rev=151327
==============================================================================
--- geronimo/trunk/modules/j2ee-schema/src/test-data/j2ee_1_2dtd/ejb-1-21.xml (added)
+++ geronimo/trunk/modules/j2ee-schema/src/test-data/j2ee_1_2dtd/ejb-1-21.xml Thu Feb  3 22:59:48 2005
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+    Copyright 2003-2004 The Apache Software Foundation
+
+    Licensed 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.
+-->
+
+<ejb-jar xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee">
+  <description>description</description>
+  <display-name>My  Favorite Ejb</display-name>
+  <enterprise-beans>
+    <entity>
+      <description>description</description>
+      <display-name>Favorite Bean</display-name>
+      <ejb-name>FavoriteBean</ejb-name>
+      <home>org.apache.geronimo.FavoriteBeanHome</home>
+      <remote>org.apache.geronimo.FavoriteBean</remote>
+      <ejb-class>org.apache.geronimo.FavoriteBeanEJB</ejb-class>
+      <persistence-type>Container</persistence-type>
+      <prim-key-class>java.lang.Integer</prim-key-class>
+      <reentrant>false</reentrant>
+      <cmp-version>1.x</cmp-version>
+      <cmp-field>
+        <field-name>id</field-name>
+      </cmp-field>
+      <cmp-field>
+        <field-name>preference</field-name>
+      </cmp-field>
+      <cmp-field>
+        <field-name>color</field-name>
+      </cmp-field>
+      <primkey-field>id</primkey-field>
+    </entity>
+  </enterprise-beans>
+  <assembly-descriptor>
+    <container-transaction>
+      <method>
+        <ejb-name>FavoriteBean</ejb-name>
+        <method-intf>Home</method-intf>
+        <method-name>remove</method-name>
+        <method-params>
+          <method-param>java.lang.Object</method-param>
+        </method-params>
+      </method>
+      <trans-attribute>Required</trans-attribute>
+    </container-transaction>
+    <container-transaction>
+      <method>
+        <ejb-name>FavoriteBean</ejb-name>
+        <method-intf>Home</method-intf>
+        <method-name>create</method-name>
+        <method-params>
+          <method-param>int</method-param>
+          <method-param>float</method-param>
+          <method-param>java.lang.String</method-param>
+        </method-params>
+      </method>
+      <trans-attribute>Required</trans-attribute>
+    </container-transaction>
+    <container-transaction>
+      <method>
+        <ejb-name>FavoriteBean</ejb-name>
+        <method-intf>Remote</method-intf>
+        <method-name>getPreference</method-name>
+        <method-params/>
+      </method>
+      <trans-attribute>Required</trans-attribute>
+    </container-transaction>
+    <container-transaction>
+      <method>
+        <ejb-name>FavoriteBean</ejb-name>
+        <method-intf>Remote</method-intf>
+        <method-name>remove</method-name>
+        <method-params/>
+      </method>
+      <trans-attribute>Required</trans-attribute>
+    </container-transaction>
+    <container-transaction>
+      <method>
+        <ejb-name>FavoriteBean</ejb-name>
+        <method-intf>Home</method-intf>
+        <method-name>remove</method-name>
+        <method-params>
+          <method-param>javax.ejb.Handle</method-param>
+        </method-params>
+      </method>
+      <trans-attribute>Required</trans-attribute>
+    </container-transaction>
+    <container-transaction>
+      <method>
+        <ejb-name>FavoriteBean</ejb-name>
+        <method-intf>Home</method-intf>
+        <method-name>findByPrimaryKey</method-name>
+        <method-params>
+          <method-param>java.lang.Integer</method-param>
+        </method-params>
+      </method>
+      <trans-attribute>Required</trans-attribute>
+    </container-transaction>
+    <container-transaction>
+      <method>
+        <ejb-name>FavoriteBean</ejb-name>
+        <method-intf>Remote</method-intf>
+        <method-name>updatePreference</method-name>
+        <method-params>
+          <method-param>float</method-param>
+        </method-params>
+      </method>
+      <trans-attribute>Required</trans-attribute>
+    </container-transaction>
+  </assembly-descriptor>
+</ejb-jar>

Modified: geronimo/trunk/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java?view=diff&r1=151326&r2=151327
==============================================================================
--- geronimo/trunk/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java (original)
+++ geronimo/trunk/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java Thu Feb  3 22:59:48 2005
@@ -144,6 +144,35 @@
         assertTrue("Differences after reconverting to application schema: " + problems, ok3);
     }
 
+    public void testEJB11ToEJB21Transform() throws Exception {
+        File srcXml = new File(basedir, "src/test-data/j2ee_1_2dtd/ejb-1-11.xml");
+        File expectedOutputXml = new File(basedir, "src/test-data/j2ee_1_2dtd/ejb-1-21.xml");
+        XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
+        XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
+        SchemaConversionUtils.validateDD(expected);
+        xmlObject = SchemaConversionUtils.convertToEJBSchema(xmlObject);
+//        System.out.println(xmlObject.toString());
+//        System.out.println(expected.toString());
+        List problems = new ArrayList();
+        boolean ok = compareXmlObjects(xmlObject, expected, problems);
+        assertTrue("Differences: " + problems, ok);
+        //make sure trying to convert twice has no bad effects
+        XmlCursor cursor2 = xmlObject.newCursor();
+        try {
+            String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";
+            String version = "2.1";
+            assertFalse(SchemaConversionUtils.convertToSchema(cursor2, SchemaConversionUtils.J2EE_NAMESPACE, schemaLocationURL, version));
+        } finally {
+            cursor2.dispose();
+        }
+        boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
+        assertTrue("Differences after reconverting to schema: " + problems, ok2);
+        //do the whole transform twice...
+        xmlObject = SchemaConversionUtils.convertToEJBSchema(xmlObject);
+        boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
+        assertTrue("Differences after reconverting to ejb schema: " + problems, ok3);
+    }
+
     public void testEJB20ToEJB21Transform() throws Exception {
         File srcXml = new File(basedir, "src/test-data/j2ee_1_3dtd/ejb-jar.xml");
         File expectedOutputXml = new File(basedir, "src/test-data/j2ee_1_3dtd/ejb-jar-21.xml");