geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r397077 - in /geronimo/branches/1.1/modules/upgrade: project.xml src/java/org/apache/geronimo/upgrade/Upgrade1_0To1_1.java src/test/org/apache/geronimo/upgrade/Upgrade1_0To1_1Test.java
Date Wed, 26 Apr 2006 04:07:41 GMT
Author: djencks
Date: Tue Apr 25 21:07:39 2006
New Revision: 397077

URL: http://svn.apache.org/viewcvs?rev=397077&view=rev
Log:
tweak upgrader to handle some ejb refs

Modified:
    geronimo/branches/1.1/modules/upgrade/project.xml
    geronimo/branches/1.1/modules/upgrade/src/java/org/apache/geronimo/upgrade/Upgrade1_0To1_1.java
    geronimo/branches/1.1/modules/upgrade/src/test/org/apache/geronimo/upgrade/Upgrade1_0To1_1Test.java

Modified: geronimo/branches/1.1/modules/upgrade/project.xml
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/upgrade/project.xml?rev=397077&r1=397076&r2=397077&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/upgrade/project.xml (original)
+++ geronimo/branches/1.1/modules/upgrade/project.xml Tue Apr 25 21:07:39 2006
@@ -133,6 +133,11 @@
             <artifactId>geronimo-kernel</artifactId>
             <version>${pom.currentVersion}</version>
         </dependency>
+        <dependency>
+            <groupId>mx4j</groupId>
+            <artifactId>mx4j</artifactId>
+            <version>${mx4j_version}</version>
+        </dependency>
 
     </dependencies>
 

Modified: geronimo/branches/1.1/modules/upgrade/src/java/org/apache/geronimo/upgrade/Upgrade1_0To1_1.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/upgrade/src/java/org/apache/geronimo/upgrade/Upgrade1_0To1_1.java?rev=397077&r1=397076&r2=397077&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/upgrade/src/java/org/apache/geronimo/upgrade/Upgrade1_0To1_1.java
(original)
+++ geronimo/branches/1.1/modules/upgrade/src/java/org/apache/geronimo/upgrade/Upgrade1_0To1_1.java
Tue Apr 25 21:07:39 2006
@@ -26,6 +26,8 @@
 import java.util.Collection;
 
 import javax.xml.namespace.QName;
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
 
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlException;
@@ -80,6 +82,15 @@
     private static final String DEFAULT_VERSION = "1-default";
     private static final QName CLIENT_ENVIRONMENT_QNAME = new QName("http://geronimo.apache.org/xml/ns/deployment-1.1",
"client-environment");
     private static final QName SERVER_ENVIRONMENT_QNAME = new QName("http://geronimo.apache.org/xml/ns/deployment-1.1",
"server-environment");
+    private static final QName EJB_LINK_QNAME = new QName("http://geronimo.apache.org/xml/ns/naming-1.1",
"ejb-link");
+    private static final QName PATTERN_QNAME = new QName("http://geronimo.apache.org/xml/ns/naming-1.1",
"pattern");
+    private static final QName GROUP_QNAME = new QName("http://geronimo.apache.org/xml/ns/naming-1.1",
"groupId");
+    private static final QName ARTIFACT_QNAME = new QName("http://geronimo.apache.org/xml/ns/naming-1.1",
"artifactId");
+    private static final QName VERSION_QNAME = new QName("http://geronimo.apache.org/xml/ns/naming-1.1",
"version");
+    private static final QName TYPE_QNAME = new QName("http://geronimo.apache.org/xml/ns/naming-1.1",
"type");
+    private static final QName MODULE_QNAME = new QName("http://geronimo.apache.org/xml/ns/naming-1.1",
"module");
+    private static final QName NAME_QNAME = new QName("http://geronimo.apache.org/xml/ns/naming-1.1",
"name");
+;
 
     public static void upgrade(InputStream source, Writer target) throws IOException, XmlException
{
         XmlObject xmlObject = parse(source);
@@ -101,8 +112,9 @@
                 } else if (configId != null) {
 
                     insertEnvironment(configId, parentId, cursor, ENVIRONMENT_QNAME, suppressDefaultEnvironment);
+                } else {
+                    cleanRef(cursor);
                 }
-
             }
         }
 
@@ -112,11 +124,102 @@
 
     }
 
