Author: dkulp
Date: Mon Apr  2 15:47:39 2012
New Revision: 1308396

URL: http://svn.apache.org/viewvc?rev=1308396&view=rev
Log:
[XMLSCHEMA-23] Fix issues with namespace declarations not being
preserved on anything other than the top level element

Added:
    webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-23/
    
webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-23/test.xsd
   (with props)
Modified:
    
webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
    
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ExternalAttTest.java
    
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ext/PlainExtensionDeserializerTest.java

Modified: 
webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java?rev=1308396&r1=1308395&r2=1308396&view=diff
==============================================================================
--- 
webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
 (original)
+++ 
webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
 Mon Apr  2 15:47:39 2012
@@ -248,7 +248,7 @@ public class SchemaBuilder {
         }
 
         // process extra attributes and elements
-        processExtensibilityComponents(annotation, annotEl);
+        processExtensibilityComponents(annotation, annotEl, true);
         return annotation;
     }
 
@@ -352,7 +352,7 @@ public class SchemaBuilder {
         }
 
         // process extra attributes and elements
-        processExtensibilityComponents(ct, complexEl);
+        processExtensibilityComponents(ct, complexEl, true);
 
         return ct;
     }
@@ -487,7 +487,7 @@ public class SchemaBuilder {
         element.setMaxOccurs(getMaxOccurs(el));
 
         // process extra attributes and elements
-        processExtensibilityComponents(element, el);
+        processExtensibilityComponents(element, el, true);
 
         return element;
     }
@@ -579,7 +579,7 @@ public class SchemaBuilder {
         }
 
         // process extra attributes and elements
-        processExtensibilityComponents(include, includeEl);
+        processExtensibilityComponents(include, includeEl, true);
         return include;
     }
 
@@ -628,7 +628,7 @@ public class SchemaBuilder {
         }
 
         // process extra attributes and elements
-        processExtensibilityComponents(simpleType, simpleEl);
+        processExtensibilityComponents(simpleType, simpleEl, true);
 
         return simpleType;
     }
@@ -660,7 +660,7 @@ public class SchemaBuilder {
         }
 
         // add the extensibility components
-        processExtensibilityComponents(currentSchema, schemaEl);
+        processExtensibilityComponents(currentSchema, schemaEl, false);
 
         return currentSchema;
     }
@@ -1016,7 +1016,7 @@ public class SchemaBuilder {
         }
 
         // process extra attributes and elements
-        processExtensibilityComponents(attr, attrEl);
+        processExtensibilityComponents(attr, attrEl, true);
         return attr;
     }
 
@@ -1653,7 +1653,7 @@ public class SchemaBuilder {
                 }
                 restriction.getFacets().add(facet);
                 // process extra attributes and elements
-                processExtensibilityComponents(facet, el);
+                processExtensibilityComponents(facet, el, true);
             }
         }
         return restriction;
@@ -1737,7 +1737,7 @@ public class SchemaBuilder {
                     facet.setAnnotation(facetAnnotation);
                 }
                 // process extra attributes and elements
-                processExtensibilityComponents(facet, el);
+                processExtensibilityComponents(facet, el, true);
                 restriction.getFacets().add(facet);
             }
 
