You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/09/07 08:48:43 UTC

svn commit: r1166019 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-testsuite/src/main/java/org/apache/axiom/ts/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/

Author: veithen
Date: Wed Sep  7 06:48:43 2011
New Revision: 1166019

URL: http://svn.apache.org/viewvc?rev=1166019&view=rev
Log:
Document and validate that the StAX builder performs namespace repairing (some Axis2 databindings rely on this).

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/NamespaceDeclarationFilter.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java?rev=1166019&r1=1166018&r2=1166019&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java Wed Sep  7 06:48:43 2011
@@ -67,6 +67,9 @@ public interface OMMetaFactory {
     
     /**
      * Create an object model builder for plain XML that pulls events from a StAX stream reader.
+     * <p>
+     * The implementation must perform namespace repairing, i.e. it must add appropriate namespace
+     * declarations if undeclared namespaces appear in the StAX stream.
      * 
      * @param omFactory
      *            The object model factory to use. This factory must be obtained from the same

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java?rev=1166019&r1=1166018&r2=1166019&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java Wed Sep  7 06:48:43 2011
@@ -60,6 +60,7 @@ public class OMTestSuiteBuilder extends 
             addTest(new org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromDOMSource(metaFactory, conformanceFiles[i]));
             addTest(new org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromSAXSource(metaFactory, conformanceFiles[i]));
         }
+        addTest(new org.apache.axiom.ts.om.builder.TestCreateStAXOMBuilderNamespaceRepairing(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestGetDocumentElement(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestGetDocumentElementWithDiscardDocument(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestInvalidXML(metaFactory));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/NamespaceDeclarationFilter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/NamespaceDeclarationFilter.java?rev=1166019&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/NamespaceDeclarationFilter.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/NamespaceDeclarationFilter.java Wed Sep  7 06:48:43 2011
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.om.builder;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper;
+
+/**
+ * {@link XMLStreamReader} wrapper that filters out all namespace declarations.
+ */
+public class NamespaceDeclarationFilter extends XMLStreamReaderWrapper {
+    public NamespaceDeclarationFilter(XMLStreamReader parent) {
+        super(parent);
+    }
+
+    public int getNamespaceCount() {
+        return 0;
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/NamespaceDeclarationFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing.java?rev=1166019&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing.java Wed Sep  7 06:48:43 2011
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.om.builder;
+
+import java.io.StringReader;
+import java.util.Iterator;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMMetaFactory#createStAXOMBuilder(OMFactory, XMLStreamReader)} performs
+ * namespace repairing.
+ */
+public class TestCreateStAXOMBuilderNamespaceRepairing extends AxiomTestCase {
+    public TestCreateStAXOMBuilderNamespaceRepairing(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader(
+                "<p:root xmlns:p='urn:ns1' xmlns:q='urn:ns2'><child q:attr='value'/></p:root>"));
+        OMElement element = metaFactory.createStAXOMBuilder(metaFactory.getOMFactory(),
+                new NamespaceDeclarationFilter(reader)).getDocumentElement();
+        
+        Iterator it = element.getAllDeclaredNamespaces();
+        assertTrue(it.hasNext());
+        OMNamespace ns = (OMNamespace)it.next();
+        assertEquals("p", ns.getPrefix());
+        assertEquals("urn:ns1", ns.getNamespaceURI());
+        assertFalse(it.hasNext());
+        
+        OMElement child = element.getFirstElement();
+        it = child.getAllDeclaredNamespaces();
+        assertTrue(it.hasNext());
+        ns = (OMNamespace)it.next();
+        assertEquals("q", ns.getPrefix());
+        assertEquals("urn:ns2", ns.getNamespaceURI());
+        assertFalse(it.hasNext());
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateStAXOMBuilderNamespaceRepairing.java
------------------------------------------------------------------------------
    svn:eol-style = native