+    private static void cleanRef(XmlCursor cursor) throws XmlException {
+        String localName = cursor.getName().getLocalPart();
+        if ("ejb-ref".equals(localName)) {
+            cursor.toFirstChild();
+            String application = null;
+            String module = null;
+            String name = null;
+            while (cursor.getName() != null) {
+                localName = cursor.getName().getLocalPart();
+                if ("ref-name".equals(localName)) {
+//                    cursor.toNextSibling();
+                } else if ("domain".equals(localName)) {
+                    cursor.removeXml();
+                } else if ("server".equals(localName)) {
+                    cursor.removeXml();
+                } else if ("application".equals(localName)) {
+                    application = cursor.getTextValue();
+                    if ("null".equals(application)) {
+                        application = null;
+                    }
+                    cursor.removeXml();
+                } else if ("module".equals(localName)) {
+                    if (application == null) {
+                        //this is a configuration name
+                        application = cursor.getTextValue();
+                    } else {
+                        module = cursor.getTextValue();
+                    }
+                    cursor.removeXml();
+                } else if ("type".equals(localName)) {
+                    cursor.removeXml();
+                } else if ("name".equals(localName)) {
+                    name = cursor.getTextValue();
+                    cursor.removeXml();
+                } else if ("ejb-link".equals(localName)) {
+                    break;
+                } else if ("target-name".equals(localName)) {
+                    String targetNameString = cursor.getTextValue();
+                    cursor.removeXml();
+                    ObjectName targetName;
+                    try {
+                        targetName = ObjectName.getInstance(targetNameString);
+                    } catch (MalformedObjectNameException e) {
+                        throw new XmlException("Invalid object name: " + targetNameString);
+                    }
+                    name = targetName.getKeyProperty("name");
+                    application = targetName.getKeyProperty("J2EEApplication");
+                    if ("null".equals(application)) {
+                        application = targetName.getKeyProperty("EJBModule");
+                    } else {
+                        module = targetName.getKeyProperty("EJBModule");
+                    }
+
+                } else if ("ns-corbaloc".equals(localName)) {
+                    cursor.toNextSibling();
+//                    cursor.toNextSibling();
+                } else if ("css".equals(localName)) {
+                    //TODO fix this
+//                    cursor.toNextSibling();
+                } else if ("css-link".equals(localName)) {
+//                    cursor.toNextSibling();
+                } else if ("css-name".equals(localName)) {
+//                    cursor.toNextSibling();
+                } else {
+                    throw new IllegalStateException("unrecognized element: " + cursor.getTextValue());
+                }
+                if (!cursor.toNextSibling()) {
+                    break;
+                }
+            }
+            if (name != null) {
+                cursor.beginElement(PATTERN_QNAME);
+                if (application != null) {
+                    try {
+                        Artifact artifact = Artifact.create(application);
+                        cursor.insertElementWithText(GROUP_QNAME, artifact.getGroupId());
+                        cursor.insertElementWithText(ARTIFACT_QNAME, artifact.getArtifactId());
+                    } catch (Exception e) {
+                        cursor.insertElementWithText(ARTIFACT_QNAME, application.replace('/',
'_'));
+                    }
+//                    cursor.insertElementWithText(VERSION_QNAME, artifact.getVersion().toString());
+                }
+                if (module != null) {
+                    cursor.insertElementWithText(MODULE_QNAME, module);
+                }
+                cursor.insertElementWithText(NAME_QNAME, name);
+                cursor.toNextToken();
+            }
+        }
+    }
+
     private static void insertEnvironment(Artifact configId, Artifact parentId, XmlCursor
cursor, QName environmentQname, boolean suppressDefaultEnvironment) {
         positionEnvironment(cursor);
         Environment environment = new Environment();
         environment.setConfigId(configId);
-        if (parentId != null ) {
+        if (parentId != null) {
             environment.addDependency(parentId, ImportType.ALL);
         }
         environment.setSuppressDefaultEnvironment(suppressDefaultEnvironment);
@@ -180,6 +283,7 @@
         }
 
     }
+
     private static void positionEnvironment(XmlCursor cursor) {
         XmlCursor.TokenType token;
         while ((token = cursor.toNextToken()) != XmlCursor.TokenType.START && token
!= XmlCursor.TokenType.END) {
@@ -210,7 +314,7 @@
         QName attrQName = new QName(null, "suppressDefaultParentId");
         if ((attrValue = cursor.getAttributeText(attrQName)) != null) {
             cursor.removeAttribute(attrQName);
-                return Boolean.valueOf(attrValue).booleanValue();
+            return Boolean.valueOf(attrValue).booleanValue();
         }
         return false;
     }

Modified: geronimo/branches/1.1/modules/upgrade/src/test/org/apache/geronimo/upgrade/Upgrade1_0To1_1Test.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/upgrade/src/test/org/apache/geronimo/upgrade/Upgrade1_0To1_1Test.java?rev=397077&r1=397076&r2=397077&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/upgrade/src/test/org/apache/geronimo/upgrade/Upgrade1_0To1_1Test.java
(original)
+++ geronimo/branches/1.1/modules/upgrade/src/test/org/apache/geronimo/upgrade/Upgrade1_0To1_1Test.java
Tue Apr 25 21:07:39 2006
@@ -56,6 +56,10 @@
         test("transport_2");
     }
 
+    public void test5() throws Exception {
+        test("assembly_1");
+    }
+
     private void test(String testName) throws Exception {
         InputStream srcXml = classLoader.getResourceAsStream(testName + ".xml");
         Writer targetXml = new StringWriter();



Mime
View raw message