sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1784764 - /sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
Date Tue, 28 Feb 2017 15:40:48 GMT
Author: desruisseaux
Date: Tue Feb 28 15:40:48 2017
New Revision: 1784764

URL: http://svn.apache.org/viewvc?rev=1784764&view=rev
Log:
Workaround for default JAXB implementation not recognizing STAX result.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java?rev=1784764&r1=1784763&r2=1784764&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java [UTF-8] Tue
Feb 28 15:40:48 2017
@@ -37,7 +37,9 @@ import javax.xml.bind.JAXBException;
 import javax.xml.transform.Source;
 import javax.xml.transform.Result;
 import javax.xml.transform.stax.StAXSource;
+import javax.xml.transform.stax.StAXResult;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
 import org.apache.sis.util.Static;
 import org.apache.sis.util.Version;
 import org.apache.sis.util.Workaround;
@@ -453,7 +455,21 @@ public final class XML extends Static {
                 marshaller.setProperty(entry.getKey(), entry.getValue());
             }
         }
-        marshaller.marshal(object, output);
+        /*
+         * STAX results are not handled by JAXB as of JDK 8. We have to handle those cases
ourselves.
+         * This workaround should be removed if a future JDK version handles those cases.
+         */
+        if (output instanceof StAXResult) {
+            @Workaround(library = "JDK", version = "1.8")
+            final XMLStreamWriter writer = ((StAXResult) output).getXMLStreamWriter();
+            if (writer != null) {
+                marshaller.marshal(object, writer);
+            } else {
+                marshaller.marshal(object, ((StAXResult) output).getXMLEventWriter());
+            }
+        } else {
+            marshaller.marshal(object, output);
+        }
         pool.recycle(marshaller);
     }
 



Mime
View raw message