src/javax/xml/datatype/DatatypeFactory.java

Print this page

        

@@ -23,21 +23,21 @@
  * questions.
  */
 
 package javax.xml.datatype;
 
-import java.math.BigInteger;
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.util.GregorianCalendar;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 /**
  * <p>Factory that creates new <code>javax.xml.datatype</code> <code>Object</code>s that map XML to/from Java <code>Object</code>s.</p>
  *
- * <p><a name="DatatypeFactory.newInstance"/>{@link #newInstance()} is used to create a new <code>DatatypeFactory</code>.
- * The following implementation resolution mechanisms are used in the following order:</p>
+ * <p>A new instance of the <code>DatatypeFactory</code> is created through the {@link #newInstance()} method 
+ * that uses the following implementation resolution mechanisms to determine an implementation:</p>
  * <ol>
  *    <li>
  *      If the system property specified by {@link #DATATYPEFACTORY_PROPERTY}, "<code>javax.xml.datatype.DatatypeFactory</code>",
  *      exists, a class with the name of the property's value is instantiated.
  *      Any Exception thrown during the instantiation process is wrapped as a {@link DatatypeConfigurationException}.

@@ -46,12 +46,17 @@
  *      If the file ${JAVA_HOME}/lib/jaxp.properties exists, it is loaded in a {@link java.util.Properties} <code>Object</code>.
  *      The <code>Properties</code> <code>Object </code> is then queried for the property as documented in the prior step
  *      and processed as documented in the prior step.
  *    </li>
  *    <li>
- *      The services resolution mechanism is used, e.g. <code>META-INF/services/java.xml.datatype.DatatypeFactory</code>.
- *      Any Exception thrown during the instantiation process is wrapped as a {@link DatatypeConfigurationException}.
+ *     <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.datatype.DatatypeConfigurationException}.</p>
  *    </li>
  *    <li>
  *      The final mechanism is to attempt to instantiate the <code>Class</code> specified by
  *      {@link #DATATYPEFACTORY_IMPLEMENTATION_CLASS}.
  *      Any Exception thrown during the instantiation process is wrapped as a {@link DatatypeConfigurationException}.

@@ -60,11 +65,11 @@
  *
  * @author <a href="mailto:Joseph.Fialli@Sun.COM">Joseph Fialli</a>
  * @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
  * @author <a href="mailto:Neeraj.Bajaj@sun.com">Neeraj Bajaj</a>
  *
- * @version $Revision: 1.13 $, $Date: 2010/03/11 23:10:53 $
+ * @version $Revision: 1.14 $, $Date: 2010-11-01 04:36:08 $
  * @since 1.5
  */
 public abstract class DatatypeFactory {
 
         /**

@@ -123,20 +128,16 @@
      * @see #newInstance(String factoryClassName, ClassLoader classLoader)
          */
         public static DatatypeFactory newInstance()
                 throws DatatypeConfigurationException {
 
-                try {
-                        return (DatatypeFactory) FactoryFinder.find(
+        return (DatatypeFactory) FactoryFinder.find(DatatypeFactory.class,
                                 /* The default property name according to the JAXP spec */
                                  DATATYPEFACTORY_PROPERTY,
                                 /* The fallback implementation class name */
                                 DATATYPEFACTORY_IMPLEMENTATION_CLASS);
-                } catch (FactoryFinder.ConfigurationError e) {
-                        throw new DatatypeConfigurationException(e.getMessage(), e.getException());
-                }
-        }
+}
 
     /**
      * <p>Obtain a new instance of a <code>DatatypeFactory</code> from class name.
      * This function is useful when there are multiple providers in the classpath.
      * It gives more control to the application as it can specify which provider

@@ -170,15 +171,11 @@
      *
      * @since 1.6
      */
     public static DatatypeFactory newInstance(String factoryClassName, ClassLoader classLoader)
         throws DatatypeConfigurationException {
-        try {
             return (DatatypeFactory) FactoryFinder.newInstance(factoryClassName, classLoader, false);
-        } catch (FactoryFinder.ConfigurationError e) {
-            throw new DatatypeConfigurationException(e.getMessage(), e.getException());
-        }
     }
 
         /**
          * <p>Obtain a new instance of a <code>Duration</code>
          * specifying the <code>Duration</code> as its string representation, "PnYnMnDTnHnMnS",