ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1741068 - in /webservices/axiom/trunk: aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/ testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/ testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap...
Date Tue, 26 Apr 2016 18:29:26 GMT
Author: veithen
Date: Tue Apr 26 18:29:26 2016
New Revision: 1741068

URL: http://svn.apache.org/viewvc?rev=1741068&view=rev
Log:
Eliminate duplicate code from AbstractOMMetaFactory. This also enables building a SOAPEnvelope
from a SAXSource.

Added:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderFactory.java
      - copied, changed from r1740922, webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestCreateSOAPModelBuilderFromSAXSource.java
  (with props)
Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java?rev=1741068&r1=1741067&r2=1741068&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java
Tue Apr 26 18:29:26 2016
@@ -18,49 +18,22 @@
  */
 package org.apache.axiom.om.impl.common.factory;
 
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.net.URL;
+import static org.apache.axiom.om.impl.common.factory.BuilderFactory.OM;
+import static org.apache.axiom.om.impl.common.factory.BuilderFactory.SOAP;
 
-import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamSource;
 
-import org.apache.axiom.core.CoreNode;
 import org.apache.axiom.core.NodeFactory;
-import org.apache.axiom.core.impl.builder.BuilderImpl;
-import org.apache.axiom.core.impl.builder.BuilderListener;
-import org.apache.axiom.core.impl.builder.PlainXMLModel;
-import org.apache.axiom.core.stream.FilteredXmlInput;
-import org.apache.axiom.core.stream.XmlInput;
-import org.apache.axiom.core.stream.dom.DOMInput;
-import org.apache.axiom.core.stream.sax.SAXInput;
-import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMXMLParserWrapper;
-import org.apache.axiom.om.impl.builder.Detachable;
-import org.apache.axiom.om.impl.common.builder.OMXMLParserWrapperImpl;
-import org.apache.axiom.om.impl.stream.stax.StAXPullInput;
 import org.apache.axiom.om.util.StAXParserConfiguration;
-import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.SOAPModelBuilder;
 import org.apache.axiom.soap.SOAPProcessingException;
-import org.apache.axiom.soap.impl.common.builder.SOAPFilter;
-import org.apache.axiom.soap.impl.common.builder.SOAPModel;
-import org.apache.axiom.soap.impl.common.builder.SOAPModelBuilderImpl;
-import org.apache.axiom.soap.impl.intf.AxiomSOAPEnvelope;
-import org.apache.axiom.soap.impl.intf.AxiomSOAPMessage;
-import org.apache.axiom.util.stax.XMLEventUtils;
-import org.apache.axiom.util.stax.XMLFragmentStreamReader;
 import org.apache.axiom.util.stax.xop.MimePartProvider;
-import org.apache.axiom.util.stax.xop.XOPDecodingStreamReader;
 import org.w3c.dom.Node;
 import org.xml.sax.InputSource;
 
