Log Message
Add StandardStaxDriver instead of SjsxpStaxDriver.
Modified Paths
- trunk/xstream/src/java/com/thoughtworks/xstream/core/JVM.java
- trunk/xstream/src/java/com/thoughtworks/xstream/io/xml/SjsxpDriver.java
- trunk/xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java
- trunk/xstream-distribution/src/content/changes.html
Added Paths
Diff
Modified: trunk/xstream/src/java/com/thoughtworks/xstream/core/JVM.java (2101 => 2102)
--- trunk/xstream/src/java/com/thoughtworks/xstream/core/JVM.java 2013-07-20 14:36:38 UTC (rev 2101)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/core/JVM.java 2013-07-20 15:15:43 UTC (rev 2102)
@@ -38,7 +38,6 @@
private static final boolean isAWTAvailable;
private static final boolean isSwingAvailable;
private static final boolean isSQLAvailable;
- private static final boolean isSunStAXAvailable;
private static final boolean canAllocateWithUnsafe;
private static final boolean optimizedTreeSetAddAll;
private static final boolean optimizedTreeMapPutAll;
@@ -106,7 +105,6 @@
isAWTAvailable = loadClassForName("java.awt.Color", false) != null;
isSwingAvailable = loadClassForName("javax.swing.LookAndFeel", false) != null;
isSQLAvailable = loadClassForName("java.sql.Date") != null;
- isSunStAXAvailable = loadClassForName("com.sun.xml.internal.stream.XMLInputFactoryImpl") != null;
Class type = null;
if (canUseSun14ReflectionProvider()) {
@@ -260,6 +258,56 @@
}
/**
+ * Get the XMLInputFactory implementation used normally by the current Java runtime as
+ * standard.
+ * <p>
+ * In contrast to XMLInputFactory.newFactory() this method will ignore any implementations
+ * provided with the system property <em>javax.xml.stream.XMLInputFactory</em>,
+ * implementations configured in <em>lib/stax.properties</em> or registered with the Service
+ * API.
+ * </p>
+ *
+ * @return the XMLInputFactory implementation or null
+ * @throws ClassNotFoundException if the standard class cannot be found
+ * @since upcoming
+ */
+ public static Class getStaxInputFactory() throws ClassNotFoundException {
+ if (is16()) {
+ if (isIBM()) {
+ return Class.forName("com.ibm.xml.xlxp.api.stax.XMLInputFactoryImpl");
+ } else {
+ return Class.forName("com.sun.xml.internal.stream.XMLInputFactoryImpl");
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the XMLOutputFactory implementation used normally by the current Java runtime as
+ * standard.
+ * <p>
+ * In contrast to XMLOutputFactory.newFactory() this method will ignore any implementations
+ * provided with the system property <em>javax.xml.stream.XMLOutputFactory</em>,
+ * implementations configured in <em>lib/stax.properties</em> or registered with the Service
+ * API.
+ * </p>
+ *
+ * @return the XMLOutputFactory implementation or null
+ * @throws ClassNotFoundException if the standard class cannot be found
+ * @since upcoming
+ */
+ public static Class getStaxOutputFactory() throws ClassNotFoundException {
+ if (is16()) {
+ if (isIBM()) {
+ return Class.forName("com.ibm.xml.xlxp.api.stax.XMLOutputFactoryImpl");
+ } else {
+ return Class.forName("com.sun.xml.internal.stream.XMLOutputFactoryImpl");
+ }
+ }
+ return null;
+ }
+
+ /**
* @deprecated As of upcoming use {@link #newReflectionProvider()}
*/
public synchronized ReflectionProvider bestReflectionProvider() {
@@ -347,15 +395,6 @@
}
/**
- * Checks if the jvm supports StAX implementation by Sun.
- *
- * @since upcoming
- */
- public static boolean isSunStAXAvilable() {
- return isSunStAXAvailable;
- }
-
- /**
* Checks if TreeSet.addAll is optimized for SortedSet argument.
*
* @since 1.4
@@ -402,6 +441,22 @@
}
}
+ String staxInputFactory = null;
+ try {
+ staxInputFactory = getStaxInputFactory().getName();
+ } catch (ClassNotFoundException e) {
+ staxInputFactory = e.getMessage();
+ } catch (NullPointerException e) {
+ }
+
+ String staxOutputFactory = null;
+ try {
+ staxOutputFactory = getStaxOutputFactory().getName();
+ } catch (ClassNotFoundException e) {
+ staxOutputFactory = e.getMessage();
+ } catch (NullPointerException e) {
+ }
+
System.out.println("XStream JVM diagnostics");
System.out.println("java.specification.version: " + System.getProperty("java.specification.version"));
System.out.println("java.specification.vendor: " + System.getProperty("java.specification.vendor"));
@@ -413,7 +468,9 @@
System.out.println("XStream support for enhanced Mode: " + canUseSun14ReflectionProvider());
System.out.println("Supports AWT: " + isAWTAvailable());
System.out.println("Supports Swing: " + isSwingAvailable());
- System.out.println("Supports SQL: " + isSunStAXAvilable());
+ System.out.println("Supports SQL: " + isSQLAvailable());
+ System.out.println("Standard StAX XMLInputFactory: " + staxInputFactory);
+ System.out.println("Standard StAX XMLOutputFactory: " + staxOutputFactory);
System.out.println("Optimized TreeSet.addAll: " + hasOptimizedTreeSetAddAll());
System.out.println("Optimized TreeMap.putAll: " + hasOptimizedTreeMapPutAll());
System.out.println("Can parse UTC date format: " + canParseUTCDateFormat());
Modified: trunk/xstream/src/java/com/thoughtworks/xstream/io/xml/SjsxpDriver.java (2101 => 2102)
--- trunk/xstream/src/java/com/thoughtworks/xstream/io/xml/SjsxpDriver.java 2013-07-20 14:36:38 UTC (rev 2101)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/io/xml/SjsxpDriver.java 2013-07-20 15:15:43 UTC (rev 2102)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009, 2011 XStream Committers.
+ * Copyright (C) 2009, 2011, 2013 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
@@ -20,25 +20,41 @@
*
* @author Jörg Schaible
* @since 1.4
+ * @deprecated As of upcoming use {@link StandardStaxDriver}
*/
public class SjsxpDriver extends StaxDriver {
+ /**
+ * @deprecated As of upcoming use {@link StandardStaxDriver#StandardStaxDriver()}
+ */
public SjsxpDriver() {
super();
}
+ /**
+ * @deprecated As of upcoming use {@link StandardStaxDriver#StandardStaxDriver(QNameMap, XmlFriendlyNameCoder)}
+ */
public SjsxpDriver(QNameMap qnameMap, XmlFriendlyNameCoder nameCoder) {
super(qnameMap, nameCoder);
}
+ /**
+ * @deprecated As of upcoming use {@link StandardStaxDriver#StandardStaxDriver(QNameMap)}
+ */
public SjsxpDriver(QNameMap qnameMap) {
super(qnameMap);
}
+ /**
+ * @deprecated As of upcoming use {@link StandardStaxDriver#StandardStaxDriver(XmlFriendlyNameCoder)}
+ */
public SjsxpDriver(XmlFriendlyNameCoder nameCoder) {
super(nameCoder);
}
+ /**
+ * @deprecated As of upcoming use {@link StandardStaxDriver#createInputFactory()}
+ */
protected XMLInputFactory createInputFactory() {
Exception exception = null;
try {
@@ -53,6 +69,9 @@
throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLInputFaqctory instance.", exception);
}
+ /**
+ * @deprecated As of upcoming use {@link StandardStaxDriver#createOutputFactory()}
+ */
protected XMLOutputFactory createOutputFactory() {
Exception exception = null;
try {
Added: trunk/xstream/src/java/com/thoughtworks/xstream/io/xml/StandardStaxDriver.java (0 => 2102)
--- trunk/xstream/src/java/com/thoughtworks/xstream/io/xml/StandardStaxDriver.java (rev 0)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/io/xml/StandardStaxDriver.java 2013-07-20 15:15:43 UTC (rev 2102)
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2013 XStream Committers.
+ * All rights reserved.
+ *
+ * The software in this package is published under the terms of the BSD
+ * style license a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ *
+ * Created on 27. July 2013 by Joerg Schaible
+ */
+package com.thoughtworks.xstream.io.xml;
+
+import com.thoughtworks.xstream.core.JVM;
+import com.thoughtworks.xstream.io.StreamException;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+
+/**
+ * A driver using the standard JDK StAX implementation provided by the Java runtime (since Java
+ * 6).
+ * <p>
+ * In contrast to XMLInputFactory.newFactory() or XMLOutputFactory.newFactory() this
+ * implementation will ignore any implementations provided with the system properties
+ * <em>javax.xml.stream.XMLInputFactory</em> and <em>javax.xml.stream.XMLOutputFactory</em>, all
+ * implementations configured in <em>lib/stax.properties</em> or registered with the Service
+ * API.
+ * </p>
+ *
+ * @author Jörg Schaible
+ * @since upcoming
+ */
+public class StandardStaxDriver extends StaxDriver {
+
+ public StandardStaxDriver() {
+ super();
+ }
+
+ public StandardStaxDriver(QNameMap qnameMap, XmlFriendlyNameCoder nameCoder) {
+ super(qnameMap, nameCoder);
+ }
+
+ public StandardStaxDriver(QNameMap qnameMap) {
+ super(qnameMap);
+ }
+
+ public StandardStaxDriver(XmlFriendlyNameCoder nameCoder) {
+ super(nameCoder);
+ }
+
+ protected XMLInputFactory createInputFactory() {
+ Exception exception = null;
+ try {
+ Class staxInputFactory = JVM.getStaxInputFactory();
+ if (staxInputFactory != null) {
+ return (XMLInputFactory)staxInputFactory.newInstance();
+ } else {
+ throw new StreamException("Java runtime has no standard XMLInputFactory implementation.", exception);
+ }
+ } catch (InstantiationException e) {
+ exception = e;
+ } catch (IllegalAccessException e) {
+ exception = e;
+ } catch (ClassNotFoundException e) {
+ exception = e;
+ }
+ throw new StreamException("Cannot create standard XMLInputFactory instance of Java runtime.", exception);
+ }
+
+ protected XMLOutputFactory createOutputFactory() {
+ Exception exception = null;
+ try {
+ Class staxOutputFactory = JVM.getStaxOutputFactory();
+ if (staxOutputFactory != null) {
+ return (XMLOutputFactory)staxOutputFactory.newInstance();
+ } else {
+ throw new StreamException("Java runtime has no standard XMLOutputFactory implementation.", exception);
+ }
+ } catch (InstantiationException e) {
+ exception = e;
+ } catch (IllegalAccessException e) {
+ exception = e;
+ } catch (ClassNotFoundException e) {
+ exception = e;
+ }
+ throw new StreamException("Cannot create standard XMLOutputFactory instance of Java runtime.", exception);
+ }
+
+}
Property changes on: trunk/xstream/src/java/com/thoughtworks/xstream/io/xml/StandardStaxDriver.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: trunk/xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java (2101 => 2102)
--- trunk/xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java 2013-07-20 14:36:38 UTC (rev 2101)
+++ trunk/xstream/src/test/com/thoughtworks/xstream/io/DriverEndToEndTestSuite.java 2013-07-20 15:15:43 UTC (rev 2102)
@@ -55,8 +55,7 @@
addDriverTest(new DomDriver());
addDriverTest(new JDomDriver());
if (JVM.is15()) {
- JVM jvm = new JVM();
- Class driverType = jvm.loadClassForName("com.thoughtworks.xstream.io.xml.JDom2Driver");
+ Class driverType = JVM.loadClassForName("com.thoughtworks.xstream.io.xml.JDom2Driver");
try {
addDriverTest((HierarchicalStreamDriver)driverType.newInstance());
} catch (InstantiationException e) {
@@ -69,15 +68,13 @@
addDriverTest(new KXml2Driver());
addDriverTest(new StaxDriver());
if (JVM.is16()) {
- if (JVM.isSunStAXAvilable()) {
- Class driverType = JVM.loadClassForName("com.thoughtworks.xstream.io.xml.SjsxpDriver");
- try {
- addDriverTest((HierarchicalStreamDriver)driverType.newInstance());
- } catch (InstantiationException e) {
- throw new AssertionFailedError("Cannot instantiate " + driverType.getName());
- } catch (IllegalAccessException e) {
- throw new AssertionFailedError("Cannot access default constructor of " + driverType.getName());
- }
+ Class driverType = JVM.loadClassForName("com.thoughtworks.xstream.io.xml.StandardStaxDriver");
+ try {
+ addDriverTest((HierarchicalStreamDriver)driverType.newInstance());
+ } catch (InstantiationException e) {
+ throw new AssertionFailedError("Cannot instantiate " + driverType.getName());
+ } catch (IllegalAccessException e) {
+ throw new AssertionFailedError("Cannot access default constructor of " + driverType.getName());
}
}
addDriverTest(new WstxDriver());
Modified: trunk/xstream-distribution/src/content/changes.html (2101 => 2102)
--- trunk/xstream-distribution/src/content/changes.html 2013-07-20 14:36:38 UTC (rev 2101)
+++ trunk/xstream-distribution/src/content/changes.html 2013-07-20 15:15:43 UTC (rev 2102)
@@ -84,6 +84,11 @@
<h2>API changes</h2>
<ul>
+ <li>Added c.t.x.io.xml.StandardStaxDriver to use the StAX implementation delivered with the Java 6 runtime.</li>
+ <li>Deprecated c.t.x.io.xml.SjsxpStaxDriver to select the internal StAX implementation of Oracle.</li>
+ <li>Added static methods getStaxInputFactory and getStaxOutputFactory to c.t.x.core.JVM as returning the
+ implementations of javax.xml.stream.XMLInputFactory (resp. javax.xml.stream.XMLOutputFactory) delivered with
+ the Java Runtime since Java 6.</li>
<li>Added c.t.x.core.ClassLoaderReference.</li>
<li>Added constructors taking a ClassLoaderReference instead of a ClassLoader and deprecated the ones taking the ClassLoader:
<ul>
To unsubscribe from this list please visit:
