src/javax/xml/stream/XMLEventFactory.java

Print this page

        

@@ -58,30 +58,43 @@
    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
    */
   public static XMLEventFactory newInstance()
     throws FactoryConfigurationError
   {
-    return (XMLEventFactory) FactoryFinder.find(
+    return (XMLEventFactory) FactoryFinder.find(XMLEventFactory.class, 
       JAXPFACTORYID,
       DEFAULIMPL);
   }
 
   /**
-   * Create a new instance of the factory.
+   * <p>Create a new instance of the factory.</p>
    * This static method creates a new factory instance.
    * This method uses the following ordered lookup procedure to determine
    * the XMLEventFactory implementation class to load:
+   * <ul>
+   * <li>
    *   Use the javax.xml.stream.XMLEventFactory system property.
+   * </li>
+   * <li>
    *   Use the properties file "lib/stax.properties" in the JRE directory.
    *     This configuration file is in standard java.util.Properties format
    *     and contains the fully qualified name of the implementation class
    *     with the key being the system property defined above.
-   *   Use the Services API (as detailed in the JAR specification), if available,
-   *     to determine the classname. The Services API will look for a classname
-   *     in the file META-INF/services/javax.xml.stream.XMLEventFactory in jars
-   *     available to the runtime.
+   * </li>
+   * <li>
+   *   <p>Uses the service-provider loading facilities, defined by the {@link java.util.ServiceLoader} class, to attempt 
+   *   to locate and load an implementation of the service. In case of multiple providers, the first non-default implementation
+   *   shall be instantiated and returned.  The default implementation is returned if it is the only one
+   *   found by the service loader.</p>
+   *   <p>
+   *   If a misconfigured provider is encountered and {@link java.util.ServiceConfigurationError} is thrown, the error will be wrapped 
+   *   in a {@link javax.xml.stream.FactoryConfigurationError}.</p>
+   * </li>
+   * <li>
    *   Platform default XMLEventFactory instance.
+   *</li>
+   * </ul>
    *
    *   Once an application has obtained a reference to a XMLEventFactory it
    *   can use the factory to configure and obtain stream instances.
    *
    *   Note that this is a new method that replaces the deprecated newInstance() method.

@@ -91,11 +104,11 @@
    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
    */
   public static XMLEventFactory newFactory()
     throws FactoryConfigurationError
   {
-    return (XMLEventFactory) FactoryFinder.find(
+    return (XMLEventFactory) FactoryFinder.find(XMLEventFactory.class,
       JAXPFACTORYID,
       DEFAULIMPL);
   }
 
   /**

@@ -114,17 +127,13 @@
    *              method defines no changes in behavior.
    */
   public static XMLEventFactory newInstance(String factoryId,
           ClassLoader classLoader)
           throws FactoryConfigurationError {
-      try {
           //do not fallback if given classloader can't find the class, throw exception
-          return (XMLEventFactory) FactoryFinder.find(factoryId, classLoader, null);
-      } catch (FactoryFinder.ConfigurationError e) {
-          throw new FactoryConfigurationError(e.getException(),
-                  e.getMessage());
-      }
+            return (XMLEventFactory) FactoryFinder.find(XMLEventFactory.class, factoryId, classLoader, null);
+
   }
 
   /**
    * Create a new instance of the factory.
    * If the classLoader argument is null, then the ContextClassLoader is used.

@@ -141,17 +150,13 @@
    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
    */
   public static XMLEventFactory newFactory(String factoryId,
           ClassLoader classLoader)
           throws FactoryConfigurationError {
-      try {
           //do not fallback if given classloader can't find the class, throw exception
-          return (XMLEventFactory) FactoryFinder.find(factoryId, classLoader, null);
-      } catch (FactoryFinder.ConfigurationError e) {
-          throw new FactoryConfigurationError(e.getException(),
-                  e.getMessage());
-      }
+            return (XMLEventFactory) FactoryFinder.find(XMLEventFactory.class, factoryId, classLoader, null);
+
   }
 
  /**
    * This method allows setting of the Location on each event that
    * is created by this factory.  The values are copied by value into