ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1147674 - in /webservices/commons/trunk/modules/axiom: modules/axiom-api/src/main/java/org/apache/axiom/om/ modules/axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/ modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/ ...
Date Sun, 17 Jul 2011 16:18:38 GMT
Author: veithen
Date: Sun Jul 17 16:18:36 2011
New Revision: 1147674

URL: http://svn.apache.org/viewvc?rev=1147674&view=rev
Log:
Introduced a getSAXSource method in OMContainer. In LLOM and DOOM this method is implemented
using the existing OMSource class, but other implementations may return a SAXSource that uses
special optimizations.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetSAXSource.java
      - copied, changed from r1144617, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/jaxp/OMSourceToStreamResultTestCase.java
Removed:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/jaxp/OMSourceToStreamResultTestCase.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/jaxp/OMSourceToStreamResultTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/jaxp/OMSourceToStreamResultTest.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/OMSource.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/OMXMLReader.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/pom.xml
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
    webservices/commons/trunk/modules/axiom/src/docbkx/userguide.xml

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java?rev=1147674&r1=1147673&r2=1147674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
Sun Jul 17 16:18:36 2011
@@ -22,6 +22,11 @@ package org.apache.axiom.om;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.sax.SAXSource;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.ext.LexicalHandler;
 
 import java.io.OutputStream;
 import java.io.Writer;
@@ -299,4 +304,32 @@ public interface OMContainer extends OMS
      * @return an {@link XMLStreamReader} representation of this element
      */
     XMLStreamReader getXMLStreamReader(boolean cache);
+    
+    /**
+     * Get a {@link SAXSource} representation for this node. This method can be used to integrate
+     * Axiom with APIs and third party libraries that don't support StAX. In particular it
can be
+     * used with the {@link Transformer} API.
+     * <p>
+     * The returned object supports all events defined by {@link ContentHandler} and
+     * {@link LexicalHandler}, with the exception of DTD related events. {@link OMDocType}
nodes
+     * will be silently skipped.
+     * <p>
+     * If the node is an element and has a parent which is not a document, care is taken
to properly
+     * generate {@link ContentHandler#startPrefixMapping(String, String)} and
+     * {@link ContentHandler#endPrefixMapping(String)} events also for namespace mappings
declared
+     * on the ancestors of the element. To understand why this is important, consider the
following
+     * example:
+     * <pre>&lt;root xmlns:ns="urn:ns">&lt;element attr="ns:someThing"/>&lt;root></pre>
+     * <p>
+     * In that case, to correctly interpret the attribute value, the SAX content handler
must be
+     * aware of the namespace mapping for the <tt>ns</tt> prefix, even if the
serialization starts
+     * only at the child element.
+     * 
+     * @param cache
+     *            Indicates if caching should be enabled. If set to <code>false</code>,
the returned
+     *            {@link SAXSource} may only be used once, and using it may have the side
effect of
+     *            consuming the original content of this node.
+     * @return a {@link SAXSource} representation of this element
+     */
+    SAXSource getSAXSource(boolean cache);
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/OMSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/OMSource.java?rev=1147674&r1=1147673&r2=1147674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/OMSource.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/OMSource.java
Sun Jul 17 16:18:36 2011
@@ -21,6 +21,7 @@ package org.apache.axiom.om.impl.jaxp;
 
 import javax.xml.transform.sax.SAXSource;
 
+import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.impl.serialize.OMXMLReader;
 import org.xml.sax.InputSource;
@@ -32,9 +33,16 @@ import org.xml.sax.InputSource;
  * <p>
  * Note that {@link org.apache.axiom.om.OMDocType} nodes are not supported and will be
  * silently skipped.
