8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations
authordfuchs
Tue, 29 Nov 2016 13:19:23 +0000
changeset 42390 4083bc2c3b5b
parent 42389 95883d86a743
child 42392 f1d47e36de0c
8169778: Add new public methods to get new instances of the JAXP factories builtin system-default implementations Summary: A new public static method is added to each of the JAXP factories. The new method will create and return a new instance of the system-default builtin implementation, without going through the lookup process. Reviewed-by: rriggs, joehw, lancea, alanb
jaxp/src/java.xml/share/classes/javax/xml/datatype/DatatypeFactory.java
jaxp/src/java.xml/share/classes/javax/xml/parsers/DocumentBuilderFactory.java
jaxp/src/java.xml/share/classes/javax/xml/parsers/SAXParserFactory.java
jaxp/src/java.xml/share/classes/javax/xml/stream/XMLEventFactory.java
jaxp/src/java.xml/share/classes/javax/xml/stream/XMLInputFactory.java
jaxp/src/java.xml/share/classes/javax/xml/stream/XMLOutputFactory.java
jaxp/src/java.xml/share/classes/javax/xml/transform/TransformerFactory.java
jaxp/src/java.xml/share/classes/javax/xml/validation/SchemaFactory.java
jaxp/src/java.xml/share/classes/javax/xml/xpath/XPathFactory.java
jaxp/test/javax/xml/jaxp/functional/javax/xml/datatype/ptests/FactoryNewInstanceTest.java
jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/DocumentBuilderFactoryTest.java
jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserFactTest.java
jaxp/test/javax/xml/jaxp/functional/javax/xml/stream/ptests/XMLEventFactoryNewInstanceTest.java
jaxp/test/javax/xml/jaxp/functional/javax/xml/stream/ptests/XMLInputFactoryNewInstanceTest.java
jaxp/test/javax/xml/jaxp/functional/javax/xml/stream/ptests/XMLOutputFactoryNewInstanceTest.java
jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerFactoryTest.java
jaxp/test/javax/xml/jaxp/functional/javax/xml/validation/ptests/SchemaFactoryTest.java
jaxp/test/javax/xml/jaxp/functional/javax/xml/xpath/ptests/XPathFactoryTest.java
--- a/jaxp/src/java.xml/share/classes/javax/xml/datatype/DatatypeFactory.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/javax/xml/datatype/DatatypeFactory.java	Tue Nov 29 13:19:23 2016 +0000
@@ -30,6 +30,7 @@
 import java.util.GregorianCalendar;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl;
 
 /**
  * Factory that creates new {@code javax.xml.datatype} {@code Object}s that map XML to/from Java {@code Object}s.
@@ -136,6 +137,20 @@
     }
 
     /**
+     * Creates a new instance of the {@code DatatypeFactory} {@linkplain
+     * #DATATYPEFACTORY_IMPLEMENTATION_CLASS builtin system-default
+     * implementation}.
+     *
+     * @return A new instance of the {@code DatatypeFactory} builtin
+     *         system-default implementation.
+     *
+     * @since 9
+     */
+    public static DatatypeFactory newDefaultInstance() {
+        return new DatatypeFactoryImpl();
+    }
+
+    /**
      * Obtain a new instance of a {@code DatatypeFactory}.
      *
      * <p>The implementation resolution mechanisms are <a href="#DatatypeFactory.newInstance">defined</a> in this
--- a/jaxp/src/java.xml/share/classes/javax/xml/parsers/DocumentBuilderFactory.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/javax/xml/parsers/DocumentBuilderFactory.java	Tue Nov 29 13:19:23 2016 +0000
@@ -25,6 +25,7 @@
 
 package javax.xml.parsers;
 
+import com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl;
 import javax.xml.validation.Schema;
 
 /**
@@ -54,6 +55,19 @@
     }
 
     /**
+     * Creates a new instance of the {@code DocumentBuilderFactory} builtin
+     * system-default implementation.
+     *
+     * @return A new instance of the {@code DocumentBuilderFactory} builtin
+     *         system-default implementation.
+     *
+     * @since 9
+     */
+    public static DocumentBuilderFactory newDefaultInstance() {
+        return new DocumentBuilderFactoryImpl();
+    }
+
+    /**
      * Obtain a new instance of a
      * {@code DocumentBuilderFactory}. This static method creates
      * a new factory instance.
@@ -93,7 +107,8 @@
      * </li>
      * <li>
      * <p>
-     * Otherwise, the system-default implementation is returned.
+     * Otherwise, the {@linkplain #newDefaultInstance() system-default}
+     * implementation is returned.
      * </li>
      * </ul>
      *
--- a/jaxp/src/java.xml/share/classes/javax/xml/parsers/SAXParserFactory.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/javax/xml/parsers/SAXParserFactory.java	Tue Nov 29 13:19:23 2016 +0000
@@ -25,6 +25,7 @@
 
 package javax.xml.parsers;
 
+import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
 import javax.xml.validation.Schema;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXNotRecognizedException;
@@ -59,6 +60,19 @@
     }
 
     /**
+     * Creates a new instance of the {@code SAXParserFactory} builtin
+     * system-default implementation.
+     *
+     * @return A new instance of the {@code SAXParserFactory} builtin
+     *         system-default implementation.
+     *
+     * @since 9
+     */
+    public static SAXParserFactory newDefaultInstance() {
+        return new SAXParserFactoryImpl();
+    }
+
+    /**
      * Obtain a new instance of a {@code SAXParserFactory}. This
      * static method creates a new factory instance
      * This method uses the following ordered lookup procedure to determine
@@ -97,7 +111,8 @@
      * </li>
      * <li>
      * <p>
-     * Otherwise the system-default implementation is returned.
+     * Otherwise, the {@linkplain #newDefaultInstance() system-default}
+     * implementation is returned.
      * </li>
      * </ul>
      *
--- a/jaxp/src/java.xml/share/classes/javax/xml/stream/XMLEventFactory.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/javax/xml/stream/XMLEventFactory.java	Tue Nov 29 13:19:23 2016 +0000
@@ -27,6 +27,7 @@
  */
 
 package javax.xml.stream;
