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/04/16 21:48:26 UTC

svn commit: r1094037 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-api/src/main/java/org/apache/axiom/om/impl/ axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ axiom-impl/src/test/java/or...

Author: veithen
Date: Sat Apr 16 19:48:26 2011
New Revision: 1094037

URL: http://svn.apache.org/viewvc?rev=1094037&view=rev
Log:
AXIOM-353: Generalized the API introduced in r1088682 so that one can also create an OM builder from a DOMSource. Note that the DOM->StAX conversion is directly supported by Woodstox.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromDOMSource.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromSAXSource.java
      - copied, changed from r1089635, webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestSAXOMBuilder.java
Removed:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestSAXOMBuilder.java
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-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/AbstractOMMetaFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.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=1094037&r1=1094036&r2=1094037&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 Sat Apr 16 19:48:26 2011
@@ -20,7 +20,7 @@
 package org.apache.axiom.om;
 
 import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.Source;
 
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.soap.SOAPFactory;
@@ -98,7 +98,7 @@ public interface OMMetaFactory {
     OMXMLParserWrapper createOMBuilder(OMFactory omFactory, StAXParserConfiguration configuration, InputSource is);
     
     /**
-     * Create an object model builder for plain XML that gets its input from a {@link SAXSource}.
+     * Create an object model builder for plain XML that gets its input from a {@link Source}.
      * 
      * @param omFactory
      *            The object model factory to use. This factory must be obtained from the same
@@ -110,7 +110,7 @@ public interface OMMetaFactory {
      *            the source of the XML document
      * @return the builder
      */
-    OMXMLParserWrapper createSAXOMBuilder(OMFactory omFactory, SAXSource source);
+    OMXMLParserWrapper createOMBuilder(OMFactory omFactory, Source source);
     
     /**
      * Create an object model builder for SOAP that pulls events from a StAX stream reader. The

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java?rev=1094037&r1=1094036&r2=1094037&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java Sat Apr 16 19:48:26 2011
@@ -22,7 +22,7 @@ import java.io.InputStream;
 import java.io.Reader;
 
 import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.Source;
 
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.soap.SOAPFactory;
@@ -182,19 +182,19 @@ public class OMXMLBuilderFactory {
     
     /**
      * Create an object model builder that reads a plain XML document from the provided
-     * {@link SAXSource}.
+     * {@link Source}.
      * 
      * @param source
      *            the source of the XML document
      * @return the builder
      */
-    public static OMXMLParserWrapper createSAXOMBuilder(SAXSource source) {
+    public static OMXMLParserWrapper createOMBuilder(Source source) {
         OMMetaFactory metaFactory = OMAbstractFactory.getMetaFactory();
-        return metaFactory.createSAXOMBuilder(metaFactory.getOMFactory(), source);
+        return metaFactory.createOMBuilder(metaFactory.getOMFactory(), source);
     }
     
     /**
-     * Create an object model builder that reads an XML document from the provided {@link SAXSource}
+     * Create an object model builder that reads an XML document from the provided {@link Source}
      * using a specified object model factory.
      * 
      * @param omFactory
@@ -203,8 +203,8 @@ public class OMXMLBuilderFactory {
      *            the source of the XML document
      * @return the builder
      */
-    public static OMXMLParserWrapper createSAXOMBuilder(OMFactory omFactory, SAXSource source) {
-        return omFactory.getMetaFactory().createSAXOMBuilder(omFactory, source);
+    public static OMXMLParserWrapper createOMBuilder(OMFactory omFactory, Source source) {
+        return omFactory.getMetaFactory().createOMBuilder(omFactory, source);
     }
     
     /**

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/AbstractOMMetaFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/AbstractOMMetaFactory.java?rev=1094037&r1=1094036&r2=1094037&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/AbstractOMMetaFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/AbstractOMMetaFactory.java Sat Apr 16 19:48:26 2011
@@ -20,6 +20,7 @@ package org.apache.axiom.om.impl;
 
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
 import javax.xml.transform.sax.SAXSource;
 
 import org.apache.axiom.om.OMException;
@@ -72,8 +73,16 @@ public abstract class AbstractOMMetaFact
         return createStAXOMBuilder(omFactory, createXMLStreamReader(configuration, is));
     }
     
-    public OMXMLParserWrapper createSAXOMBuilder(OMFactory omFactory, SAXSource source) {
-        return new SAXOMXMLParserWrapper(omFactory, source);
+    public OMXMLParserWrapper createOMBuilder(OMFactory omFactory, Source source) {
+        if (source instanceof SAXSource) {
+            return new SAXOMXMLParserWrapper(omFactory, (SAXSource)source);
+        } else {
+            try {
+                return new StAXOMBuilder(omFactory, StAXUtils.getXMLInputFactory().createXMLStreamReader(source));
+            } catch (XMLStreamException ex) {
+                throw new OMException(ex);
+            }
+        }
     }
 
     public SOAPModelBuilder createStAXSOAPModelBuilder(XMLStreamReader parser) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1094037&r1=1094036&r2=1094037&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java Sat Apr 16 19:48:26 2011
@@ -23,6 +23,7 @@ import junit.framework.TestSuite;
 
 import org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactory;
 import org.apache.axiom.ts.OMTestSuiteBuilder;
+import org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromDOMSource;
 import org.apache.axiom.ts.om.container.TestSerialize;
 import org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCDATAEventFromElement;
 import org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithOMSourcedElementDescendant;
@@ -65,6 +66,12 @@ public class OMImplementationTest extend
         // TODO: this case is not working because Axiom doesn't serialize the DTD
         builder.exclude(TestSerialize.class, "(&(file=spaces.xml)(container=document))");
         
+        // TODO: CDATA sections are lost when using createOMBuilder with a DOMSource
+        builder.exclude(TestCreateOMBuilderFromDOMSource.class, "(|(file=cdata.xml)(file=test.xml))");
+        
+        // TODO: suspecting Woodstox bug here
+        builder.exclude(TestCreateOMBuilderFromDOMSource.class, "(file=spaces.xml)");
+        
         return builder.build();
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java?rev=1094037&r1=1094036&r2=1094037&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java Sat Apr 16 19:48:26 2011
@@ -23,6 +23,7 @@ import junit.framework.TestSuite;
 
 import org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory;
 import org.apache.axiom.ts.OMTestSuiteBuilder;
+import org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromDOMSource;
 import org.apache.axiom.ts.om.container.TestSerialize;
 import org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithOMSourcedElementDescendant;
 import org.apache.axiom.ts.om.node.TestInsertSiblingAfterOnChild;
@@ -48,6 +49,12 @@ public class OMImplementationTest extend
         // TODO: this case is not working because Axiom doesn't serialize the DTD
         builder.exclude(TestSerialize.class, "(&(file=spaces.xml)(container=document))");
         
+        // TODO: CDATA sections are lost when using createOMBuilder with a DOMSource
+        builder.exclude(TestCreateOMBuilderFromDOMSource.class, "(|(file=cdata.xml)(file=test.xml))");
+        
+        // TODO: suspecting Woodstox bug here
+        builder.exclude(TestCreateOMBuilderFromDOMSource.class, "(file=spaces.xml)");
+        
         return builder.build();
     }
 }

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=1094037&r1=1094036&r2=1094037&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 Sat Apr 16 19:48:26 2011
@@ -45,14 +45,15 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.attribute.TestEqualsHashCode(metaFactory));
         addTest(new org.apache.axiom.ts.om.attribute.TestGetQNameWithNamespace(metaFactory));
         addTest(new org.apache.axiom.ts.om.attribute.TestGetQNameWithoutNamespace(metaFactory));
+        for (int i=0; i<conformanceFiles.length; i++) {
+            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.TestGetDocumentElement(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestGetDocumentElementWithDiscardDocument(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestInvalidXML(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestIOExceptionInGetText(metaFactory));
         for (int i=0; i<conformanceFiles.length; i++) {
-            addTest(new org.apache.axiom.ts.om.builder.TestSAXOMBuilder(metaFactory, conformanceFiles[i]));
-        }
-        for (int i=0; i<conformanceFiles.length; i++) {
             for (int j=0; j<containerFactories.length; j++) {
                 addTest(new org.apache.axiom.ts.om.container.TestGetXMLStreamReader(metaFactory, conformanceFiles[i], containerFactories[j], true));
                 addTest(new org.apache.axiom.ts.om.container.TestGetXMLStreamReader(metaFactory, conformanceFiles[i], containerFactories[j], false));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromDOMSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromDOMSource.java?rev=1094037&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromDOMSource.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromDOMSource.java Sat Apr 16 19:48:26 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.ts.ConformanceTestCase;
+
+public class TestCreateOMBuilderFromDOMSource extends ConformanceTestCase {
+    public TestCreateOMBuilderFromDOMSource(OMMetaFactory metaFactory, String file) {
+        super(metaFactory, file);
+    }
+
+    protected void runTest() throws Throwable {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        DocumentBuilder documentBuilder = factory.newDocumentBuilder();
+        InputStream in = getFileAsStream();
+        try {
+            DOMSource source = new DOMSource(documentBuilder.parse(in));
+            OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), source);
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            builder.getDocument().serialize(baos);
+            assertXMLIdentical(compareXML(
+                    AbstractTestCase.toDocumentWithoutDTD(getFileAsStream()),
+                    AbstractTestCase.toDocumentWithoutDTD(new ByteArrayInputStream(baos.toByteArray()))), true);
+        } finally {
+            in.close();
+        }
+    }
+}

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

Copied: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromSAXSource.java (from r1089635, webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestSAXOMBuilder.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromSAXSource.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromSAXSource.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestSAXOMBuilder.java&r1=1089635&r2=1094037&rev=1094037&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestSAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromSAXSource.java Sat Apr 16 19:48:26 2011
@@ -33,8 +33,8 @@ import org.apache.axiom.om.OMXMLParserWr
 import org.apache.axiom.ts.ConformanceTestCase;
 import org.xml.sax.InputSource;
 
-public class TestSAXOMBuilder extends ConformanceTestCase {
-    public TestSAXOMBuilder(OMMetaFactory metaFactory, String file) {
+public class TestCreateOMBuilderFromSAXSource extends ConformanceTestCase {
+    public TestCreateOMBuilderFromSAXSource(OMMetaFactory metaFactory, String file) {
         super(metaFactory, file);
     }
 
@@ -46,7 +46,7 @@ public class TestSAXOMBuilder extends Co
         InputStream in = getFileAsStream();
         try {
             SAXSource source = new SAXSource(parser.getXMLReader(), new InputSource(in));
-            OMXMLParserWrapper builder = OMXMLBuilderFactory.createSAXOMBuilder(metaFactory.getOMFactory(), source);
+            OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), source);
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             builder.getDocument().serialize(baos);
             assertXMLIdentical(compareXML(