@@ -69,232 +42,52 @@ import org.xml.sax.InputSource;
  * ({@link org.apache.axiom.core.impl.builder.BuilderImpl} and its subclasses).
  */
 public abstract class AbstractOMMetaFactory implements OMMetaFactory {
-    private final static class SourceInfo {
-        private final XMLStreamReader reader;
-        private final Detachable detachable;
-        private final Closeable closeable;
-        
-        SourceInfo(XMLStreamReader reader, Detachable detachable, Closeable closeable) {
-            this.reader = reader;
-            this.detachable = detachable;
-            this.closeable = closeable;
-        }
-
-        XMLStreamReader getReader() {
-            return reader;
-        }
-
-        Detachable getDetachable() {
-            return detachable;
-        }
-
-        Closeable getCloseable() {
-            return closeable;
-        }
-    }
-    
     private final NodeFactory nodeFactory;
     
     public AbstractOMMetaFactory(NodeFactory nodeFactory) {
         this.nodeFactory = nodeFactory;
     }
     
-    private static SourceInfo createXMLStreamReader(StAXParserConfiguration configuration,
-            InputSource is, boolean makeDetachable) {
-        XMLStreamReader reader;
-        Detachable detachable;
-        Closeable closeable;
-        try {
-            if (is.getByteStream() != null) {
-                String systemId = is.getSystemId();
-                String encoding = is.getEncoding();
-                InputStream in = is.getByteStream();
-                if (makeDetachable) {
-                    DetachableInputStream detachableInputStream = new DetachableInputStream(in,
false);
-                    in = detachableInputStream;
-                    detachable = detachableInputStream;
-                } else {
-                    detachable = null;
-                }
-                if (systemId != null) {
-                    if (encoding == null) {
-                        reader = StAXUtils.createXMLStreamReader(configuration, systemId,
in);
-                    } else {
-                        throw new UnsupportedOperationException();
-                    }
-                } else {
-                    if (encoding == null) {
-                        reader = StAXUtils.createXMLStreamReader(configuration, in);
-                    } else {
-                        reader = StAXUtils.createXMLStreamReader(configuration, in, encoding);
-                    }
-                }
-                closeable = null;
-            } else if (is.getCharacterStream() != null) {
-                Reader in = is.getCharacterStream();
-                if (makeDetachable) {
-                    DetachableReader detachableReader = new DetachableReader(in);
-                    in = detachableReader;
-                    detachable = detachableReader;
-                } else {
-                    detachable = null;
-                }
-                reader = StAXUtils.createXMLStreamReader(configuration, in);
-                closeable = null;
-            } else {
-                String systemId = is.getSystemId();
-                InputStream in = new URL(systemId).openConnection().getInputStream();
-                if (makeDetachable) {
-                    DetachableInputStream detachableInputStream = new DetachableInputStream(in,
true);
-                    in = detachableInputStream;
-                    detachable = detachableInputStream;
-                } else {
-                    detachable = null;
-                }
-                reader = StAXUtils.createXMLStreamReader(configuration, systemId, in);
-                closeable = in;
-            }
-        } catch (XMLStreamException ex) {
-            throw new OMException(ex);
-        } catch (IOException ex) {
-            throw new OMException(ex);
-        }
-        return new SourceInfo(reader, detachable, closeable);
-    }
-    
-    private static XMLStreamReader getXMLStreamReader(XMLStreamReader originalReader) {
-        int eventType = originalReader.getEventType();
-        switch (eventType) {
-            case XMLStreamReader.START_DOCUMENT:
-                return originalReader;
-            case XMLStreamReader.START_ELEMENT:
-                return new XMLFragmentStreamReader(originalReader);
-            default:
-                throw new OMException("The supplied XMLStreamReader is in an unexpected state
("
-                        + XMLEventUtils.getEventTypeString(eventType) + ")");
-        }
-    }
-    
-    private OMXMLParserWrapper createOMBuilder(XmlInput input, boolean repairNamespaces,
Detachable detachable) {
-        return new OMXMLParserWrapperImpl(new BuilderImpl(input, nodeFactory, PlainXMLModel.INSTANCE,
null, repairNamespaces), detachable);
-    }
-    
-    private SOAPModelBuilder createSOAPModelBuilder(XmlInput input,
-            boolean repairNamespaces, Detachable detachable) {
-        BuilderImpl builder = new BuilderImpl(new FilteredXmlInput(input, SOAPFilter.INSTANCE),
nodeFactory, new SOAPModel(), null, true);
-        // The SOAPFactory instance linked to the SOAPMessage is unknown until we reach the
-        // SOAPEnvelope. Register a post-processor that does the necessary updates on the
-        // SOAPMessage.
-        builder.addListener(new BuilderListener() {
-            private AxiomSOAPMessage message;
-            
-            @Override
-            public Runnable nodeAdded(CoreNode node, int depth) {
-                if (node instanceof AxiomSOAPMessage) {
-                    message = (AxiomSOAPMessage)node;
-                } else if (message != null && node instanceof AxiomSOAPEnvelope)
{
-                    message.initSOAPFactory((SOAPFactory)((AxiomSOAPEnvelope)node).getOMFactory());
-                }
-                return null;
-            }
-        });
-        return new SOAPModelBuilderImpl(builder, detachable);
-    }
-    
     public OMXMLParserWrapper createStAXOMBuilder(XMLStreamReader parser) {
-        return createOMBuilder(
-                new StAXPullInput(getXMLStreamReader(parser), false, null),
-                true, null);
+        return OM.createBuilder(nodeFactory, parser);
     }
 
     public OMXMLParserWrapper createOMBuilder(StAXParserConfiguration configuration, InputSource
is) {
-        SourceInfo sourceInfo = createXMLStreamReader(configuration, is, true);
-        return createOMBuilder(
-                new StAXPullInput(sourceInfo.getReader(), true, sourceInfo.getCloseable()),
-                false, sourceInfo.getDetachable());
-    }
-    
-    private static InputSource toInputSource(StreamSource source) {
-        InputSource is = new InputSource();
-        is.setByteStream(source.getInputStream());
-        is.setCharacterStream(source.getReader());
-        is.setPublicId(source.getPublicId());
-        is.setSystemId(source.getSystemId());
-        return is;
+        return OM.createBuilder(nodeFactory, configuration, is);
     }
     
     public OMXMLParserWrapper createOMBuilder(Source source) {
-        if (source instanceof SAXSource) {
-            return createOMBuilder((SAXSource)source, true);
-        } else if (source instanceof DOMSource) {
-            return createOMBuilder(((DOMSource)source).getNode(), true);
-        } else if (source instanceof StreamSource) {
-            return createOMBuilder(StAXParserConfiguration.DEFAULT, toInputSource((StreamSource)source));
-        } else {
-            try {
-                return createOMBuilder(
-                        new StAXPullInput(StAXUtils.getXMLInputFactory().createXMLStreamReader(source),
true, null),
-                        true, null);
-            } catch (XMLStreamException ex) {
-                throw new OMException(ex);
-            }
-        }
+        return OM.createBuilder(nodeFactory, StAXParserConfiguration.DEFAULT, source);
     }
 
     public OMXMLParserWrapper createOMBuilder(Node node, boolean expandEntityReferences)
{
-        return createOMBuilder(
-                new DOMInput(node, expandEntityReferences),
-                true, null);
+        return OM.createBuilder(nodeFactory, node, expandEntityReferences);
     }
 
     public OMXMLParserWrapper createOMBuilder(SAXSource source, boolean expandEntityReferences)
{
-        return createOMBuilder(new SAXInput(source, expandEntityReferences), true, null);
+        return OM.createBuilder(nodeFactory, source, expandEntityReferences);
     }
 
     public OMXMLParserWrapper createOMBuilder(StAXParserConfiguration configuration,
             InputSource rootPart, MimePartProvider mimePartProvider) {
-        SourceInfo sourceInfo = createXMLStreamReader(configuration, rootPart, false);
-        return createOMBuilder(
-                new StAXPullInput(new XOPDecodingStreamReader(sourceInfo.getReader(), mimePartProvider),
true, sourceInfo.getCloseable()), 
-                false, mimePartProvider instanceof Detachable ? (Detachable)mimePartProvider
: null);
+        return OM.createBuilder(nodeFactory, configuration, rootPart, mimePartProvider);
     }
 
     public SOAPModelBuilder createStAXSOAPModelBuilder(XMLStreamReader parser) {
-        return createSOAPModelBuilder(new StAXPullInput(getXMLStreamReader(parser), false,
null), true, null);
+        return SOAP.createBuilder(nodeFactory, parser);
     }
 
     public SOAPModelBuilder createSOAPModelBuilder(StAXParserConfiguration configuration,
InputSource is) {
-        SourceInfo sourceInfo = createXMLStreamReader(configuration, is, true);
-        return createSOAPModelBuilder(
-                new StAXPullInput(sourceInfo.getReader(), true, sourceInfo.getCloseable()),
-                false, sourceInfo.getDetachable());
+        return SOAP.createBuilder(nodeFactory, configuration, is);
     }
 
     public SOAPModelBuilder createSOAPModelBuilder(Source source) {
-        if (source instanceof SAXSource) {
-            // TODO: supporting this will require some refactoring of the builders
-            throw new UnsupportedOperationException();
-        } else if (source instanceof DOMSource) {
-            return createSOAPModelBuilder(new DOMInput(((DOMSource)source).getNode(), true),
true, null);
-        } else if (source instanceof StreamSource) {
-            return createSOAPModelBuilder(StAXParserConfiguration.SOAP,
-                    toInputSource((StreamSource)source));
-        } else {
-            try {
-                return createSOAPModelBuilder(new StAXPullInput(StAXUtils.getXMLInputFactory().createXMLStreamReader(source),
true, null), true, null);
-            } catch (XMLStreamException ex) {
-                throw new OMException(ex);
-            }
-        }
+        return SOAP.createBuilder(nodeFactory, StAXParserConfiguration.SOAP, source);
     }
 
     public SOAPModelBuilder createSOAPModelBuilder(StAXParserConfiguration configuration,
             SOAPFactory soapFactory, InputSource rootPart, MimePartProvider mimePartProvider)
{
-        SourceInfo sourceInfo = createXMLStreamReader(configuration, rootPart, false);
-        SOAPModelBuilder builder = createSOAPModelBuilder(
-                new StAXPullInput(new XOPDecodingStreamReader(sourceInfo.getReader(), mimePartProvider),
true, sourceInfo.getCloseable()),
-                false,
-                mimePartProvider instanceof Detachable ? (Detachable)mimePartProvider : null);
+        SOAPModelBuilder builder = SOAP.createBuilder(nodeFactory, configuration, rootPart,
mimePartProvider);
         if (builder.getSOAPMessage().getOMFactory() != soapFactory) {
             throw new SOAPProcessingException("Invalid SOAP namespace URI. " +
                     "Expected " + soapFactory.getSoapVersionURI(), SOAP12Constants.FAULT_CODE_SENDER);

Copied: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderFactory.java
(from r1740922, webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderFactory.java?p2=webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderFactory.java&p1=webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java&r1=1740922&r2=1741068&rev=1741068&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/BuilderFactory.java
Tue Apr 26 18:29:26 2016
@@ -41,17 +41,14 @@ import org.apache.axiom.core.stream.XmlI
 import org.apache.axiom.core.stream.dom.DOMInput;
 import org.apache.axiom.core.stream.sax.SAXInput;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.builder.Detachable;
 import org.apache.axiom.om.impl.common.builder.OMXMLParserWrapperImpl;
 import org.apache.axiom.om.impl.stream.stax.StAXPullInput;
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.om.util.StAXUtils;
-import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.SOAPModelBuilder;
-import org.apache.axiom.soap.SOAPProcessingException;
 import org.apache.axiom.soap.impl.common.builder.SOAPFilter;
 import org.apache.axiom.soap.impl.common.builder.SOAPModel;
 import org.apache.axiom.soap.impl.common.builder.SOAPModelBuilderImpl;
@@ -64,11 +61,7 @@ import org.apache.axiom.util.stax.xop.XO
 import org.w3c.dom.Node;
 import org.xml.sax.InputSource;
 
-/**
- * Base class for {@link OMMetaFactory} implementations that make use of the standard builders
- * ({@link org.apache.axiom.core.impl.builder.BuilderImpl} and its subclasses).
- */
-public abstract class AbstractOMMetaFactory implements OMMetaFactory {
+abstract class BuilderFactory<T extends OMXMLParserWrapper> {
     private final static class SourceInfo {
         private final XMLStreamReader reader;
         private final Detachable detachable;
@@ -93,12 +86,40 @@ public abstract class AbstractOMMetaFact
         }
     }
     
-    private final NodeFactory nodeFactory;
-    
-    public AbstractOMMetaFactory(NodeFactory nodeFactory) {
-        this.nodeFactory = nodeFactory;
-    }
-    
+    final static BuilderFactory<OMXMLParserWrapper> OM = new BuilderFactory<OMXMLParserWrapper>()
{
+        @Override
+        OMXMLParserWrapper createBuilder(NodeFactory nodeFactory, XmlInput input,
+                boolean repairNamespaces, Detachable detachable) {
+            return new OMXMLParserWrapperImpl(new BuilderImpl(input, nodeFactory,
+                    PlainXMLModel.INSTANCE, null, repairNamespaces), detachable);
+        }
+    };
+
+    final static BuilderFactory<SOAPModelBuilder> SOAP = new BuilderFactory<SOAPModelBuilder>()
{
+        @Override
+        SOAPModelBuilder createBuilder(NodeFactory nodeFactory, XmlInput input,
+                boolean repairNamespaces, Detachable detachable) {
+            BuilderImpl builder = new BuilderImpl(new FilteredXmlInput(input, SOAPFilter.INSTANCE),
nodeFactory, new SOAPModel(), null, true);
+            // The SOAPFactory instance linked to the SOAPMessage is unknown until we reach
the
+            // SOAPEnvelope. Register a post-processor that does the necessary updates on
the
+            // SOAPMessage.
+            builder.addListener(new BuilderListener() {
+                private AxiomSOAPMessage message;
+                
+                @Override
+                public Runnable nodeAdded(CoreNode node, int depth) {
+                    if (node instanceof AxiomSOAPMessage) {
+                        message = (AxiomSOAPMessage)node;
+                    } else if (message != null && node instanceof AxiomSOAPEnvelope)
{
+                        message.initSOAPFactory((SOAPFactory)((AxiomSOAPEnvelope)node).getOMFactory());
+                    }
+                    return null;
+                }
+            });
+            return new SOAPModelBuilderImpl(builder, detachable);
+        }
+    };
+
     private static SourceInfo createXMLStreamReader(StAXParserConfiguration configuration,
             InputSource is, boolean makeDetachable) {
         XMLStreamReader reader;
@@ -162,77 +183,48 @@ public abstract class AbstractOMMetaFact
         return new SourceInfo(reader, detachable, closeable);
     }
     
-    private static XMLStreamReader getXMLStreamReader(XMLStreamReader originalReader) {
-        int eventType = originalReader.getEventType();
+    abstract T createBuilder(NodeFactory nodeFactory, XmlInput input, boolean repairNamespaces,
+            Detachable detachable);
+
+    final T createBuilder(NodeFactory nodeFactory, XMLStreamReader reader) {
+        int eventType = reader.getEventType();
         switch (eventType) {
             case XMLStreamReader.START_DOCUMENT:
-                return originalReader;
+                break;
             case XMLStreamReader.START_ELEMENT:
-                return new XMLFragmentStreamReader(originalReader);
+                reader = new XMLFragmentStreamReader(reader);
+                break;
             default:
                 throw new OMException("The supplied XMLStreamReader is in an unexpected state
("
                         + XMLEventUtils.getEventTypeString(eventType) + ")");
         }
-    }
-    
-    private OMXMLParserWrapper createOMBuilder(XmlInput input, boolean repairNamespaces,
Detachable detachable) {
-        return new OMXMLParserWrapperImpl(new BuilderImpl(input, nodeFactory, PlainXMLModel.INSTANCE,
null, repairNamespaces), detachable);
-    }
-    
-    private SOAPModelBuilder createSOAPModelBuilder(XmlInput input,
-            boolean repairNamespaces, Detachable detachable) {
-        BuilderImpl builder = new BuilderImpl(new FilteredXmlInput(input, SOAPFilter.INSTANCE),
nodeFactory, new SOAPModel(), null, true);
-        // The SOAPFactory instance linked to the SOAPMessage is unknown until we reach the
-        // SOAPEnvelope. Register a post-processor that does the necessary updates on the
-        // SOAPMessage.
-        builder.addListener(new BuilderListener() {
-            private AxiomSOAPMessage message;
-            
-            @Override
-            public Runnable nodeAdded(CoreNode node, int depth) {
-                if (node instanceof AxiomSOAPMessage) {
-                    message = (AxiomSOAPMessage)node;
-                } else if (message != null && node instanceof AxiomSOAPEnvelope)
{
-                    message.initSOAPFactory((SOAPFactory)((AxiomSOAPEnvelope)node).getOMFactory());
-                }
-                return null;
-            }
-        });
-        return new SOAPModelBuilderImpl(builder, detachable);
-    }
-    
-    public OMXMLParserWrapper createStAXOMBuilder(XMLStreamReader parser) {
-        return createOMBuilder(
-                new StAXPullInput(getXMLStreamReader(parser), false, null),
-                true, null);
+        return createBuilder(nodeFactory, new StAXPullInput(reader, false, null), true, null);
     }
 
-    public OMXMLParserWrapper createOMBuilder(StAXParserConfiguration configuration, InputSource
is) {
+    final T createBuilder(NodeFactory nodeFactory, StAXParserConfiguration configuration,
+            InputSource is) {
         SourceInfo sourceInfo = createXMLStreamReader(configuration, is, true);
-        return createOMBuilder(
-                new StAXPullInput(sourceInfo.getReader(), true, sourceInfo.getCloseable()),
-                false, sourceInfo.getDetachable());
-    }
-    
-    private static InputSource toInputSource(StreamSource source) {
-        InputSource is = new InputSource();
-        is.setByteStream(source.getInputStream());
-        is.setCharacterStream(source.getReader());
-        is.setPublicId(source.getPublicId());
-        is.setSystemId(source.getSystemId());
-        return is;
+        return createBuilder(nodeFactory,
+                new StAXPullInput(sourceInfo.getReader(), true, sourceInfo.getCloseable()),
false,
+                sourceInfo.getDetachable());
     }
-    
-    public OMXMLParserWrapper createOMBuilder(Source source) {
+
+    final T createBuilder(NodeFactory nodeFactory, StAXParserConfiguration configuration,
Source source) {
         if (source instanceof SAXSource) {
-            return createOMBuilder((SAXSource)source, true);
+            return createBuilder(nodeFactory, (SAXSource)source, true);
         } else if (source instanceof DOMSource) {
-            return createOMBuilder(((DOMSource)source).getNode(), true);
+            return createBuilder(nodeFactory, ((DOMSource)source).getNode(), true);
         } else if (source instanceof StreamSource) {
-            return createOMBuilder(StAXParserConfiguration.DEFAULT, toInputSource((StreamSource)source));
+            StreamSource streamSource = (StreamSource)source;
+            InputSource is = new InputSource();
+            is.setByteStream(streamSource.getInputStream());
+            is.setCharacterStream(streamSource.getReader());
+            is.setPublicId(streamSource.getPublicId());
+            is.setSystemId(streamSource.getSystemId());
+            return createBuilder(nodeFactory, configuration, is);
         } else {
             try {
-                return createOMBuilder(
+                return createBuilder(nodeFactory,
                         new StAXPullInput(StAXUtils.getXMLInputFactory().createXMLStreamReader(source),
true, null),
                         true, null);
             } catch (XMLStreamException ex) {
@@ -241,64 +233,22 @@ public abstract class AbstractOMMetaFact
         }
     }
 
-    public OMXMLParserWrapper createOMBuilder(Node node, boolean expandEntityReferences)
{
-        return createOMBuilder(
-                new DOMInput(node, expandEntityReferences),
-                true, null);
+    final T createBuilder(NodeFactory nodeFactory, Node node, boolean expandEntityReferences)
{
+        return createBuilder(nodeFactory, new DOMInput(node, expandEntityReferences), true,
null);
     }
 
-    public OMXMLParserWrapper createOMBuilder(SAXSource source, boolean expandEntityReferences)
{
-        return createOMBuilder(new SAXInput(source, expandEntityReferences), true, null);
+    final T createBuilder(NodeFactory nodeFactory, SAXSource source, boolean expandEntityReferences)
{
+        return createBuilder(nodeFactory, new SAXInput(source, expandEntityReferences), true,
null);
     }
 
-    public OMXMLParserWrapper createOMBuilder(StAXParserConfiguration configuration,
+    final T createBuilder(NodeFactory nodeFactory, StAXParserConfiguration configuration,
             InputSource rootPart, MimePartProvider mimePartProvider) {
         SourceInfo sourceInfo = createXMLStreamReader(configuration, rootPart, false);
-        return createOMBuilder(
-                new StAXPullInput(new XOPDecodingStreamReader(sourceInfo.getReader(), mimePartProvider),
true, sourceInfo.getCloseable()), 
-                false, mimePartProvider instanceof Detachable ? (Detachable)mimePartProvider
: null);
-    }
-
-    public SOAPModelBuilder createStAXSOAPModelBuilder(XMLStreamReader parser) {
-        return createSOAPModelBuilder(new StAXPullInput(getXMLStreamReader(parser), false,
null), true, null);
-    }
-
-    public SOAPModelBuilder createSOAPModelBuilder(StAXParserConfiguration configuration,
InputSource is) {
-        SourceInfo sourceInfo = createXMLStreamReader(configuration, is, true);
-        return createSOAPModelBuilder(
-                new StAXPullInput(sourceInfo.getReader(), true, sourceInfo.getCloseable()),
-                false, sourceInfo.getDetachable());
-    }
-
-    public SOAPModelBuilder createSOAPModelBuilder(Source source) {
-        if (source instanceof SAXSource) {
-            // TODO: supporting this will require some refactoring of the builders
-            throw new UnsupportedOperationException();
-        } else if (source instanceof DOMSource) {
-            return createSOAPModelBuilder(new DOMInput(((DOMSource)source).getNode(), true),
true, null);
-        } else if (source instanceof StreamSource) {
-            return createSOAPModelBuilder(StAXParserConfiguration.SOAP,
-                    toInputSource((StreamSource)source));
-        } else {
-            try {
-                return createSOAPModelBuilder(new StAXPullInput(StAXUtils.getXMLInputFactory().createXMLStreamReader(source),
true, null), true, null);
-            } catch (XMLStreamException ex) {
-                throw new OMException(ex);
-            }
-        }
-    }
-
-    public SOAPModelBuilder createSOAPModelBuilder(StAXParserConfiguration configuration,
-            SOAPFactory soapFactory, InputSource rootPart, MimePartProvider mimePartProvider)
{
-        SourceInfo sourceInfo = createXMLStreamReader(configuration, rootPart, false);
-        SOAPModelBuilder builder = createSOAPModelBuilder(
-                new StAXPullInput(new XOPDecodingStreamReader(sourceInfo.getReader(), mimePartProvider),
true, sourceInfo.getCloseable()),
+        return createBuilder(nodeFactory,
+                new StAXPullInput(
+                        new XOPDecodingStreamReader(sourceInfo.getReader(), mimePartProvider),
true,
+                        sourceInfo.getCloseable()),
                 false,
-                mimePartProvider instanceof Detachable ? (Detachable)mimePartProvider : null);
-        if (builder.getSOAPMessage().getOMFactory() != soapFactory) {
-            throw new SOAPProcessingException("Invalid SOAP namespace URI. " +
-                    "Expected " + soapFactory.getSoapVersionURI(), SOAP12Constants.FAULT_CODE_SENDER);
-        }
-        return builder;
+                mimePartProvider instanceof Detachable ? (Detachable) mimePartProvider :
null);
     }
 }

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java?rev=1741068&r1=1741067&r2=1741068&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
(original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
Tue Apr 26 18:29:26 2016
@@ -130,6 +130,7 @@ public class SOAPTestSuiteBuilder extend
         addTest(new org.apache.axiom.ts.soap.builder.TestCommentInEpilog(metaFactory, spec));
         addTest(new org.apache.axiom.ts.soap.builder.TestCommentInProlog(metaFactory, spec));
         addTest(new org.apache.axiom.ts.soap.builder.TestCreateSOAPModelBuilderFromDOMSource(metaFactory,
spec));
+        addTest(new org.apache.axiom.ts.soap.builder.TestCreateSOAPModelBuilderFromSAXSource(metaFactory,
spec));
         addTest(new org.apache.axiom.ts.soap.builder.TestCreateSOAPModelBuilderMTOMContentTypeMismatch(metaFactory,
spec));
         addTest(new org.apache.axiom.ts.soap.builder.TestDTD(metaFactory, spec));
         if (supportsOMSourcedElement) {

Added: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestCreateSOAPModelBuilderFromSAXSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestCreateSOAPModelBuilderFromSAXSource.java?rev=1741068&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestCreateSOAPModelBuilderFromSAXSource.java
(added)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestCreateSOAPModelBuilderFromSAXSource.java
Tue Apr 26 18:29:26 2016
@@ -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.soap.builder;
+
+import static com.google.common.truth.Truth.assertAbout;
+import static com.google.common.truth.Truth.assertThat;
+import static org.apache.axiom.truth.xml.XMLTruth.xml;
+
+import java.io.InputStream;
+
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.sax.SAXSource;
+
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.soap.SOAPMessage;
+import org.apache.axiom.ts.jaxp.SAXImplementation;
+import org.apache.axiom.ts.soap.SOAPSample;
+import org.apache.axiom.ts.soap.SOAPSampleSet;
+import org.apache.axiom.ts.soap.SOAPSpec;
+import org.apache.axiom.ts.soap.SOAPTestCase;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+public class TestCreateSOAPModelBuilderFromSAXSource extends SOAPTestCase {
+    public TestCreateSOAPModelBuilderFromSAXSource(OMMetaFactory metaFactory, SOAPSpec spec)
{
+        super(metaFactory, spec);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        SAXParserFactory parserFactory = SAXImplementation.XERCES.newSAXParserFactory();
+        parserFactory.setNamespaceAware(true);
+        XMLReader reader = parserFactory.newSAXParser().getXMLReader();
+        SOAPSample sample = SOAPSampleSet.SIMPLE_FAULT.getMessage(spec);
+        InputStream in = sample.getInputStream();
+        InputSource is = new InputSource(in);
+        is.setEncoding(sample.getEncoding());
+        SOAPMessage message = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new
SAXSource(reader, is)).getSOAPMessage();
+        assertAbout(xml())
+                .that(xml(OMDocument.class, message))
+                .ignoringWhitespaceInPrologAndEpilog()
+                .hasSameContentAs(sample.getEnvelope());
+        assertThat(message.getSOAPEnvelope().getBody().getFault()).isNotNull();
+    }
+}

Propchange: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestCreateSOAPModelBuilderFromSAXSource.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message