You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ja...@apache.org on 2006/07/05 17:32:51 UTC
svn commit: r419255 - in
/geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src:
java/org/apache/geronimo/schema/ test-data/j2ee_1_4schema/
test-data/javaee_5schema/ test/org/apache/geronimo/schema/
Author: janb
Date: Wed Jul 5 08:32:51 2006
New Revision: 419255
URL: http://svn.apache.org/viewvc?rev=419255&view=rev
Log:
make the full conversion to the javaee namespace work: note that the XmlObject has to be produced
using the XmlBeanUtils which converts a j2ee to a javaee namespace first as there is seemingly
no way to do this with just XmlCursor.
Added:
geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/j2ee_1_4schema/application-14.xml (with props)
geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/javaee_5schema/application-5.xml (with props)
Modified:
geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtilsJavaEE.java
geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java
Modified: geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtilsJavaEE.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtilsJavaEE.java?rev=419255&r1=419254&r2=419255&view=diff
==============================================================================
--- geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtilsJavaEE.java (original)
+++ geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtilsJavaEE.java Wed Jul 5 08:32:51 2006
@@ -93,34 +93,16 @@
cursor.toStartDoc();
cursor.toFirstChild();
if ("http://java.sun.com/xml/ns/j2ee".equals(cursor.getName().getNamespaceURI())) {
- System.err.println("DOC Is j2ee type, converting type and validating");
- System.err.println("PRIOR TO CONVERSION: "+xmlObject.toString());
- System.err.println("____________________________________");
- convertSchemaVersion(cursor, JAVAEE_NAMESPACE, schemaLocationURL, version);
-
- System.err.println("____________________________________");
- System.err.println("CONVERSION: "+xmlObject.toString());
- System.err.println("____________________________________");
- XmlObject result = xmlObject.changeType(ApplicationDocument.type);
- System.err.println("AFTER CONVERSION TO APPLICATIONDOCUMENT");
- System.err.println(result.toString());
+ convertSchemaVersion(cursor, JAVAEE_NAMESPACE, schemaLocationURL, version);
+ XmlObject result = xmlObject.changeType(ApplicationDocument.type);
validateDD(result);
return (ApplicationDocument) result;
}
if ("http://java.sun.com/xml/ns/javaee".equals(cursor.getName().getNamespaceURI())) {
- System.err.println("Doc is javaee namespace, ensuring full conversion");
- System.err.println("PRIOR TO CONVERSION: "+xmlObject.toString());
- System.err.println("____________________________________");
convertSchemaVersion(cursor, JAVAEE_NAMESPACE, schemaLocationURL, version);
-
- System.err.println("____________________________________");
- System.err.println("CONVERSION: "+xmlObject.toString());
- System.err.println("____________________________________");
- XmlObject result = xmlObject.changeType(ApplicationDocument.type);
- System.err.println("AFTER CONVERSION TO APPLICATIONDOCUMENT");
- System.err.println(result.toString());
+ XmlObject result = xmlObject.changeType(ApplicationDocument.type);
validateDD(result);
return (ApplicationDocument) result;
}
@@ -145,10 +127,7 @@
}
public static ApplicationClientDocument convertToApplicationClientSchema(XmlObject xmlObject) throws XmlException {
- if (ApplicationClientDocument.type.equals(xmlObject.schemaType())) {
- validateDD(xmlObject);
- return (ApplicationClientDocument) xmlObject;
- }
+
XmlCursor cursor = xmlObject.newCursor();
XmlCursor moveable = xmlObject.newCursor();
String schemaLocationURL = "http://java.sun.com/xml/ns/javaee/application-client_5.xsd ";
@@ -156,8 +135,14 @@
try {
cursor.toStartDoc();
cursor.toFirstChild();
- if ("http://java.sun.com/xml/ns/j2ee".equals(cursor.getName().getNamespaceURI())) {
- System.err.println("DOC Is j2ee type, converting type and validating");
+ if ("http://java.sun.com/xml/ns/j2ee".equals(cursor.getName().getNamespaceURI())) {
+ convertSchemaVersion(cursor, JAVAEE_NAMESPACE, schemaLocationURL, version);
+ XmlObject result = xmlObject.changeType(ApplicationDocument.type);
+ validateDD(result);
+ return (ApplicationClientDocument) result;
+ }
+
+ if ("http://java.sun.com/xml/ns/javaee".equals(cursor.getName().getNamespaceURI())) {
convertSchemaVersion(cursor, JAVAEE_NAMESPACE, schemaLocationURL, version);
XmlObject result = xmlObject.changeType(ApplicationDocument.type);
validateDD(result);
@@ -255,10 +240,6 @@
}
public static EjbJarDocument convertToEJBSchema(XmlObject xmlObject) throws XmlException {
- if (EjbJarDocument.type.equals(xmlObject.schemaType())) {
- validateDD(xmlObject);
- return (EjbJarDocument) xmlObject;
- }
String schemaLocationURL = "http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd";
String version = "3.0";
@@ -273,6 +254,14 @@
validateDD(result);
return (EjbJarDocument) result;
}
+
+ if ("http://java.sun.com/xml/ns/javaee".equals(cursor.getName().getNamespaceURI())) {
+ convertSchemaVersion(cursor, JAVAEE_NAMESPACE, schemaLocationURL, version);
+ XmlObject result = xmlObject.changeType(EjbJarDocument.type);
+ validateDD(result);
+ return (EjbJarDocument) result;
+ }
+
// deployment descriptor is probably in EJB 1.1 or 2.0 format
XmlDocumentProperties xmlDocumentProperties = cursor.documentProperties();
String publicId = xmlDocumentProperties.getDoctypePublicId();
@@ -303,11 +292,7 @@
}
public static WebAppDocument convertToServletSchema(XmlObject xmlObject) throws XmlException {
- if (WebAppDocument.type.equals(xmlObject.schemaType())) {
- System.err.println("DOC Is correct type:"+WebAppDocument.type+" validating");
- validateDD(xmlObject);
- return (WebAppDocument) xmlObject;
- }
+
String schemaLocationURL = "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
String version = "2.5";
XmlCursor cursor = xmlObject.newCursor();
@@ -315,7 +300,6 @@
cursor.toStartDoc();
cursor.toFirstChild();
if ("http://java.sun.com/xml/ns/j2ee".equals(cursor.getName().getNamespaceURI())) {
- System.err.println("DOC Is j2ee type, converting type and validating");
convertSchemaVersion(cursor,JAVAEE_NAMESPACE, schemaLocationURL, version);
XmlObject result = xmlObject.changeType(WebAppDocument.type);
validateDD(result);
@@ -323,19 +307,19 @@
}
if ("http://java.sun.com/xml/ns/javaee".equals(cursor.getName().getNamespaceURI())) {
- System.err.println("Doc is javaee namespace, converting to type:"+WebAppDocument.type);
+ convertSchemaVersion(cursor, JAVAEE_NAMESPACE, schemaLocationURL, version);
XmlObject result = xmlObject.changeType(WebAppDocument.type);
validateDD(result);
return (WebAppDocument) result;
}
+ //otherwise assume DTD
XmlDocumentProperties xmlDocumentProperties = cursor.documentProperties();
String publicId = xmlDocumentProperties.getDoctypePublicId();
if ("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN".equals(publicId) ||
"-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN".equals(publicId)) {
XmlCursor moveable = xmlObject.newCursor();
try {
- System.err.println("Coverting 2.3 or 2.2 to schema 5");
moveable.toStartDoc();
moveable.toFirstChild();
@@ -511,7 +495,7 @@
cursor.toNextToken();
if (isFirstStart) {
cursor.insertNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
- cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", "xsi"), namespace + schemaLocationURL);
+ cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", "xsi"), namespace + " "+schemaLocationURL);
cursor.insertAttributeWithValue(new QName("version"), version);
isFirstStart = false;
}
@@ -523,27 +507,28 @@
}
public static boolean convertSchemaVersion (XmlCursor cursor, String namespace, String schemaLocationURL, String version) {
-
- //convert namespace
boolean isFirstStart = true;
+
+
while (cursor.hasNextToken()) {
- if (cursor.isStart()) {
- System.err.println("CURSOR="+cursor.getName().getLocalPart()+" "+cursor.getName().getNamespaceURI());
+ if (cursor.isStart()) {
+ //convert namespace of each starting element
cursor.setName(new QName(namespace, cursor.getName().getLocalPart()));
- System.err.println("CURSOR="+cursor.getName().getLocalPart()+" "+cursor.getName().getNamespaceURI()+" "+cursor.getName().getPrefix());
- cursor.toNextToken();
if (isFirstStart) {
- cursor.removeAttribute(new QName("version"));
- //cursor.insertAttributeWithValue(new QName("version"), version);
- cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", "xsi"), namespace + " "+schemaLocationURL);
+ //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;
}
Added: geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/j2ee_1_4schema/application-14.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/j2ee_1_4schema/application-14.xml?rev=419255&view=auto
==============================================================================
--- geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/j2ee_1_4schema/application-14.xml (added)
+++ geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/j2ee_1_4schema/application-14.xml Wed Jul 5 08:32:51 2006
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application version="1.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
+ <description>Test</description>
+ <display-name>Test</display-name>
+ <module>
+ <java>xyz.jar</java>
+ </module>
+ <module>
+ <java>pqy.jar</java>
+ </module>
+ <module>
+ <web>
+ <web-uri>web.war</web-uri>
+ <context-root>/test</context-root>
+ </web>
+ </module>
+ <module>
+ <ejb>ejb.jar</ejb>
+ </module>
+</application>
Propchange: geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/j2ee_1_4schema/application-14.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/j2ee_1_4schema/application-14.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/j2ee_1_4schema/application-14.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/javaee_5schema/application-5.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/javaee_5schema/application-5.xml?rev=419255&view=auto
==============================================================================
--- geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/javaee_5schema/application-5.xml (added)
+++ geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/javaee_5schema/application-5.xml Wed Jul 5 08:32:51 2006
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application version="5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/application_5.xsd">
+ <description>Test</description>
+ <display-name>Test</display-name>
+ <module>
+ <java>xyz.jar</java>
+ </module>
+ <module>
+ <java>pqy.jar</java>
+ </module>
+ <module>
+ <web>
+ <web-uri>web.war</web-uri>
+ <context-root>/test</context-root>
+ </web>
+ </module>
+ <module>
+ <ejb>ejb.jar</ejb>
+ </module>
+</application>
Propchange: geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/javaee_5schema/application-5.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/javaee_5schema/application-5.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test-data/javaee_5schema/application-5.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java?rev=419255&r1=419254&r2=419255&view=diff
==============================================================================
--- geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java (original)
+++ geronimo/sandbox/servlet-2.5/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java Wed Jul 5 08:32:51 2006
@@ -18,6 +18,7 @@
package org.apache.geronimo.schema;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.net.URL;
@@ -27,6 +28,7 @@
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlOptions;
import org.apache.geronimo.xbeans.j2ee.EjbJarType;
/**
@@ -37,6 +39,14 @@
*/
public class SchemaConversionUtilsTest extends TestCase {
private ClassLoader classLoader = this.getClass().getClassLoader();
+ private XmlOptions options = new XmlOptions();
+ private HashMap namespaces = new HashMap();
+
+ public void setUp () throws Exception {
+ namespaces.clear();
+ namespaces.put("http://java.sun.com/xml/ns/j2ee", "http://java.sun.com/xml/ns/javaee");
+ options.setLoadSubstituteNamespaces(namespaces);
+ }
//comment on validity of j2ee 1.4 schemas: validation doesn't work...
// From: "Radu Preotiuc-Pietro" <ra...@bea.com>
@@ -87,7 +97,7 @@
boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
assertTrue("Differences after reconverting to application client schema: " + problems, ok3);
}
-
+*/
public void testApplication13ToApplication14Transform() throws Exception {
URL srcXml = classLoader.getResource("j2ee_1_3dtd/application-13.xml");
URL expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/application-14.xml");
@@ -116,6 +126,36 @@
boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
assertTrue("Differences after reconverting to application schema: " + problems, ok3);
}
+
+ public void testApplication14ToApplication15Transform() throws Exception {
+ URL srcXml = classLoader.getResource("j2ee_1_4schema/application-14.xml");
+ URL expectedOutputXml = classLoader.getResource("javaee_5schema/application-5.xml");
+ XmlObject xmlObject = XmlObject.Factory.parse(srcXml, options);
+ XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
+ SchemaConversionUtilsJavaEE.validateDD(expected);
+ xmlObject = SchemaConversionUtilsJavaEE.convertToApplicationSchema(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/application_5.xsd";
+ String version = "5";
+ assertFalse(SchemaConversionUtilsJavaEE.convertToSchema(cursor2, SchemaConversionUtilsJavaEE.JAVAEE_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 = SchemaConversionUtilsJavaEE.convertToApplicationSchema(xmlObject);
+ boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
+ assertTrue("Differences after reconverting to application schema: " + problems, ok3);
+ }
+ /*
public void testConnector10ToConnector15Transform() throws Exception {
URL srcXml = classLoader.getResource("j2ee_1_3dtd/ra-10.xml");
@@ -317,14 +357,31 @@
assertTrue("Differences: " + problems, ok);
}
*/
+
+ public void testWeb24To25Transform() throws Exception {
+ URL srcXml = classLoader.getResource("j2ee_1_4schema/web-2-24.xml");
+ URL expectedOutputXml = classLoader.getResource("javaee_5schema/web-2-25.xml");
+ XmlObject xmlObject = XmlObject.Factory.parse(srcXml, options);
+ xmlObject = SchemaConversionUtilsJavaEE.convertToServletSchema(xmlObject);
+ XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
+ System.out.println(xmlObject.toString());
+ System.out.println(expected.toString());
+ List problems = new ArrayList();
+ boolean ok = compareXmlObjects(xmlObject, expected, problems);
+ assertTrue("Differences: " + problems, ok);
+ xmlObject = SchemaConversionUtilsJavaEE.convertToServletSchema(xmlObject);
+ boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
+ assertTrue("Differences: " + problems, ok2);
+ }
+
public void testWeb23To25Transform() throws Exception {
URL srcXml = classLoader.getResource("j2ee_1_3dtd/web-23.xml");
URL expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/web-25.xml");
XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
xmlObject = SchemaConversionUtilsJavaEE.convertToServletSchema(xmlObject);
XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
-// System.out.println(xmlObject.toString());
-// System.out.println(expected.toString());
+ System.out.println(xmlObject.toString());
+ System.out.println(expected.toString());
List problems = new ArrayList();
boolean ok = compareXmlObjects(xmlObject, expected, problems);
assertTrue("Differences: " + problems, ok);
@@ -380,6 +437,7 @@
XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
xmlObject = SchemaConversionUtilsJavaEE.convertToServletSchema(xmlObject);
}
+
/*
public void testEJB21To21DoesNothing() throws Exception {
URL srcXml = classLoader.getResource("j2ee_1_4schema/ejb-jar.xml");