Author: veithen
Date: Thu Jul 30 22:41:00 2009
New Revision: 799465

URL: http://svn.apache.org/viewvc?rev=799465&view=rev
Log:
Improved the detection of the Sun StAX implementation in Java 1.6.

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java?rev=799465&r1=799464&r2=799465&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java
 Thu Jul 30 22:41:00 2009
@@ -168,6 +168,27 @@
         return dialect;
     }
     
+    /**
+     * Check that a given class is part of the bootstrap classes. This method 
is used to detect
+     * different JRE flavors and to check which StAX implementation is part of 
the JRE.
+     * <p>
+     * Note: We look for a well defined class instead of just checking the 
package name of the class
+     * passed to {...@link #getDialect(Class)} because on some JREs, the 
implementations of the StAX
+     * interfaces (factories, readers and writers) are not in the same package.
+     * 
+     * @param className
+     *            the class name
+     * @return <code>true</code> if the class can be loaded from the bootstrap 
class loader
+     */
+    private static boolean isBootstrapClass(String className) {
+        try {
+            Class cls = 
ClassLoader.getSystemClassLoader().loadClass(className);
+            return cls.getClassLoader() == null;
+        } catch (ClassNotFoundException ex) {
+            return false;
+        }
+    }
+    
     private static StAXDialect detectDialectFromJRE() {
         String vendor = System.getProperty("java.vendor");
         String version = System.getProperty("java.version");
@@ -176,7 +197,7 @@
                     "  Vendor:  " + vendor + "\n" +
                     "  Version: " + version);
         }
-        if (vendor.startsWith("Sun") || vendor.startsWith("Apple")) {
+        if 
(isBootstrapClass("com.sun.xml.internal.stream.XMLInputFactoryImpl")) {
             return SJSXPDialect.INSTANCE;
         } else {
             log.warn("Unable to determine dialect of StAX implementation 
provided by the JRE");


Reply via email to