+import com.sun.xml.internal.stream.events.XMLEventFactoryImpl;
 import java.util.Iterator;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
@@ -54,6 +55,19 @@
 
 
   /**
+   * Creates a new instance of the {@code XMLEventFactory} builtin
+   * system-default implementation.
+   *
+   * @return A new instance of the {@code XMLEventFactory} builtin
+   *         system-default implementation.
+   *
+   * @since 9
+   */
+  public static XMLEventFactory newDefaultFactory() {
+      return new XMLEventFactoryImpl();
+  }
+
+  /**
    * Creates a new instance of the factory in exactly the same manner as the
    * {@link #newFactory()} method.
    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
@@ -108,7 +122,8 @@
    * </li>
    * <li>
    *   <p>
-   *   Otherwise, the system-default implementation is returned.
+   *   Otherwise, the {@linkplain #newDefaultFactory() system-default}
+   *   implementation is returned.
    * </li>
    * </ul>
    * <p>
--- a/jaxp/src/java.xml/share/classes/javax/xml/stream/XMLInputFactory.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/javax/xml/stream/XMLInputFactory.java	Tue Nov 29 13:19:23 2016 +0000
@@ -28,6 +28,7 @@
 
 package javax.xml.stream;
 
+import com.sun.xml.internal.stream.XMLInputFactoryImpl;
 import javax.xml.stream.util.XMLEventAllocator;
 import javax.xml.transform.Source;
 
@@ -144,6 +145,19 @@
   protected XMLInputFactory(){}
 
   /**
+   * Creates a new instance of the {@code XMLInputFactory} builtin
+   * system-default implementation.
+   *
+   * @return A new instance of the {@code XMLInputFactory} builtin
+   *         system-default implementation.
+   *
+   * @since 9
+   */
+  public static XMLInputFactory newDefaultFactory() {
+      return new XMLInputFactoryImpl();
+  }
+
+  /**
    * Creates a new instance of the factory in exactly the same manner as the
    * {@link #newFactory()} method.
    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
@@ -195,7 +209,8 @@
    *   ClassLoader#getSystemClassLoader() system class loader} will be used.
    * </li>
    * <li>
-   * <p>Otherwise, the system-default implementation is returned.
+   * <p>Otherwise, the {@linkplain #newDefaultFactory() system-default}
+   *    implementation is returned.
    * </li>
    * </ul>
    * <p>
--- a/jaxp/src/java.xml/share/classes/javax/xml/stream/XMLOutputFactory.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/javax/xml/stream/XMLOutputFactory.java	Tue Nov 29 13:19:23 2016 +0000
@@ -28,6 +28,7 @@
 
 package javax.xml.stream;
 
+import com.sun.xml.internal.stream.XMLOutputFactoryImpl;
 import javax.xml.transform.Result;
 
 /**
@@ -121,6 +122,19 @@
   protected XMLOutputFactory(){}
 
   /**
+   * Creates a new instance of the {@code XMLOutputFactory} builtin
+   * system-default implementation.
+   *
+   * @return A new instance of the {@code XMLOutputFactory} builtin
+   *         system-default implementation.
+   *
+   * @since 9
+   */
+  public static XMLOutputFactory newDefaultFactory() {
+      return new XMLOutputFactoryImpl();
+  }
+
+  /**
    * Creates a new instance of the factory in exactly the same manner as the
    * {@link #newFactory()} method.
    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
@@ -175,7 +189,8 @@
    * </li>
    * <li>
    *   <p>
-   *   Otherwise, the system-default implementation is returned.
+   *   Otherwise, the {@linkplain #newDefaultFactory() system-default}
+   *   implementation is returned.
    * </li>
    * </ul>
    * <p>
--- a/jaxp/src/java.xml/share/classes/javax/xml/transform/TransformerFactory.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/javax/xml/transform/TransformerFactory.java	Tue Nov 29 13:19:23 2016 +0000
@@ -25,6 +25,8 @@
 
 package javax.xml.transform;
 
+import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
+
 /**
  * <p>A TransformerFactory instance can be used to create
  * {@link javax.xml.transform.Transformer} and
@@ -51,6 +53,19 @@
 
 
     /**
+     * Creates a new instance of the {@code TransformerFactory} builtin
+     * system-default implementation.
+     *
+     * @return A new instance of the {@code TransformerFactory} builtin
+     *         system-default implementation.
+     *
+     * @since 9
+     */
+    public static TransformerFactory newDefaultInstance() {
+        return TransformerFactoryImpl.newTransformerFactoryNoServiceLoader();
+    }
+
+    /**
      * Obtain a new instance of a {@code TransformerFactory}.
      * This static method creates a new factory instance.
      * <p>
@@ -89,7 +104,8 @@
      * </li>
      * <li>
      * <p>
-     *   Otherwise, the system-default implementation is returned.
+     *   Otherwise, the {@linkplain #newDefaultInstance() system-default}
+     *   implementation is returned.
      * </li>
      * </ul>
      *
--- a/jaxp/src/java.xml/share/classes/javax/xml/validation/SchemaFactory.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/javax/xml/validation/SchemaFactory.java	Tue Nov 29 13:19:23 2016 +0000
@@ -25,6 +25,7 @@
 
 package javax.xml.validation;
 
+import com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory;
 import java.io.File;
 import java.net.URL;
 import javax.xml.transform.Source;
@@ -124,6 +125,24 @@
     }
 
     /**
+     * Creates a new instance of the {@code SchemaFactory} builtin
+     * system-default implementation.
+     *
+     * @implSpec The {@code SchemaFactory} builtin
+     * system-default implementation is only required to support the
+     * <a href="http://www.w3.org/TR/xmlschema-1">W3C XML Schema 1.0</a>,
+     * but may support additional <a href="#schemaLanguage">schema languages</a>.
+     *
+     * @return A new instance of the {@code SchemaFactory} builtin
+     *         system-default implementation.
+     *
+     * @since 9
+     */
+    public static SchemaFactory newDefaultInstance() {
+        return XMLSchemaFactory.newXMLSchemaFactoryNoServiceLoader();
+    }
+
+    /**
      * Lookup an implementation of the {@code SchemaFactory} that supports the specified
      * schema language and return it.
      *
@@ -179,7 +198,8 @@
      *   <li>
      *     <p>
      *     Platform default {@code SchemaFactory} is located
-     *     in a implementation specific way. There must be a platform default
+     *     in an implementation specific way. There must be a
+     *     {@linkplain #newDefaultInstance() platform default}
      *     {@code SchemaFactory} for W3C XML Schema.
      *   </li>
      * </ol>
--- a/jaxp/src/java.xml/share/classes/javax/xml/xpath/XPathFactory.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/javax/xml/xpath/XPathFactory.java	Tue Nov 29 13:19:23 2016 +0000
@@ -25,6 +25,8 @@
 
 package javax.xml.xpath;
 
+import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl;
+
 /**
  * <p>An {@code XPathFactory} instance can be used to create
  * {@link javax.xml.xpath.XPath} objects.</p>
@@ -74,6 +76,25 @@
     }
 
     /**
+     * Creates a new instance of the {@code XPathFactory} builtin
+     * system-default implementation.
+     *
+     * @implSpec The {@code XPathFactory} builtin
+     * system-default implementation is only required to support the
+     * {@link #DEFAULT_OBJECT_MODEL_URI default object model}, the
+     * {@linkplain org.w3c.dom W3C DOM}, but may support additional
+     * object models.
+     *
+     * @return A new instance of the {@code XPathFactory} builtin
+     *         system-default implementation.
+     *
+     * @since 9
+     */
+    public static XPathFactory newDefaultInstance() {
+        return XPathFactoryImpl.newXPathFactoryNoServiceLoader();
+    }
+
+    /**
      * <p>Get a new {@code XPathFactory} instance using the default object model,
      * {@link #DEFAULT_OBJECT_MODEL_URI},
      * the W3C DOM.</p>
@@ -153,8 +174,11 @@
     *   </li>
     *   <li>
     *     <p>
-    *     Platform default {@code XPathFactory} is located in a platform specific way.
-    *     There must be a platform default XPathFactory for the W3C DOM, i.e. {@link #DEFAULT_OBJECT_MODEL_URI}.
+    *     Platform default {@code XPathFactory} is located in a platform
+    *     specific way.
+    *     There must be a {@linkplain #newDefaultInstance() platform default}
+    *     {@code XPathFactory} for the W3C DOM, i.e.
+    *     {@link #DEFAULT_OBJECT_MODEL_URI}.
     *   </li>
     * </ol>
     * <p>If everything fails, an {@code XPathFactoryConfigurationException} will be thrown.
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/datatype/ptests/FactoryNewInstanceTest.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/datatype/ptests/FactoryNewInstanceTest.java	Tue Nov 29 13:19:23 2016 +0000
@@ -24,6 +24,9 @@
 package javax.xml.datatype.ptests;
 
 import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNotSame;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertEquals;
 
 import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.DatatypeFactory;
@@ -37,6 +40,7 @@
 
 /*
  * @test
+ * @bug 8169778
  * @library /javax/xml/jaxp/libs
  * @run testng/othervm -DrunSecMngr=true javax.xml.datatype.ptests.FactoryNewInstanceTest
  * @run testng/othervm javax.xml.datatype.ptests.FactoryNewInstanceTest
@@ -45,13 +49,30 @@
 @Listeners({jaxp.library.BasePolicy.class})
 public class FactoryNewInstanceTest {
 
-    private static final String DATATYPE_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl";
+    private static final String DEFAULT_IMPL_CLASS =
+        "com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl";
+    private static final String DATATYPE_FACTORY_CLASSNAME = DEFAULT_IMPL_CLASS;
 
     @DataProvider(name = "parameters")
     public Object[][] getValidateParameters() {
         return new Object[][] { { DATATYPE_FACTORY_CLASSNAME, null }, { DATATYPE_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
     }
 
+    /**
+     * Test if newDefaultInstance() method returns an instance
+     * of the expected factory.
+     * @throws Exception If any errors occur.
+     */
+    @Test
+    public void testDefaultInstance() throws Exception {
+        DatatypeFactory dtf1 = DatatypeFactory.newDefaultInstance();
+        DatatypeFactory dtf2 = DatatypeFactory.newInstance();
+        assertNotSame(dtf1, dtf2, "same instance returned:");
+        assertSame(dtf1.getClass(), dtf2.getClass(),
+                  "unexpected class mismatch for newDefaultInstance():");
+        assertEquals(dtf1.getClass().getName(), DEFAULT_IMPL_CLASS);
+    }
+
     /*
      * test for DatatypeFactory.newInstance(java.lang.String factoryClassName,
      * java.lang.ClassLoader classLoader) factoryClassName points to correct
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/DocumentBuilderFactoryTest.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/DocumentBuilderFactoryTest.java	Tue Nov 29 13:19:23 2016 +0000
@@ -34,6 +34,8 @@
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertNotSame;
 
 import java.io.BufferedReader;
 import java.io.Closeable;
@@ -66,7 +68,7 @@
 import org.xml.sax.helpers.DefaultHandler;
 
 /**
- * @bug 8080907
+ * @bug 8080907 8169778
  * This checks the methods of DocumentBuilderFactoryImpl.
  */
 /*
@@ -77,10 +79,17 @@
  */
 @Listeners({jaxp.library.FilePolicy.class})
 public class DocumentBuilderFactoryTest {
+
+    /**
+     * DocumentBuilderFactory builtin system-default implementation class name.
+     */
+    private static final String DEFAULT_IMPL_CLASS =
+        "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
+
     /**
      * DocumentBuilderFactory implementation class name.
      */
-    private static final String DOCUMENT_BUILDER_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
+    private static final String DOCUMENT_BUILDER_FACTORY_CLASSNAME = DEFAULT_IMPL_CLASS;
 
     /**
      * Provide valid DocumentBuilderFactory instantiation parameters.
@@ -93,6 +102,21 @@
     }
 
     /**
+     * Test if newDefaultInstance() method returns an instance
+     * of the expected factory.
+     * @throws Exception If any errors occur.
+     */
+    @Test
+    public void testDefaultInstance() throws Exception {
+        DocumentBuilderFactory dbf1 = DocumentBuilderFactory.newDefaultInstance();
+        DocumentBuilderFactory dbf2 = DocumentBuilderFactory.newInstance();
+        assertNotSame(dbf1, dbf2, "same instance returned:");
+        assertSame(dbf1.getClass(), dbf2.getClass(),
+                  "unexpected class mismatch for newDefaultInstance():");
+        assertEquals(dbf1.getClass().getName(), DEFAULT_IMPL_CLASS);
+    }
+
+    /**
      * Test for DocumentBuilderFactory.newInstance(java.lang.String
      * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
      * points to correct implementation of
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserFactTest.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserFactTest.java	Tue Nov 29 13:19:23 2016 +0000
@@ -24,6 +24,9 @@
 package javax.xml.parsers.ptests;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertNotSame;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertEquals;
 
 import javax.xml.parsers.SAXParserFactory;
 
@@ -35,6 +38,7 @@
  */
 /*
  * @test
+ * @bug 8169778
  * @library /javax/xml/jaxp/libs
  * @run testng/othervm -DrunSecMngr=true javax.xml.parsers.ptests.SAXParserFactTest
  * @run testng/othervm javax.xml.parsers.ptests.SAXParserFactTest
@@ -48,6 +52,23 @@
     private static final String VALIDATION = "http://xml.org/sax/features/validation";
     private static final String EXTERNAL_G_ENTITIES = "http://xml.org/sax/features/external-general-entities";
     private static final String EXTERNAL_P_ENTITIES = "http://xml.org/sax/features/external-parameter-entities";
+    private static final String DEFAULT_IMPL_CLASS =
+        "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl";
+
+    /**
+     * Test if newDefaultInstance() method returns an instance
+     * of the expected factory.
+     * @throws Exception If any errors occur.
+     */
+    @Test
+    public void testDefaultInstance() throws Exception {
+        SAXParserFactory spf1 = SAXParserFactory.newDefaultInstance();
+        SAXParserFactory spf2 = SAXParserFactory.newInstance();
+        assertNotSame(spf1, spf2, "same instance returned:");
+        assertSame(spf1.getClass(), spf2.getClass(),
+                  "unexpected class mismatch for newDefaultInstance():");
+        assertEquals(spf1.getClass().getName(), DEFAULT_IMPL_CLASS);
+    }
 
     /**
      * Test if newSAXParser() method returns SAXParser.
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/stream/ptests/XMLEventFactoryNewInstanceTest.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/stream/ptests/XMLEventFactoryNewInstanceTest.java	Tue Nov 29 13:19:23 2016 +0000
@@ -27,6 +27,9 @@
 import static jaxp.library.JAXPTestUtilities.clearSystemProperty;
 
 import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNotSame;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertEquals;
 
 import javax.xml.stream.XMLEventFactory;
 
@@ -38,6 +41,7 @@
 
 /*
  * @test
+ * @bug 8169778
  * @library /javax/xml/jaxp/libs
  * @run testng/othervm -DrunSecMngr=true javax.xml.stream.ptests.XMLEventFactoryNewInstanceTest
  * @run testng/othervm javax.xml.stream.ptests.XMLEventFactoryNewInstanceTest
@@ -46,12 +50,31 @@
 @Listeners({jaxp.library.BasePolicy.class})
 public class XMLEventFactoryNewInstanceTest {
 
-    private static final String XMLEVENT_FACTORY_CLASSNAME = "com.sun.xml.internal.stream.events.XMLEventFactoryImpl";
-    private static final String XMLEVENT_FACRORY_ID = "javax.xml.stream.XMLEventFactory";
+    private static final String DEFAULT_IMPL_CLASS =
+        "com.sun.xml.internal.stream.events.XMLEventFactoryImpl";
+    private static final String XMLEVENT_FACTORY_CLASSNAME = DEFAULT_IMPL_CLASS;
+    private static final String XMLEVENT_FACTORY_ID = "javax.xml.stream.XMLEventFactory";
 
     @DataProvider(name = "parameters")
     public Object[][] getValidateParameters() {
-        return new Object[][] { { XMLEVENT_FACRORY_ID, null }, { XMLEVENT_FACRORY_ID, this.getClass().getClassLoader() } };
+        return new Object[][] {
+            { XMLEVENT_FACTORY_ID, null },
+            { XMLEVENT_FACTORY_ID, this.getClass().getClassLoader() } };
+    }
+
+    /**
+     * Test if newDefaultFactory() method returns an instance
+     * of the expected factory.
+     * @throws Exception If any errors occur.
+     */
+    @Test
+    public void testDefaultInstance() throws Exception {
+        XMLEventFactory ef1 = XMLEventFactory.newDefaultFactory();
+        XMLEventFactory ef2 = XMLEventFactory.newFactory();
+        assertNotSame(ef1, ef2, "same instance returned:");
+        assertSame(ef1.getClass(), ef2.getClass(),
+                  "unexpected class mismatch for newDefaultFactory():");
+        assertEquals(ef1.getClass().getName(), DEFAULT_IMPL_CLASS);
     }
 
     /*
@@ -62,12 +85,12 @@
      */
     @Test(dataProvider = "parameters")
     public void testNewFactory(String factoryId, ClassLoader classLoader) {
-        setSystemProperty(XMLEVENT_FACRORY_ID, XMLEVENT_FACTORY_CLASSNAME);
+        setSystemProperty(XMLEVENT_FACTORY_ID, XMLEVENT_FACTORY_CLASSNAME);
         try {
             XMLEventFactory xef = XMLEventFactory.newFactory(factoryId, classLoader);
             assertNotNull(xef);
         } finally {
-            clearSystemProperty(XMLEVENT_FACRORY_ID);
+            clearSystemProperty(XMLEVENT_FACTORY_ID);
         }
     }
 
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/stream/ptests/XMLInputFactoryNewInstanceTest.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/stream/ptests/XMLInputFactoryNewInstanceTest.java	Tue Nov 29 13:19:23 2016 +0000
@@ -27,6 +27,9 @@
 import static jaxp.library.JAXPTestUtilities.clearSystemProperty;
 
 import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNotSame;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertEquals;
 
 import javax.xml.stream.XMLInputFactory;
 
@@ -38,6 +41,7 @@
 
 /*
  * @test
+ * @bug 8169778
  * @library /javax/xml/jaxp/libs
  * @run testng/othervm -DrunSecMngr=true javax.xml.stream.ptests.XMLInputFactoryNewInstanceTest
  * @run testng/othervm javax.xml.stream.ptests.XMLInputFactoryNewInstanceTest
@@ -46,12 +50,31 @@
 @Listeners({jaxp.library.BasePolicy.class})
 public class XMLInputFactoryNewInstanceTest {
 
-    private static final String XMLINPUT_FACTORY_CLASSNAME = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
-    private static final String XMLINPUT_FACRORY_ID = "javax.xml.stream.XMLInputFactory";
+    private static final String DEFAULT_IMPL_CLASS =
+        "com.sun.xml.internal.stream.XMLInputFactoryImpl";
+    private static final String XMLINPUT_FACTORY_CLASSNAME = DEFAULT_IMPL_CLASS;
+    private static final String XMLINPUT_FACTORY_ID = "javax.xml.stream.XMLInputFactory";
 
     @DataProvider(name = "parameters")
     public Object[][] getValidateParameters() {
-        return new Object[][] { { XMLINPUT_FACRORY_ID, null }, { XMLINPUT_FACRORY_ID, this.getClass().getClassLoader() } };
+        return new Object[][] {
+            { XMLINPUT_FACTORY_ID, null },
+            { XMLINPUT_FACTORY_ID, this.getClass().getClassLoader() } };
+    }
+
+    /**
+     * Test if newDefaultFactory() method returns an instance
+     * of the expected factory.
+     * @throws Exception If any errors occur.
+     */
+    @Test
+    public void testDefaultInstance() throws Exception {
+        XMLInputFactory if1 = XMLInputFactory.newDefaultFactory();
+        XMLInputFactory if2 = XMLInputFactory.newFactory();
+        assertNotSame(if1, if2, "same instance returned:");
+        assertSame(if1.getClass(), if2.getClass(),
+                  "unexpected class mismatch for newDefaultFactory():");
+        assertEquals(if1.getClass().getName(), DEFAULT_IMPL_CLASS);
     }
 
     /*
@@ -62,12 +85,12 @@
      */
     @Test(dataProvider = "parameters")
     public void testNewFactory(String factoryId, ClassLoader classLoader) {
-        setSystemProperty(XMLINPUT_FACRORY_ID, XMLINPUT_FACTORY_CLASSNAME);
+        setSystemProperty(XMLINPUT_FACTORY_ID, XMLINPUT_FACTORY_CLASSNAME);
         try {
             XMLInputFactory xif = XMLInputFactory.newFactory(factoryId, classLoader);
             assertNotNull(xif);
         } finally {
-            clearSystemProperty(XMLINPUT_FACRORY_ID);
+            clearSystemProperty(XMLINPUT_FACTORY_ID);
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/stream/ptests/XMLOutputFactoryNewInstanceTest.java	Tue Nov 29 13:19:23 2016 +0000
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.xml.stream.ptests;
+
+import static jaxp.library.JAXPTestUtilities.setSystemProperty;
+import static jaxp.library.JAXPTestUtilities.clearSystemProperty;
+
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNotSame;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertEquals;
+
+import javax.xml.stream.XMLOutputFactory;
+
+import jaxp.library.JAXPDataProvider;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Listeners;
+import org.testng.annotations.Test;
+
+/*
+ * @test
+ * @bug 8169778
+ * @library /javax/xml/jaxp/libs
+ * @run testng/othervm -DrunSecMngr=true javax.xml.stream.ptests.XMLOutputFactoryNewInstanceTest
+ * @run testng/othervm javax.xml.stream.ptests.XMLOutputFactoryNewInstanceTest
+ * @summary Tests for XMLOutputFactory.newFactory(factoryId , classLoader)
+ */
+@Listeners({jaxp.library.BasePolicy.class})
+public class XMLOutputFactoryNewInstanceTest {
+
+    private static final String DEFAULT_IMPL_CLASS =
+        "com.sun.xml.internal.stream.XMLOutputFactoryImpl";
+    private static final String XMLOUTPUT_FACTORY_CLASSNAME = DEFAULT_IMPL_CLASS;
+    private static final String XMLOUTPUT_FACTORY_ID = "javax.xml.stream.XMLOutputFactory";
+
+    @DataProvider(name = "parameters")
+    public Object[][] getValidateParameters() {
+        return new Object[][] {
+            { XMLOUTPUT_FACTORY_ID, null },
+            { XMLOUTPUT_FACTORY_ID, this.getClass().getClassLoader() } };
+    }
+
+    /**
+     * Test if newDefaultFactory() method returns an instance
+     * of the expected factory.
+     * @throws Exception If any errors occur.
+     */
+    @Test
+    public void testDefaultInstance() throws Exception {
+        XMLOutputFactory of1 = XMLOutputFactory.newDefaultFactory();
+        XMLOutputFactory of2 = XMLOutputFactory.newFactory();
+        assertNotSame(of1, of2, "same instance returned:");
+        assertSame(of1.getClass(), of2.getClass(),
+                  "unexpected class mismatch for newDefaultFactory():");
+        assertEquals(of1.getClass().getName(), DEFAULT_IMPL_CLASS);
+    }
+
+    /*
+     * test for XMLOutputFactory.newFactory(java.lang.String factoryId,
+     * java.lang.ClassLoader classLoader) factoryClassName points to correct
+     * implementation of javax.xml.stream.XMLOutputFactory , should return
+     * newInstance of XMLOutputFactory
+     */
+    @Test(dataProvider = "parameters")
+    public void testNewFactory(String factoryId, ClassLoader classLoader) {
+        setSystemProperty(XMLOUTPUT_FACTORY_ID, XMLOUTPUT_FACTORY_CLASSNAME);
+        try {
+            XMLOutputFactory xif = XMLOutputFactory.newFactory(factoryId, classLoader);
+            assertNotNull(xif);
+        } finally {
+            clearSystemProperty(XMLOUTPUT_FACTORY_ID);
+        }
+    }
+
+    /*
+     * test for XMLOutputFactory.newFactory(java.lang.String factoryClassName,
+     * java.lang.ClassLoader classLoader) factoryClassName is null , should
+     * throw NullPointerException
+     */
+    @Test(expectedExceptions = NullPointerException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
+    public void testNewFactoryNeg(String factoryId, ClassLoader classLoader) {
+        XMLOutputFactory.newFactory(factoryId, classLoader);
+    }
+
+}
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerFactoryTest.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerFactoryTest.java	Tue Nov 29 13:19:23 2016 +0000
@@ -28,6 +28,9 @@
 import static jaxp.library.JAXPTestUtilities.compareWithGold;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertNotSame;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertEquals;
 
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -55,6 +58,7 @@
  */
 /*
  * @test
+ * @bug 8169778
  * @library /javax/xml/jaxp/libs
  * @run testng/othervm -DrunSecMngr=true javax.xml.transform.ptests.TransformerFactoryTest
  * @run testng/othervm javax.xml.transform.ptests.TransformerFactoryTest
@@ -62,9 +66,15 @@
 @Listeners({jaxp.library.FilePolicy.class})
 public class TransformerFactoryTest {
     /**
+     * TransformerFactory builtin system-default implementation class name.
+     */
+    private static final String DEFAULT_IMPL_CLASS =
+       "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
+
+    /**
      * TransformerFactory implementation class name.
      */
-    private static final String TRANSFORMER_FACTORY_CLASSNAME = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
+    private static final String TRANSFORMER_FACTORY_CLASSNAME = DEFAULT_IMPL_CLASS;
 
     /**
      * Provide valid TransformerFactory instantiation parameters.
@@ -77,6 +87,21 @@
     }
 
     /**
+     * Test if newDefaultInstance() method returns an instance
+     * of the expected factory.
+     * @throws Exception If any errors occur.
+     */
+    @Test
+    public void testDefaultInstance() throws Exception {
+        TransformerFactory tf1 = TransformerFactory.newDefaultInstance();
+        TransformerFactory tf2 = TransformerFactory.newInstance();
+        assertNotSame(tf1, tf2, "same instance returned:");
+        assertSame(tf1.getClass(), tf2.getClass(),
+                  "unexpected class mismatch for newDefaultInstance():");
+        assertEquals(tf1.getClass().getName(), DEFAULT_IMPL_CLASS);
+    }
+
+    /**
      * Test for TransformerFactory.newInstance(java.lang.String
      * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
      * points to correct implementation of
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/validation/ptests/SchemaFactoryTest.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/validation/ptests/SchemaFactoryTest.java	Tue Nov 29 13:19:23 2016 +0000
@@ -28,6 +28,9 @@
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotSame;
+import static org.testng.Assert.assertEquals;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -66,7 +69,7 @@
 
 /*
  * @test
- * @bug 8080907
+ * @bug 8080907 8169778
  * @library /javax/xml/jaxp/libs
  * @run testng/othervm -DrunSecMngr=true javax.xml.validation.ptests.SchemaFactoryTest
  * @run testng/othervm javax.xml.validation.ptests.SchemaFactoryTest
@@ -102,6 +105,25 @@
                 { W3C_XML_SCHEMA_NS_URI, SCHEMA_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
     }
 
+    /**
+     * Test if newDefaultInstance() method returns an instance
+     * of the expected factory.
+     * @throws Exception If any errors occur.
+     */
+    @Test
+    public void testDefaultInstance() throws Exception {
+        SchemaFactory sf1 = SchemaFactory.newDefaultInstance();
+        SchemaFactory sf2 = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
+        assertNotSame(sf1, sf2, "same instance returned:");
+        assertSame(sf1.getClass(), sf2.getClass(),
+                  "unexpected class mismatch for newDefaultInstance():");
+        assertEquals(sf1.getClass().getName(), DEFAULT_IMPL_CLASS);
+        assertTrue(sf1.isSchemaLanguageSupported(W3C_XML_SCHEMA_NS_URI),
+                   "isSchemaLanguageSupported(W3C_XML_SCHEMA_NS_URI):");
+        assertFalse(sf1.isSchemaLanguageSupported(UNRECOGNIZED_NAME),
+                   "isSchemaLanguageSupported(UNRECOGNIZED_NAME):");
+    }
+
     /*
      * test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
      * java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
@@ -394,7 +416,10 @@
 
     private static final String UNRECOGNIZED_NAME = "http://xml.org/sax/features/namespace-prefixes";
 
-    private static final String SCHEMA_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory";
+    private static final String DEFAULT_IMPL_CLASS =
+        "com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory";
+
+    private static final String SCHEMA_FACTORY_CLASSNAME = DEFAULT_IMPL_CLASS;
 
     private SchemaFactory sf;
     private XMLInputFactory ifac;
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/xpath/ptests/XPathFactoryTest.java	Mon Nov 28 09:20:13 2016 +0100
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/xpath/ptests/XPathFactoryTest.java	Tue Nov 29 13:19:23 2016 +0000
@@ -24,7 +24,13 @@
 package javax.xml.xpath.ptests;
 
 import static javax.xml.xpath.XPathConstants.DOM_OBJECT_MODEL;
+import static javax.xml.xpath.XPathFactory.DEFAULT_OBJECT_MODEL_URI;
 import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNotSame;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertFalse;
 
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathFactory;
@@ -41,6 +47,7 @@
  */
 /*
  * @test
+ * @bug 8169778
  * @library /javax/xml/jaxp/libs
  * @run testng/othervm -DrunSecMngr=true javax.xml.xpath.ptests.XPathFactoryTest
  * @run testng/othervm javax.xml.xpath.ptests.XPathFactoryTest
@@ -58,9 +65,15 @@
     private static final String INVALID_URL = "http://java.sun.com/jaxp/xpath/dom1";
 
     /**
+     * XPathFactory builtin system-default implementation class name.
+     */
+    private static final String DEFAULT_IMPL_CLASS =
+        "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl";
+
+    /**
      * XPathFactory implementation class name.
      */
-    private static final String XPATH_FACTORY_CLASSNAME = "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl";
+    private static final String XPATH_FACTORY_CLASSNAME = DEFAULT_IMPL_CLASS;
 
 
     /**
@@ -74,6 +87,25 @@
     }
 
     /**
+     * Test if newDefaultInstance() method returns an instance
+     * of the expected factory.
+     * @throws Exception If any errors occur.
+     */
+    @Test
+    public void testDefaultInstance() throws Exception {
+        XPathFactory xpf1 = XPathFactory.newDefaultInstance();
+        XPathFactory xpf2 = XPathFactory.newInstance(DEFAULT_OBJECT_MODEL_URI);
+        assertNotSame(xpf1, xpf2, "same instance returned:");
+        assertSame(xpf1.getClass(), xpf2.getClass(),
+                  "unexpected class mismatch for newDefaultInstance():");
+        assertEquals(xpf1.getClass().getName(), DEFAULT_IMPL_CLASS);
+        assertTrue(xpf1.isObjectModelSupported(DEFAULT_OBJECT_MODEL_URI),
+                   "isObjectModelSupported(DEFAULT_OBJECT_MODEL_URI):");
+        assertFalse(xpf1.isObjectModelSupported(INVALID_URL),
+                   "isObjectModelSupported(INVALID_URL):");
+    }
+
+    /**
      * Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
      * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
      * points to correct implementation of javax.xml.xpath.XPathFactory , should