ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1308398 - in /webservices/xmlschema/trunk/xmlschema-core/src: main/java/org/apache/ws/commons/schema/ test/java/tests/ test/resources/XMLSCHEMA-20/
Date Mon, 02 Apr 2012 15:47:50 GMT
Author: dkulp
Date: Mon Apr  2 15:47:49 2012
New Revision: 1308398

URL: http://svn.apache.org/viewvc?rev=1308398&view=rev
Log:
[XMLSCHEMA-20] Fix problem of serialized import elements always having
a targetNamespace attribute that may be empty.

Added:
    webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/
    webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test.xsd  
(with props)
    webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test2.xsd 
 (with props)
    webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test3.xsd 
 (with props)
Modified:
    webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
    webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/IncludeTest.java

Modified: webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java?rev=1308398&r1=1308397&r2=1308398&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
(original)
+++ webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
Mon Apr  2 15:47:49 2012
@@ -1392,7 +1392,7 @@ public class XmlSchemaSerializer {
         Element importEl = createNewElement(doc, "import",
                                             schema.getSchemaNamespacePrefix(), XmlSchema.SCHEMA_NS);
 
-        if (importObj.namespace != null) {
+        if (importObj.namespace != null && !"".equals(importObj.namespace)) {
             importEl.setAttributeNS(null, "namespace", importObj.namespace);
         }
 
@@ -1555,10 +1555,13 @@ public class XmlSchemaSerializer {
         schemaElement = serializedSchema;
 
         if (schemaObj.getSyntacticalTargetNamespace() != null) {
-            serializedSchema.setAttributeNS(null, "targetNamespace", schemaObj.getSyntacticalTargetNamespace());
+            String targetNamespace = schemaObj.getSyntacticalTargetNamespace();
+            if (targetNamespace != null && !"".equals(targetNamespace)) {
+                serializedSchema.setAttributeNS(null, "targetNamespace", targetNamespace);
+            }
 
             String targetNS =
-                    (String)schemaNamespace.get(schemaObj.getSyntacticalTargetNamespace());
+                    (String)schemaNamespace.get(targetNamespace);
 
             //if the namespace is not entered then add
             //the targetNamespace

Modified: webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/IncludeTest.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/IncludeTest.java?rev=1308398&r1=1308397&r2=1308398&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/IncludeTest.java (original)
+++ webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/IncludeTest.java Mon Apr
 2 15:47:49 2012
@@ -28,6 +28,9 @@ import java.util.Set;
 import javax.xml.namespace.QName;
 import javax.xml.transform.stream.StreamSource;
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
 import org.xml.sax.InputSource;
 
 import org.apache.ws.commons.schema.XmlSchema;
@@ -35,6 +38,7 @@ import org.apache.ws.commons.schema.XmlS
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaExternal;
 import org.apache.ws.commons.schema.XmlSchemaInclude;
+import org.apache.ws.commons.schema.constants.Constants;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -161,4 +165,21 @@ public class IncludeTest extends Assert 
         XmlSchema schema = schemaCol.read(isource);
         assertNotNull(schema);
     }
+    
+    
+    
+    @Test
+    public void testSerializeSchema() throws Exception { 
+        String uri = Resources.asURI("XMLSCHEMA-20/test.xsd");
+        InputSource isource = new InputSource(new FileInputStream(uri));
+        isource.setSystemId(uri);
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(isource);
+        assertNotNull(schema);
+        Document doc = schema.getSchemaDocument();
+        Element el = (Element)doc.getDocumentElement()
+            .getElementsByTagNameNS(Constants.URI_2001_SCHEMA_XSD, "import").item(0);
+        assertNotNull(el);
+        assertNull(el.getAttributeNodeNS(null, "targetNamespace"));
+    }
 }

Added: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test.xsd
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test.xsd?rev=1308398&view=auto
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test.xsd (added)
+++ webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test.xsd Mon
Apr  2 15:47:49 2012
@@ -0,0 +1,15 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+	targetNamespace="http://example.org/ord" 
+	xmlns="http://example.org/ord">
+
+	<xs:include schemaLocation="test2.xsd" />
+	<xs:import schemaLocation="test3.xsd" />
+
+	<xs:element name="order" type="OrderType" />
+	<xs:complexType name="OrderType">
+		<xs:sequence>
+			<xs:element name="number" type="OrderNumType" />
+		</xs:sequence>
+	</xs:complexType>
+
+</xs:schema>
\ No newline at end of file

Propchange: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test.xsd
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test2.xsd
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test2.xsd?rev=1308398&view=auto
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test2.xsd (added)
+++ webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test2.xsd Mon
Apr  2 15:47:49 2012
@@ -0,0 +1,9 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
+	xmlns="http://example.org/ord"
+	targetNamespace="http://example.org/ord">
+
+	<xs:simpleType name="OrderNumType">
+		<xs:restriction base="xs:string" />
+	</xs:simpleType>
+
+</xs:schema>
\ No newline at end of file

Propchange: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test2.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test2.xsd
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test2.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test3.xsd
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test3.xsd?rev=1308398&view=auto
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test3.xsd (added)
+++ webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test3.xsd Mon
Apr  2 15:47:49 2012
@@ -0,0 +1,2 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+</xs:schema>
\ No newline at end of file

Propchange: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test3.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test3.xsd
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-20/test3.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message