+ * <p>
+ * <b>NOTE: As of version 1.2.13, application code should use
+ * {@link OMContainer#getSAXSource(boolean)} instead of instantiating this class directly.</b>
  */
 public class OMSource extends SAXSource {
     public OMSource(OMElement element) {
-        super(new OMXMLReader(element), new InputSource());
+        this((OMContainer)element);
+    }
+    
+    public OMSource(OMContainer node) {
+        super(new OMXMLReader(node), new InputSource());
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/OMXMLReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/OMXMLReader.java?rev=1147674&r1=1147673&r2=1147674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/OMXMLReader.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/OMXMLReader.java
Sun Jul 17 16:18:36 2011
@@ -29,6 +29,7 @@ import java.util.Set;
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMComment;
 import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
@@ -62,11 +63,11 @@ import org.xml.sax.XMLReader;
  * only at the child element.
  */
 public class OMXMLReader extends AbstractXMLReader {
-    private final OMElement element;
+    private final OMContainer root;
     private final AttributesAdapter attributesAdapter = new AttributesAdapter();
     
-    public OMXMLReader(OMElement element) {
-        this.element = element;
+    public OMXMLReader(OMContainer root) {
+        this.root = root;
     }
 
     public void parse(InputSource input) throws IOException, SAXException {
@@ -78,10 +79,21 @@ public class OMXMLReader extends Abstrac
     }
     
     private void parse() throws SAXException {
+        if (root instanceof OMDocument) {
+            generateEvents((OMDocument)root);
+        } else {
+            OMElement element = (OMElement)root;
+            contentHandler.startDocument();
+            generateParentPrefixMappingEvents(element, true);
+            generateEvents(element);
+            generateParentPrefixMappingEvents(element, false);
+            contentHandler.endDocument();
+        }
+    }
+    
+    private void generateEvents(OMDocument document) throws SAXException {
         contentHandler.startDocument();
-        generateParentPrefixMappingEvents(element, true);
-        generateEvents(element);
-        generateParentPrefixMappingEvents(element, false);
+        generateEventsForChildren(document);
         contentHandler.endDocument();
     }
     
@@ -156,7 +168,13 @@ public class OMXMLReader extends Abstrac
         // This is explicitely allowed by the specification of the startElement method.
         attributesAdapter.setAttributes(omElement);
         contentHandler.startElement(uri, localName, qName, attributesAdapter);
-        for (Iterator it = omElement.getChildren(); it.hasNext(); ) {
+        generateEventsForChildren(omElement);
+        contentHandler.endElement(uri, localName, qName);
+        generatePrefixMappingEvents(omElement, false);
+    }
+    
+    private void generateEventsForChildren(OMContainer parent) throws SAXException {
+        for (Iterator it = parent.getChildren(); it.hasNext(); ) {
             OMNode node = (OMNode)it.next();
             switch (node.getType()) {
                 case OMNode.ELEMENT_NODE:
@@ -188,8 +206,6 @@ public class OMXMLReader extends Abstrac
                     contentHandler.processingInstruction(pi.getTarget(), pi.getValue());
             }
         }
-        contentHandler.endElement(uri, localName, qName);
-        generatePrefixMappingEvents(omElement, false);
     }
     
     private void generateEvents(OMText omText, boolean space) throws SAXException {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java?rev=1147674&r1=1147673&r2=1147674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
Sun Jul 17 16:18:36 2011
@@ -32,6 +32,7 @@ import org.apache.axiom.om.impl.OMContai
 import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
+import org.apache.axiom.om.impl.jaxp.OMSource;
 import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
 import org.apache.axiom.om.impl.traverse.OMChildrenLocalNameIterator;
 import org.apache.axiom.om.impl.traverse.OMChildrenNamespaceIterator;
@@ -44,6 +45,7 @@ import org.w3c.dom.NodeList;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.sax.SAXSource;
 
 import java.util.Iterator;
 
@@ -694,4 +696,8 @@ public abstract class ParentNode extends
         }
         return new DOMStAXWrapper(builder, this, cache);
     }
+
+    public SAXSource getSAXSource(boolean cache) {
+        return new OMSource(this);
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java?rev=1147674&r1=1147673&r2=1147674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
Sun Jul 17 16:18:36 2011
@@ -29,6 +29,7 @@ import org.apache.axiom.om.impl.MTOMXMLS
 import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.OMDocumentImplUtil;
 import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.jaxp.OMSource;
 import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
 import org.apache.axiom.om.impl.traverse.OMChildrenLocalNameIterator;
 import org.apache.axiom.om.impl.traverse.OMChildrenNamespaceIterator;
@@ -38,6 +39,8 @@ import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.sax.SAXSource;
+
 import java.util.Iterator;
 
 /** Class OMDocumentImpl */
@@ -327,4 +330,8 @@ public class OMDocumentImpl extends OMSe
     public XMLStreamReader getXMLStreamReader(boolean cache) {
         return OMContainerHelper.getXMLStreamReader(this, cache);
     }
+
+    public SAXSource getSAXSource(boolean cache) {
+        return new OMSource(this);
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1147674&r1=1147673&r2=1147674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
Sun Jul 17 16:18:36 2011
@@ -39,6 +39,7 @@ import org.apache.axiom.om.impl.OMNodeEx
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.builder.XOPAwareStAXOMBuilder;
 import org.apache.axiom.om.impl.builder.XOPBuilder;
+import org.apache.axiom.om.impl.jaxp.OMSource;
 import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
 import org.apache.axiom.om.impl.traverse.OMChildElementIterator;
 import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
@@ -57,6 +58,7 @@ import javax.xml.stream.XMLStreamConstan
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.sax.SAXSource;
 
 import java.io.StringWriter;
 import java.util.HashMap;
@@ -1111,5 +1113,9 @@ public class OMElementImpl extends OMNod
             this.setComplete(true);
         }
     }
+
+    public SAXSource getSAXSource(boolean cache) {
+        return new OMSource(this);
+    }
 }
 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1147674&r1=1147673&r2=1147674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
Sun Jul 17 16:18:36 2011
@@ -42,6 +42,7 @@ import javax.xml.stream.XMLStreamConstan
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.sax.SAXSource;
 
 import java.io.IOException;
 import java.io.OutputStream;
@@ -1069,6 +1070,10 @@ public class OMSourcedElementImpl extend
         }
     }
     
+    public SAXSource getSAXSource(boolean cache) {
+        return super.getSAXSource(cache);
+    }
+
     class DeferredNamespace implements OMNamespace {
         
         final String uri;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/pom.xml?rev=1147674&r1=1147673&r2=1147674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/pom.xml Sun Jul 17 16:18:36
2011
@@ -72,5 +72,10 @@
             <classifier>tests</classifier>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>xalan</groupId>
+            <artifactId>xalan</artifactId>
+            <version>2.7.1</version>
+        </dependency>
     </dependencies>
 </project>

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=1147674&r1=1147673&r2=1147674&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
Sun Jul 17 16:18:36 2011
@@ -55,6 +55,8 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.builder.TestIOExceptionInGetText(metaFactory));
         for (int i=0; i<conformanceFiles.length; i++) {
             for (int j=0; j<containerFactories.length; j++) {
+                addTest(new org.apache.axiom.ts.om.container.TestGetSAXSource(metaFactory,
conformanceFiles[i], containerFactories[j], true));
+                addTest(new org.apache.axiom.ts.om.container.TestGetSAXSource(metaFactory,
conformanceFiles[i], containerFactories[j], false));
                 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));
                 for (int k=0; k<serializationMethods.length; k++) {

Copied: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetSAXSource.java
(from r1144617, webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/jaxp/OMSourceToStreamResultTestCase.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetSAXSource.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetSAXSource.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/jaxp/OMSourceToStreamResultTestCase.java&r1=1144617&r2=1147674&rev=1147674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/jaxp/OMSourceToStreamResultTestCase.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetSAXSource.java
Sun Jul 17 16:18:36 2011
@@ -16,65 +16,59 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.axiom.om.impl.jaxp;
+package org.apache.axiom.ts.om.container;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
 
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamResult;
 
 import junit.framework.TestSuite;
 
 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.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.jaxp.OMSource;
+import org.apache.axiom.om.util.StAXParserConfiguration;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.axiom.ts.ConformanceTestCase;
 import org.apache.axiom.util.stax.dialect.StAXDialect;
 import org.apache.axiom.util.stax.dialect.StAXDialectDetector;
+import org.apache.xalan.processor.TransformerFactoryImpl;
 
-public class OMSourceToStreamResultTestCase extends AbstractTestCase {
-    private final OMMetaFactory omMetaFactory;
-    private final TransformerFactory transformerFactory;
-    private final String file;
+public class TestGetSAXSource extends ConformanceTestCase {
+    private final OMContainerFactory containerFactory;
+    private final boolean cache;
     
-    private OMSourceToStreamResultTestCase(OMMetaFactory omMetaFactory,
-            TransformerFactory transformerFactory, String name, String file) {
-        super(name);
-        this.omMetaFactory = omMetaFactory;
-        this.transformerFactory = transformerFactory;
-        this.file = file;
+    public TestGetSAXSource(OMMetaFactory metaFactory, String file, OMContainerFactory containerFactory,
boolean cache) {
+        super(metaFactory, file);
+        this.containerFactory = containerFactory;
+        this.cache = cache;
+        containerFactory.addTestProperties(this);
+        addTestProperty("cache", Boolean.toString(cache));
     }
 
     protected void runTest() throws Throwable {
-        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
-        StAXDialect dialect = StAXDialectDetector.getDialect(inputFactory.getClass());
-        inputFactory = dialect.normalize(inputFactory);
-        // Make sure CDATA sections are reported by the StAX parser
-        inputFactory = dialect.enableCDataReporting(inputFactory);
-        XMLStreamReader reader = inputFactory.createXMLStreamReader(getTestResource(file));
-        StAXOMBuilder builder = new StAXOMBuilder(omMetaFactory.getOMFactory(), reader);
-        OMSource source = new OMSource(builder.getDocumentElement());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        StreamResult result = new StreamResult(out);
-        transformerFactory.newTransformer().transform(source, result);
-        assertXMLIdentical(compareXML(
-                toDocumentWithoutDTD(getTestResource(file)),
-                toDocumentWithoutDTD(new ByteArrayInputStream(out.toByteArray()))), true);
-    }
-    
-    public static TestSuite suite(OMMetaFactory omMetaFactory,
-            TransformerFactory transformerFactory) throws Exception {
-        TestSuite suite = new TestSuite();
-        String[] files = getConformanceTestFiles();
-        for (int i=0; i<files.length; i++) {
-            String file = files[i];
-            int idx = file.lastIndexOf('/');
-            String name = file.substring(idx+1);
-            suite.addTest(new OMSourceToStreamResultTestCase(omMetaFactory, transformerFactory,
-                    name, file));
+        InputStream in = getFileAsStream();
+        try {
+            OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(),
+                    StAXParserConfiguration.PRESERVE_CDATA_SECTIONS, in);
+            SAXSource source = containerFactory.getContainer(builder).getSAXSource(cache);
+            StreamResult result = new StreamResult(out);
+            new TransformerFactoryImpl().newTransformer().transform(source, result);
+        } finally {
+            in.close();
         }
-        return suite;
+        assertXMLIdentical(compareXML(
+                AbstractTestCase.toDocumentWithoutDTD(getFileAsStream()),
+                AbstractTestCase.toDocumentWithoutDTD(new ByteArrayInputStream(out.toByteArray()))),
true);
     }
 }

Modified: webservices/commons/trunk/modules/axiom/src/docbkx/userguide.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/docbkx/userguide.xml?rev=1147674&r1=1147673&r2=1147674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/docbkx/userguide.xml (original)
+++ webservices/commons/trunk/modules/axiom/src/docbkx/userguide.xml Sun Jul 17 16:18:36 2011
@@ -1237,6 +1237,28 @@ while (iterator.hasNext()) {
                     </para>
                 </section>
             </section>
+            <section id="changes-1.2.13">
+                <title>Changes in Axiom 1.2.13</title>
+                <section>
+                    <title>New abstract APIs</title>
+                    <para>
+                        Axiom 1.2.13 introduces a couple of new abstract APIs which give
implementations of the Axiom API
+                        the freedom to do additional optimizations. Application code should
be migrated to take
+                        advantage of these new APIs:
+                    </para>
+                    <itemizedlist>
+                        <listitem>
+                            <para>
+                                Instead of instantiating a <classname>OMSource</classname>
object directly,
+                                <methodname>OMContainer#getSAXSource(boolean)</methodname>
should be used.
+                            </para>
+                        </listitem>
+                    </itemizedlist>
+                    <para>
+                        Note that some of the superseded APIs may disappear in Axiom 1.3.
+                    </para>
+                </section>
+            </section>
         </section>
     </chapter>
 



Mime
View raw message