@@ -1826,7 +1826,9 @@ public class SchemaBuilder {
      * @param schemaObject
      * @param parentElement
      */
-    private void processExtensibilityComponents(XmlSchemaObject schemaObject, 
Element parentElement) {
+    private void processExtensibilityComponents(XmlSchemaObject schemaObject, 
+                                                Element parentElement,
+                                                boolean namespaces) {
 
         if (extReg != null) {
             // process attributes
@@ -1837,11 +1839,11 @@ public class SchemaBuilder {
                 String namespaceURI = attribute.getNamespaceURI();
                 String name = attribute.getLocalName();
 
-                if (namespaceURI != null && !"".equals(namespaceURI) && // 
ignore unqualified attributes
-                    !namespaceURI.startsWith(Constants.XMLNS_ATTRIBUTE_NS_URI) 
&& // ignore
-                    // namespaces
-                    !Constants.URI_2001_SCHEMA_XSD.equals(namespaceURI)) {
+                if (namespaceURI != null && !"".equals(namespaceURI) // ignore 
unqualified attributes
+                    // ignore namespaces
+                    && (namespaces || 
!namespaceURI.startsWith(Constants.XMLNS_ATTRIBUTE_NS_URI)) 
                     // does not belong to the schema namespace by any chance!
+                    && !Constants.URI_2001_SCHEMA_XSD.equals(namespaceURI)) {
                     QName qName = new QName(namespaceURI, name);
                     extReg.deserializeExtension(schemaObject, qName, 
attribute);
                 }

Modified: 
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ExternalAttTest.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ExternalAttTest.java?rev=1308396&r1=1308395&r2=1308396&view=diff
==============================================================================
--- 
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ExternalAttTest.java
 (original)
+++ 
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ExternalAttTest.java
 Mon Apr  2 15:47:39 2012
@@ -51,9 +51,7 @@ public class ExternalAttTest extends Ass
         Map<?, ?> extenalAttributeMap 
             = (Map<?, 
?>)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
         assertNotNull(extenalAttributeMap);
-
         assertEquals(1, extenalAttributeMap.size());
-
     }
 
 }

Modified: 
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ext/PlainExtensionDeserializerTest.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ext/PlainExtensionDeserializerTest.java?rev=1308396&r1=1308395&r2=1308396&view=diff
==============================================================================
--- 
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ext/PlainExtensionDeserializerTest.java
 (original)
+++ 
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ext/PlainExtensionDeserializerTest.java
 Mon Apr  2 15:47:39 2012
@@ -22,11 +22,16 @@ import java.util.Map;
 
 import javax.xml.parsers.DocumentBuilderFactory;
 
+import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.NodeList;
 
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.constants.Constants;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -82,4 +87,41 @@ public class PlainExtensionDeserializerT
 
         }
     }
+    
+    @Test
+    public void testExtensionAttributeNamespace() throws Exception {
+        //Test for XMLSCHEMA-23.  Need to deserialize the extension attributes 
and
+        //then serialize it again, but retain the namespace declarations
+        
+        // create a DOM document
+        DocumentBuilderFactory documentBuilderFactory = 
DocumentBuilderFactory.newInstance();
+        documentBuilderFactory.setNamespaceAware(true);
+        Document doc = documentBuilderFactory.newDocumentBuilder()
+            .parse(Resources.asURI("/XMLSCHEMA-23/test.xsd"));
+
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(doc, null);
+        assertNotNull(schema);
+
+        
+        doc = schema.getSchemaDocument();
+        NodeList nl = doc.getDocumentElement()
+                .getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema";, 
"element");
+        assertEquals(1, nl.getLength());
+        Element del = (Element)nl.item(0);
+        NamedNodeMap mp = del.getAttributes();
+        for (int x = 0; x < mp.getLength(); x++) {
+            Attr attr = (Attr)mp.item(x);
+            if (attr.getNamespaceURI() != null 
+                && !"".equals(attr.getNamespaceURI())
+                && 
!Constants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI())) {
+                String ns = del.lookupNamespaceURI(attr.getPrefix());
+                String pfx = del.lookupPrefix(attr.getNamespaceURI());
+                assertEquals(attr.getPrefix(), pfx);
+                assertEquals(attr.getNamespaceURI(), ns);
+            }
+        }
+    }
+    
+    
 }

Added: 
webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-23/test.xsd
URL: 
http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-23/test.xsd?rev=1308396&view=auto
==============================================================================
--- 
webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-23/test.xsd
 (added)
+++ 
webservices/xmlschema/trunk/xmlschema-core/src/test/resources/XMLSCHEMA-23/test.xsd
 Mon Apr  2 15:47:39 2012
@@ -0,0 +1,18 @@
+
+<xsd:schema 
+       targetNamespace="http://apache.org/hello_world_soap_http/types";
+       xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
+       xmlns:tns="http://apache.org/hello_world_soap_http/types";
+       elementFormDefault="qualified">
+
+
+       <xsd:complexType name="File">
+               <xsd:sequence>
+                       <xsd:element 
+                               xmlns:xmime="http://www.w3.org/2005/05/xmlmime";
+                               
xmime:expectedContentTypes="application/octet-stream"
+                               name="content" 
+                               type="xsd:base64Binary" />
+               </xsd:sequence>
+       </xsd:complexType>
+</xsd:schema>

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

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

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


Reply via email to