Add comments about how DatatypeFactory initialization happens.

Correct pathSeparator to fileSeparator.
Put code in requirements order.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/6256efa6
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/6256efa6
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/6256efa6

Branch: refs/heads/master
Commit: 6256efa6c77f881aa27b3992a609c6f505a8e4fb
Parents: f277e50
Author: Andy Seaborne <[email protected]>
Authored: Mon Jan 30 16:38:54 2017 +0000
Committer: Andy Seaborne <[email protected]>
Committed: Wed Feb 8 09:36:15 2017 +0000

----------------------------------------------------------------------
 .../org/apache/jena/sparql/expr/NodeValue.java  | 21 +++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/6256efa6/jena-arq/src/main/java/org/apache/jena/sparql/expr/NodeValue.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/NodeValue.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/expr/NodeValue.java
index 8b0c143..c2b727e 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/NodeValue.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/NodeValue.java
@@ -162,16 +162,12 @@ public abstract class NodeValue extends ExprNode
      */
     private static DatatypeFactory getDatatypeFactory() 
             throws DatatypeConfigurationException {
-        ClassLoader cl = NodeValue.class.getClassLoader();
-        File jaxpPropFile = new File(
-            System.getProperty("java.home") + File.pathSeparator + 
-            "lib" + File.pathSeparator + 
-            "jaxp.properties");
-        
         // Step 1. Try the system property
         String dtfClass = 
System.getProperty(DatatypeFactory.DATATYPEFACTORY_PROPERTY);
         
         try {
+            File jaxpPropFile = new File(System.getProperty("java.home") + 
+                                         File.separator + "lib" + 
File.separator + "jaxp.properties");
             // Step 2. Otherwise, try property in jaxp.properties
             if (dtfClass == null && jaxpPropFile.exists() && 
jaxpPropFile.canRead()) {
                 Properties jaxp = new Properties();
@@ -189,15 +185,22 @@ public abstract class NodeValue extends ExprNode
         }
         
         // Step 3. Otherwise try the service approach
+        // This is the normal initialization path, getting it from the Apach 
Xerces dependency
+        // and loading org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl
         if (dtfClass == null) {
+            ClassLoader cl = NodeValue.class.getClassLoader();
             Iterator<DatatypeFactory> factoryIterator = 
                 ServiceLoader.load(DatatypeFactory.class, cl).iterator();
             if (factoryIterator.hasNext()) return factoryIterator.next();
         }
         
-        // Step 4. Use the default
-        if (dtfClass == null) dtfClass = 
DatatypeFactory.DATATYPEFACTORY_IMPLEMENTATION_CLASS;
-        
+        // Step 4. Use the default.
+        // Note: When Apache Xerces is on the classpath for Jena, 
javax.xml.datatype.DatatypeFactory is from that jar and
+        //  DATATYPEFACTORY_IMPLEMENTATION_CLASS is 
"org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl"
+        // Without an explicit Xerces, we would get 
"com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl"
+        // from the JDK rt.jar version of javax.xml.datatype.DatatypeFactory.
+        if (dtfClass == null) 
+            dtfClass = DatatypeFactory.DATATYPEFACTORY_IMPLEMENTATION_CLASS;
         return DatatypeFactory.newInstance(dtfClass, 
NodeValue.class.getClassLoader()) ;
     }
     

Reply via email to