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 2006/09/19 21:13:35 UTC

svn commit: r447932 - in /geronimo/server/trunk/modules/geronimo-j2ee-schema/src: main/java/org/apache/geronimo/schema/SchemaConversionUtils.java test/java/org/apache/geronimo/schema/SchemaConversionUtilsTest.java

Author: djencks
Date: Tue Sep 19 12:13:34 2006
New Revision: 447932

URL: http://svn.apache.org/viewvc?view=rev&rev=447932
Log:
GERONIMO-2414 baby steps: parameterize some helper methods for j2ee/jee namespace

Modified:
    geronimo/server/trunk/modules/geronimo-j2ee-schema/src/main/java/org/apache/geronimo/schema/SchemaConversionUtils.java
    geronimo/server/trunk/modules/geronimo-j2ee-schema/src/test/java/org/apache/geronimo/schema/SchemaConversionUtilsTest.java

Modified: geronimo/server/trunk/modules/geronimo-j2ee-schema/src/main/java/org/apache/geronimo/schema/SchemaConversionUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-schema/src/main/java/org/apache/geronimo/schema/SchemaConversionUtils.java?view=diff&rev=447932&r1=447931&r2=447932
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-schema/src/main/java/org/apache/geronimo/schema/SchemaConversionUtils.java (original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-schema/src/main/java/org/apache/geronimo/schema/SchemaConversionUtils.java Tue Sep 19 12:13:34 2006
@@ -38,7 +38,8 @@
  * @version $Rev$ $Date$
  */
 public class SchemaConversionUtils {
-    static final String J2EE_NAMESPACE = "http://java.sun.com/xml/ns/j2ee";
+    public static final String J2EE_NAMESPACE = "http://java.sun.com/xml/ns/j2ee";
+    public static final String JAVAEE_NAMESPACE = "http://java.sun.com/xml/ns/javaee";
 
     static final String GERONIMO_NAMING_NAMESPACE = "http://geronimo.apache.org/xml/ns/naming-1.2";
     private static final String GERONIMO_SECURITY_NAMESPACE = "http://geronimo.apache.org/xml/ns/security-1.2";
@@ -94,7 +95,7 @@
             cursor.toStartDoc();
             cursor.toChild(J2EE_NAMESPACE, "application");
             cursor.toFirstChild();
-            convertToDescriptionGroup(cursor, moveable);
+            convertToDescriptionGroup(J2EE_NAMESPACE, cursor, moveable);
         } finally {
             cursor.dispose();
             moveable.dispose();
@@ -123,7 +124,7 @@
             cursor.toStartDoc();
             cursor.toChild(J2EE_NAMESPACE, "application-client");
             cursor.toFirstChild();
-            convertToDescriptionGroup(cursor, moveable);
+            convertToDescriptionGroup(J2EE_NAMESPACE, cursor, moveable);
         } finally {
             cursor.dispose();
             moveable.dispose();
@@ -156,7 +157,7 @@
                     cursor.toStartDoc();
                     cursor.toChild(J2EE_NAMESPACE, "connector");
                     cursor.toFirstChild();
-                    convertToDescriptionGroup(cursor, moveable);
+                    convertToDescriptionGroup(J2EE_NAMESPACE, cursor, moveable);
                     cursor.toNextSibling(J2EE_NAMESPACE, "spec-version");
                     cursor.removeXml();
                     cursor.toNextSibling(J2EE_NAMESPACE, "version");
@@ -283,8 +284,8 @@
                     cursor.toStartDoc();
                     cursor.toChild(J2EE_NAMESPACE, "web-app");
                     cursor.toFirstChild();
-                    convertToDescriptionGroup(cursor, moveable);
-                    convertToJNDIEnvironmentRefsGroup(cursor, moveable);
+                    convertToDescriptionGroup(J2EE_NAMESPACE, cursor, moveable);
+                    convertToJNDIEnvironmentRefsGroup(J2EE_NAMESPACE, cursor, moveable);
                     cursor.push();
                     if (cursor.toNextSibling(TAGLIB)) {
                         cursor.toPrevSibling();
@@ -300,11 +301,11 @@
                         if ("filter".equals(name) || "servlet".equals(name) || "context-param".equals(name)) {
                             cursor.push();
                             cursor.toFirstChild();
-                            convertToDescriptionGroup(cursor, moveable);
+                            convertToDescriptionGroup(J2EE_NAMESPACE, cursor, moveable);
                             while (cursor.toNextSibling(J2EE_NAMESPACE, "init-param")) {
                                 cursor.push();
                                 cursor.toFirstChild();
-                                convertToDescriptionGroup(cursor, moveable);
+                                convertToDescriptionGroup(J2EE_NAMESPACE, cursor, moveable);
                                 cursor.pop();
                             }
                             cursor.pop();
@@ -462,6 +463,32 @@
         return true;
     }
 
+    public static boolean convertSchemaVersion (XmlCursor cursor, String namespace, String schemaLocationURL, String version) {
+        boolean isFirstStart = true;
+
+
+        while (cursor.hasNextToken()) {
+            if (cursor.isStart()) {
+                //convert namespace of each starting element
+                cursor.setName(new QName(namespace, cursor.getName().getLocalPart()));
+                if (isFirstStart) {
+                    //if we are at the first element in the document, reset the version number ...
+                    cursor.setAttributeText(new QName("version"), version);
+                    //... and also set the xsi:schemaLocation
+                    cursor.setAttributeText(new QName("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", "xsi"), namespace + "  "+schemaLocationURL);
+                    isFirstStart = false;
+                }
+                cursor.toNextToken();
+
+            } else {
+                cursor.toNextToken();
+            }
+        }
+
+
+        return true;
+    }
+
     public static void convertBeans(XmlCursor cursor, XmlCursor moveable, String cmpVersion) {
         cursor.toChild(J2EE_NAMESPACE, "ejb-jar");
         cursor.toChild(J2EE_NAMESPACE, "enterprise-beans");
@@ -473,7 +500,7 @@
                 if ("session".equals(type)) {
                     cursor.toChild(J2EE_NAMESPACE, "transaction-type");
                     cursor.toNextSibling();
-                    convertToJNDIEnvironmentRefsGroup(cursor, moveable);
+                    convertToJNDIEnvironmentRefsGroup(J2EE_NAMESPACE, cursor, moveable);
                 } else if ("entity".equals(type)) {
                     cursor.toChild(J2EE_NAMESPACE, "persistence-type");
                     String persistenceType = cursor.getTextValue();
@@ -491,7 +518,7 @@
                     }
                     cursor.toNextSibling(J2EE_NAMESPACE, "primkey-field");
                     cursor.toNextSibling();
-                    convertToJNDIEnvironmentRefsGroup(cursor, moveable);
+                    convertToJNDIEnvironmentRefsGroup(J2EE_NAMESPACE, cursor, moveable);
                 } else if ("message-driven".equals(type)) {
                     cursor.toFirstChild();
                     if (cursor.toNextSibling(J2EE_NAMESPACE, "messaging-type")) {
@@ -532,7 +559,7 @@
                         cursor.toNextSibling();
                         //cursor should now be at first element in JNDIEnvironmentRefsGroup
                     }
-                    convertToJNDIEnvironmentRefsGroup(cursor, moveable);
+                    convertToJNDIEnvironmentRefsGroup(J2EE_NAMESPACE, cursor, moveable);
                 }
                 cursor.pop();
             } while (cursor.toNextSibling());
@@ -557,44 +584,45 @@
     /**
      * Reorders elements to match descriptionGroup
      *
+     * @param namespace
      * @param cursor XmlCursor positioned at first element of "group" to be reordered
      */
-    public static void convertToDescriptionGroup(XmlCursor cursor, XmlCursor moveable) {
+    public static void convertToDescriptionGroup(String namespace, XmlCursor cursor, XmlCursor moveable) {
         moveable.toCursor(cursor);
-        moveElements("description", moveable, cursor);
-        moveElements("display-name", moveable, cursor);
-        moveElements("icon", moveable, cursor);
+        moveElements("description", namespace, moveable, cursor);
+        moveElements("display-name", namespace, moveable, cursor);
+        moveElements("icon", namespace, moveable, cursor);
     }
 
-    public static void convertToJNDIEnvironmentRefsGroup(XmlCursor cursor, XmlCursor moveable) {
-        moveElements("env-entry", moveable, cursor);
-        moveElements("ejb-ref", moveable, cursor);
-        moveElements("ejb-local-ref", moveable, cursor);
-        moveElements("resource-ref", moveable, cursor);
-        moveElements("resource-env-ref", moveable, cursor);
-        moveElements("message-destination-ref", moveable, cursor);
+    public static void convertToJNDIEnvironmentRefsGroup(String namespace, XmlCursor cursor, XmlCursor moveable) {
+        moveElements("env-entry", namespace, moveable, cursor);
+        moveElements("ejb-ref", namespace, moveable, cursor);
+        moveElements("ejb-local-ref", namespace, moveable, cursor);
+        moveElements("resource-ref", namespace, moveable, cursor);
+        moveElements("resource-env-ref", namespace, moveable, cursor);
+        moveElements("message-destination-ref", namespace, moveable, cursor);
         if (cursor.toPrevSibling()) {
             do {
                 String name = cursor.getName().getLocalPart();
                 if ("env-entry".equals(name)) {
                     cursor.push();
                     cursor.toFirstChild();
-                    convertToDescriptionGroup(cursor, moveable);
-                    convertToEnvEntryGroup(cursor, moveable);
+                    convertToDescriptionGroup(namespace, cursor, moveable);
+                    convertToEnvEntryGroup(namespace, cursor, moveable);
                     cursor.pop();
                 }
             } while (cursor.toPrevSibling());
         }
     }
 
-    public static void convertToEnvEntryGroup(XmlCursor cursor, XmlCursor moveable) {
-        moveElements("env-entry-name", moveable, cursor);
-        moveElements("env-entry-type", moveable, cursor);
-        moveElements("env-entry-value", moveable, cursor);
+    public static void convertToEnvEntryGroup(String namespace, XmlCursor cursor, XmlCursor moveable) {
+        moveElements("env-entry-name", namespace, moveable, cursor);
+        moveElements("env-entry-type", namespace, moveable, cursor);
+        moveElements("env-entry-value", namespace, moveable, cursor);
     }
 
-    private static void moveElements(String localName, XmlCursor moveable, XmlCursor toHere) {
-        QName name = new QName(J2EE_NAMESPACE, localName);
+    private static void moveElements(String localName, String namespace, XmlCursor moveable, XmlCursor toHere) {
+        QName name = new QName(namespace, localName);
         //skip elements already in the correct order.
         while (name.equals(toHere.getName()) && toHere.toNextSibling()) {
         }

Modified: geronimo/server/trunk/modules/geronimo-j2ee-schema/src/test/java/org/apache/geronimo/schema/SchemaConversionUtilsTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-schema/src/test/java/org/apache/geronimo/schema/SchemaConversionUtilsTest.java?view=diff&rev=447932&r1=447931&r2=447932
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-schema/src/test/java/org/apache/geronimo/schema/SchemaConversionUtilsTest.java (original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-schema/src/test/java/org/apache/geronimo/schema/SchemaConversionUtilsTest.java Tue Sep 19 12:13:34 2006
@@ -281,7 +281,7 @@
             do {
                 srcCursor.push();
                 srcCursor.toFirstChild();
-                SchemaConversionUtils.convertToDescriptionGroup(srcCursor, moveable);
+                SchemaConversionUtils.convertToDescriptionGroup(SchemaConversionUtils.J2EE_NAMESPACE, srcCursor, moveable);
                 srcCursor.pop();
             } while (srcCursor.toNextSibling());
         } finally {
@@ -310,7 +310,7 @@
                 srcCursor.toNextSibling();
                 srcCursor.toNextSibling();
                 moveable.toCursor(srcCursor);
-                SchemaConversionUtils.convertToJNDIEnvironmentRefsGroup(srcCursor, moveable);
+                SchemaConversionUtils.convertToJNDIEnvironmentRefsGroup(SchemaConversionUtils.J2EE_NAMESPACE, srcCursor, moveable);
                 srcCursor.pop();
             } while (srcCursor.toNextSibling());
         } finally {