Author: veithen
Date: Wed Jan 19 20:20:42 2011
New Revision: 1060962

URL: http://svn.apache.org/viewvc?rev=1060962&view=rev
Log:
AXIOM-353: Use an InputSource object to pass the stream internally to 
OMMetaFactory. This allows to reduce the number of different methods in 
OMMetaFactory and enables support for character encoding and system IDs.

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-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeToOutputStream.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=1060962&r1=1060961&r2=1060962&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 Jan 19 20:20:42 2011
@@ -19,13 +19,11 @@
 
 package org.apache.axiom.om;
 
-import java.io.InputStream;
-import java.io.Reader;
-
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.soap.SOAPFactory;
+import org.xml.sax.InputSource;
 
 /**
  * Object model meta factory.
@@ -78,31 +76,16 @@ public interface OMMetaFactory {
     
     /**
      * Create an object model builder that reads an XML document from the 
provided input
-     * stream.
-     * 
-     * @param omFactory
-     *            the object model factory to use; must be obtained from the 
same
-     *            {@link OMMetaFactory}
-     * @param configuration
-     *            the parser configuration to use
-     * @param in
-     *            the input stream representing the XML document
-     * @return the builder
-     */
-    OMXMLParserWrapper createOMBuilder(OMFactory omFactory, 
StAXParserConfiguration configuration, InputStream in);
-    
-    /**
-     * Create an object model builder that reads an XML document from the 
provided character
-     * stream.
+     * source.
      * 
      * @param omFactory
      *            the object model factory to use; must be obtained from the 
same
      *            {@link OMMetaFactory}
      * @param configuration
      *            the parser configuration to use
-     * @param in
-     *            the character stream representing the XML document
+     * @param is
+     *            the source of the XML document
      * @return the builder
      */
-    OMXMLParserWrapper createOMBuilder(OMFactory omFactory, 
StAXParserConfiguration configuration, Reader in);
+    OMXMLParserWrapper createOMBuilder(OMFactory omFactory, 
StAXParserConfiguration configuration, InputSource is);
 }

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=1060962&r1=1060961&r2=1060962&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
 Wed Jan 19 20:20:42 2011
@@ -24,6 +24,7 @@ import java.io.Reader;
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.om.util.StAXParserConfiguration;
+import org.xml.sax.InputSource;
 
 /**
  * Provides static factory methods to create various kinds of object model 
builders from different
@@ -83,7 +84,7 @@ public class OMXMLBuilderFactory {
      */
     public static OMXMLParserWrapper createOMBuilder(StAXParserConfiguration 
configuration, InputStream in) {
         OMMetaFactory metaFactory = OMAbstractFactory.getMetaFactory();
-        return metaFactory.createOMBuilder(metaFactory.getOMFactory(), 
configuration, in);
+        return metaFactory.createOMBuilder(metaFactory.getOMFactory(), 
configuration, new InputSource(in));
     }
     
     /**
@@ -114,7 +115,7 @@ public class OMXMLBuilderFactory {
      * @return the builder
      */
     public static OMXMLParserWrapper createOMBuilder(OMFactory omFactory, 
StAXParserConfiguration configuration, InputStream in) {
-        return omFactory.getMetaFactory().createOMBuilder(omFactory, 
configuration, in);
+        return omFactory.getMetaFactory().createOMBuilder(omFactory, 
configuration, new InputSource(in));
     }
     
     /**
@@ -142,7 +143,7 @@ public class OMXMLBuilderFactory {
      */
     public static OMXMLParserWrapper createOMBuilder(StAXParserConfiguration 
configuration, Reader in) {
         OMMetaFactory metaFactory = OMAbstractFactory.getMetaFactory();
-        return metaFactory.createOMBuilder(metaFactory.getOMFactory(), 
configuration, in);
+        return metaFactory.createOMBuilder(metaFactory.getOMFactory(), 
configuration, new InputSource(in));
     }
     
     /**
@@ -173,6 +174,6 @@ public class OMXMLBuilderFactory {
      * @return the builder
      */
     public static OMXMLParserWrapper createOMBuilder(OMFactory omFactory, 
StAXParserConfiguration configuration, Reader in) {
-        return omFactory.getMetaFactory().createOMBuilder(omFactory, 
configuration, in);
+        return omFactory.getMetaFactory().createOMBuilder(omFactory, 
configuration, new InputSource(in));
     }
 }

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=1060962&r1=1060961&r2=1060962&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
 Wed Jan 19 20:20:42 2011
@@ -18,9 +18,6 @@
  */
 package org.apache.axiom.om.impl;
 
-import java.io.InputStream;
-import java.io.Reader;
-
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
@@ -31,6 +28,7 @@ import org.apache.axiom.om.OMXMLParserWr
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.om.util.StAXUtils;
+import org.xml.sax.InputSource;
 
 /**
  * Base class for {@link OMMetaFactory} implementations that make use of the 
standard builders
@@ -47,17 +45,22 @@ public abstract class AbstractOMMetaFact
         return builder;
     }
 
-    public OMXMLParserWrapper createOMBuilder(OMFactory omFactory, 
StAXParserConfiguration configuration, InputStream in) {
-        try {
-            return createStAXOMBuilder(omFactory, 
StAXUtils.createXMLStreamReader(configuration, in));
-        } catch (XMLStreamException ex) {
-            throw new OMException(ex);
-        }
-    }
-
-    public OMXMLParserWrapper createOMBuilder(OMFactory omFactory, 
StAXParserConfiguration configuration, Reader in) {
+    public OMXMLParserWrapper createOMBuilder(OMFactory omFactory, 
StAXParserConfiguration configuration, InputSource is) {
         try {
-            return createStAXOMBuilder(omFactory, 
StAXUtils.createXMLStreamReader(configuration, in));
+            XMLStreamReader reader;
+            if (is.getByteStream() != null) {
+                String encoding = is.getEncoding();
+                if (encoding == null) {
+                    reader = StAXUtils.createXMLStreamReader(configuration, 
is.getByteStream());
+                } else {
+                    reader = StAXUtils.createXMLStreamReader(configuration, 
is.getByteStream(), encoding);
+                }
+            } else if (is.getCharacterStream() != null) {
+                reader = StAXUtils.createXMLStreamReader(configuration, 
is.getCharacterStream());
+            } else {
+                throw new IllegalArgumentException();
+            }
+            return createStAXOMBuilder(omFactory, reader);
         } catch (XMLStreamException ex) {
             throw new OMException(ex);
         }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeToOutputStream.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeToOutputStream.java?rev=1060962&r1=1060961&r2=1060962&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeToOutputStream.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeToOutputStream.java
 Wed Jan 19 20:20:42 2011
@@ -29,6 +29,7 @@ import javax.xml.transform.stream.Stream
 
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.ts.ConformanceTestCase;
@@ -60,7 +61,7 @@ public class TestSerializeToOutputStream
         }
         in = getFileAsStream();
         try {
-            OMXMLParserWrapper builder = 
metaFactory.createOMBuilder(metaFactory.getOMFactory(),
+            OMXMLParserWrapper builder = 
OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(),
                     StAXParserConfiguration.PRESERVE_CDATA_SECTIONS, in);
             try {
                 OMElement element = builder.getDocumentElement();


Reply via email to